public static byte[] readFileAsBytes(File file) throws IOException { assert file != null; if (file.canRead() && (file.length() == 0)) return EMPTY_BYTE_ARRAY; FileInputStream fis = null; try { fis = new FileInputStream(file); byte[] readBytes = new byte[(int) file.length()]; int nbRead = fis.read(readBytes); assert nbRead == readBytes.length; return readBytes; } finally { IOHelper.close(fis); } } }
/** * Read the specified file * * @param file * the file to read * * @return the content of the file * * @throws IOException * if the file does not exist, is a directory rather than a * regular file, or for some other reason cannot be opened for * reading, if a security manager exists and its checkRead * method denies read access to the file or if an I/O error * occurs */ public static final String readFileAsString(File file) throws IOException { return new String(readFileAsBytes(file)); }
public static byte[] readFileAsBytes(File file) throws IOException { assert file != null; if (file.canRead() && (file.length() == 0)) return EMPTY_BYTE_ARRAY; FileInputStream fis = null; try { fis = new FileInputStream(file); byte[] readBytes = new byte[(int) file.length()]; int nbRead = fis.read(readBytes); assert nbRead == readBytes.length; return readBytes; } finally { IOHelper.close(fis); } } }
/** * Read the specified file * * @param file * the file to read * * @return the content of the file * * @throws IOException * if the file does not exist, is a directory rather than a * regular file, or for some other reason cannot be opened for * reading, if a security manager exists and its checkRead * method denies read access to the file or if an I/O error * occurs */ public static final String readFileAsString(File file) throws IOException { return new String(readFileAsBytes(file)); }
/** * @returns a byte[] containing the information contained in the specified * InputStream. */ public static byte[] getBytes(InputStream input) { ByteArrayOutputStream result = new ByteArrayOutputStream(); try { copy(input, result); } finally { IOHelper.close(result); } return result.toByteArray(); }
IOHelper.close(out);
throw new PropertiesException(message); } finally { IOHelper.close(propFileStream);
private Jbi generateComponentJbi() { ComponentJbiGenerator componentJbiGenerator = new ComponentJbiGenerator(componentType, componentConfiguration, getInstallRoot()); componentJbiGenerator.generate(); File generatedJbiFile = new File(getInstallRoot() + File.separator + "META-INF" + File.separator, "jbi.xml"); assert generatedJbiFile.exists(); FileInputStream fis; try { fis = new FileInputStream(generatedJbiFile); } catch (FileNotFoundException fnfe) { throw new UncheckedException(fnfe); } assert generatedJbiFile.exists(); try { return CDKJBIDescriptorBuilder.getInstance().buildJavaJBIDescriptor(fis); } catch (JBIDescriptorException cjde) { throw new UncheckedException(cjde); } finally { IOHelper.close(fis); } }