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); } } }
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); } } }
/** * @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); } }