public void afterInvoke(File file, Object[] payload) { if (payload.length != 1) { throw new AssertionError("Invalid payload length: " + payload.length); } if (!(payload[0] instanceof Closeable)) { throw new AssertionError("Invalid payload type: " + payload[0]); } IOHelper.closeQuietly((Closeable) payload[0]); }
/** * Copies a stream to a destination * * @param stream the stream * @param destination the destination * @throws IOException if there is an error copying */ private static void copy(InputStream stream, File destination) throws IOException { try (OutputStream os = new BufferedOutputStream(new FileOutputStream(destination))) { IOHelper.copy(stream, os); os.flush(); } destination.deleteOnExit(); }
private void releaseLock(File lockFile, FileLock lock, FileChannel lockChannel) { if (lock != null) { try { lock.release(); IOHelper.closeQuietly(lockChannel); if (lockFile.exists()) { lockFile.delete(); } } catch (IOException e) { // ignore } } }
try (FileInputStream input = new FileInputStream(srcFile)) { output = new FileOutputStream(destFile); IOHelper.copy(input, output); } catch (IOException e) { throw new Fabric3Exception(e);
private boolean hasLibDirectory(File file, String dir) { InputStream stream = null; try { URL jarUrl = new URL("jar:" + file.toURI().toURL().toExternalForm() + "!/WEB-INF/" + dir); stream = jarUrl.openStream(); return true; } catch (MalformedURLException e) { return false; } catch (IOException e) { return false; } finally { try { IOHelper.closeQuietly(stream); } catch (NullPointerException e) { // ignore will be thrown if the directory exists as the underlying stream is null } } }
public Object[] beforeInvoke(File file) throws InvalidDataException { FileInputStream fileStream = null; try { fileStream = new FileInputStream(file); return new Object[]{new BufferedInputStream(fileStream)}; } catch (FileNotFoundException e) { IOHelper.closeQuietly(fileStream); throw new InvalidDataException(e); } }
private boolean hasLibDirectory(File file, String dir) { InputStream stream = null; try { URL jarUrl = new URL("jar:" + file.toURI().toURL().toExternalForm() + "!/WEB-INF/" + dir); stream = jarUrl.openStream(); return true; } catch (MalformedURLException e) { return false; } catch (IOException e) { return false; } finally { try { IOHelper.closeQuietly(stream); } catch (NullPointerException e) { // ignore will be thrown if the directory exists as the underlying stream is null } } }
public void afterInvoke(File file, Object[] payload) { if (payload.length != 1) { throw new AssertionError("Invalid payload length: " + payload.length); } if (!(payload[0] instanceof DataHandler)) { throw new AssertionError("Invalid payload type: " + payload[0]); } DataHandler dataHandler = (DataHandler) payload[0]; try { IOHelper.closeQuietly(dataHandler.getInputStream()); } catch (IOException e) { // ignore as this will not happen } }
public InputSource resolveEntity(String targetNamespace, String schemaLocation, String baseUri) { String base = getBase(baseUri); try { URL url = new URL(new URL(base), schemaLocation); InputStream stream = null; try { stream = url.openStream(); if (stream != null) { return (createSource(url)); } } catch (IOException e) { // file not found return next.resolveEntity(targetNamespace, schemaLocation, baseUri); } finally { IOHelper.closeQuietly(stream); } } catch (IOException e) { e.printStackTrace(); // should not happen } return next.resolveEntity(targetNamespace, schemaLocation, baseUri); }