/** * Writes the contents from a byte array to a file. * * @param pFile The file to write to * @param pData The byte array to write * @return {@code true}, otherwise an IOException is thrown. * @throws IOException if an i/o error occurs during write. */ public static boolean write(File pFile, byte[] pData) throws IOException { boolean success = false; OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(pFile)); success = write(out, pData); } finally { close(out); } return success; }
@SuppressWarnings("SameParameterValue") private static ICC_Profile readProfileFromClasspathResource(final String profilePath) { InputStream stream = ColorSpaces.class.getResourceAsStream(profilePath); if (stream != null) { if (DEBUG) { System.out.println("Loading profile from classpath resource: " + profilePath); } try { return ICC_Profile.getInstance(stream); } catch (IOException ignore) { if (DEBUG) { ignore.printStackTrace(); } } finally { FileUtil.close(stream); } } return null; }
/** * Gets the contents of the given file, as a byte array. * * @param pFile the file to get content from * @return the content of the file as a byte array. * @throws IOException if the read operation fails */ public static byte[] read(File pFile) throws IOException { // Custom implementation, as we know the size of a file if (!pFile.exists()) { throw new FileNotFoundException(pFile.toString()); } byte[] bytes = new byte[(int) pFile.length()]; InputStream in = null; try { // Use buffer size two times byte array, to avoid i/o bottleneck in = new BufferedInputStream(new FileInputStream(pFile), BUF_SIZE * 2); int off = 0; int len; while ((len = in.read(bytes, off, in.available())) != -1 && (off < bytes.length)) { off += len; // System.out.println("read:" + len); } } // Just pass any IOException on up the stack finally { close(in); } return bytes; }
FileUtil.close(reader);
FileUtil.close(reader);
/** * Writes the contents from a byte array to a file. * * @param pFile The file to write to * @param pData The byte array to write * @return {@code true}, otherwise an IOException is thrown. * @throws IOException if an i/o error occurs during write. */ public static boolean write(File pFile, byte[] pData) throws IOException { boolean success = false; OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(pFile)); success = write(out, pData); } finally { close(out); } return success; }
private static ICC_Profile readProfileFromClasspathResource(final String profilePath) { InputStream stream = ColorSpaces.class.getResourceAsStream(profilePath); if (stream != null) { if (DEBUG) { System.out.println("Loading profile from classpath resource: " + profilePath); } try { return ICC_Profile.getInstance(stream); } catch (IOException ignore) { if (DEBUG) { ignore.printStackTrace(); } } finally { FileUtil.close(stream); } } return null; }
/** * Writes the contents from a byte array to a file. * * @param pFile The file to write to * @param pData The byte array to write * @return {@code true}, otherwise an IOException is thrown. * @throws IOException if an i/o error occurs during write. */ public static boolean write(File pFile, byte[] pData) throws IOException { boolean success = false; OutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(pFile)); success = write(out, pData); } finally { close(out); } return success; }
/** * Gets the contents of the given file, as a byte array. * * @param pFile the file to get content from * @return the content of the file as a byte array. * @throws IOException if the read operation fails */ public static byte[] read(File pFile) throws IOException { // Custom implementation, as we know the size of a file if (!pFile.exists()) { throw new FileNotFoundException(pFile.toString()); } byte[] bytes = new byte[(int) pFile.length()]; InputStream in = null; try { // Use buffer size two times byte array, to avoid i/o bottleneck in = new BufferedInputStream(new FileInputStream(pFile), BUF_SIZE * 2); int off = 0; int len; while ((len = in.read(bytes, off, in.available())) != -1 && (off < bytes.length)) { off += len; // System.out.println("read:" + len); } } // Just pass any IOException on up the stack finally { close(in); } return bytes; }
/** * Gets the contents of the given file, as a byte array. * * @param pFile the file to get content from * @return the content of the file as a byte array. * @throws IOException if the read operation fails */ public static byte[] read(File pFile) throws IOException { // Custom implementation, as we know the size of a file if (!pFile.exists()) { throw new FileNotFoundException(pFile.toString()); } byte[] bytes = new byte[(int) pFile.length()]; InputStream in = null; try { // Use buffer size two times byte array, to avoid i/o bottleneck in = new BufferedInputStream(new FileInputStream(pFile), BUF_SIZE * 2); int off = 0; int len; while ((len = in.read(bytes, off, in.available())) != -1 && (off < bytes.length)) { off += len; // System.out.println("read:" + len); } } // Just pass any IOException on up the stack finally { close(in); } return bytes; }
FileUtil.close(reader);
FileUtil.close(reader);
FileUtil.close(reader);
FileUtil.close(reader);