/** * Create a {@code FileNotFoundException} with the inner nested cause set * to the given exception. Compensates for the fact that FNFE doesn't * have an initializer that takes an exception. * @param text error text * @param ex inner exception * @return a new exception to throw. */ private static FileNotFoundException fileNotFoundException(String text, Exception ex) { return (FileNotFoundException) new FileNotFoundException(text) .initCause(ex); }
protected Reader getReader(String sourceFile) throws FileNotFoundException { try { return Files.newBufferedReader(new File(sourceFile).toPath(), Charset.defaultCharset()); } catch (IOException e) { FileNotFoundException ex = new FileNotFoundException(sourceFile); ex.initCause(e); throw ex; } }
public InputStream open(Uri uri) throws FileNotFoundException { String path = getPath(uri); if (TextUtils.isEmpty(path)) { return null; } File file = service.get(path); if (!isValid(file)) { return null; } Uri thumbnailUri = Uri.fromFile(file); try { return contentResolver.openInputStream(thumbnailUri); // PMD.AvoidCatchingNPE framework method openInputStream can throw NPEs. } catch (@SuppressWarnings("PMD.AvoidCatchingNPE") NullPointerException e) { throw (FileNotFoundException) new FileNotFoundException("NPE opening uri: " + uri + " -> " + thumbnailUri).initCause(e); } }
FileNotFoundException fnfe = new FileNotFoundException(name); if (ex != null) { fnfe.initCause(ex);
format( "File could not be opened [%s]", fileToOpen.getCanonicalPath() ) ).initCause( cause );
@Override public void render(final View view, final Renderer.Context ctx) throws Exception { String vname = view.name(); try { Map<String, Object> locals = ctx.locals(); if (vname.charAt(0) == '/') { vname = vname.substring(1); } PebbleTemplate template = pebble.getTemplate(vname); Writer writer = new StringWriter(); Map<String, Object> model = new HashMap<>(); // push locals model.putAll(locals); model.putIfAbsent("_vname", vname); // Locale: Locale locale = (Locale) locals.getOrDefault("locale", ctx.locale()); model.putIfAbsent("locale", locale); // put model model.putAll(view.model()); // render and send template.evaluate(writer, model, locale); ctx.type(MediaType.html) .send(writer.toString()); } catch (LoaderException x) { FileNotFoundException fnf = new FileNotFoundException(x.getMessage().replace("Could not find template", "").trim()); fnf.initCause(x); throw fnf; } }
@Override public AssetFileDescriptor openAssetFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException { if (uri.getPath() == null) { return null; } try { String fileName = getFileName(uri); boolean pipeMode = uri.getQueryParameter(PARAM_PIPE_MODE) != null; if (pipeMode) { ParcelFileDescriptor fileDescriptor = openPipeHelper(uri, null, null, null, this); return new AssetFileDescriptor(fileDescriptor, 0, C.LENGTH_UNSET); } else { return getContext().getAssets().openFd(fileName); } } catch (IOException e) { FileNotFoundException exception = new FileNotFoundException(e.getMessage()); exception.initCause(e); throw exception; } }
ex.initCause(errnoException); throw ex;
e.initCause(parsingError); throw e;
private static void throwFileNotFoundException(final String name, final Throwable t) throws FileNotFoundException { final FileNotFoundException e = new FileNotFoundException( "No file, resource or URL found: " + name); if (t != null) { e.initCause(t); } throw e; }
/** * Create a {@code FileNotFoundException} with the inner nested cause set * to the given exception. Compensates for the fact that FNFE doesn't * have an initializer that takes an exception. * @param text error text * @param ex inner exception * @return a new exception to throw. */ private static FileNotFoundException fileNotFoundException(String text, Exception ex) { return (FileNotFoundException) new FileNotFoundException(text) .initCause(ex); }
public static FileNotFoundException asFileNotFoundException(Throwable t) throws FileNotFoundException { if (t instanceof FileNotFoundException) { throw (FileNotFoundException) t; } final FileNotFoundException fnfe = new FileNotFoundException(t.getMessage()); fnfe.initCause(t); throw fnfe; }
public static ZipFile open(File file) throws IOException { try { return new ZipFile(file); } catch (FileNotFoundException fnfe) { FileNotFoundException ecxcption = new FileNotFoundException(file.getAbsolutePath()); ecxcption.initCause(fnfe); throw ecxcption; } }
protected Reader getReader(String sourceFile) throws FileNotFoundException { try { return Files.newBufferedReader(new File(sourceFile).toPath(), Charset.defaultCharset()); } catch (IOException e) { FileNotFoundException ex = new FileNotFoundException(sourceFile); ex.initCause(e); throw ex; } }
public MemoryMappedReadOnlyFile(File file) throws FileNotFoundException { channel = new FileInputStream(file).getChannel(); try { window(0); } catch (IOException ioe) { FileNotFoundException fnfe = new FileNotFoundException(ioe.toString()); fnfe.initCause(ioe); throw fnfe; } assert window != null; assert windowOff == 0; }
public MemoryMappedReadOnlyFile(File file) throws FileNotFoundException { channel = new FileInputStream(file).getChannel(); try { window(0); } catch (IOException ioe) { FileNotFoundException fnfe = new FileNotFoundException(ioe.toString()); fnfe.initCause(ioe); throw fnfe; } assert window != null; assert windowOff == 0; }
/** * Deletes this repository. */ public void delete() throws IOException { try { new Requester(root).method("DELETE").to(getApiTailUrl("")); } catch (FileNotFoundException x) { throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + owner.login + "/" + name + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916").initCause(x); } }
/** * Deletes this repository. */ public void delete() throws IOException { try { new Requester(root).method("DELETE").to(getApiTailUrl("")); } catch (FileNotFoundException x) { throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + getOwnerName() + "/" + name + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916").initCause(x); } }
/** * Deletes this repository. */ public void delete() throws IOException { try { new Requester(root).method("DELETE").to(getApiTailUrl("")); } catch (FileNotFoundException x) { throw (FileNotFoundException) new FileNotFoundException("Failed to delete " + getOwnerName() + "/" + name + "; might not exist, or you might need the delete_repo scope in your token: http://stackoverflow.com/a/19327004/12916").initCause(x); } }