public static File createTempDir(String prefix) throws IOException { return createTempDir(getSystemTempDir(), prefix); }
public static File createTempDir() throws IOException { return createTempDir("tmp"+random.nextInt()); }
/** * 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); } } }
public static final int dumpAndWrite(WritableByteChannel channelToDump, ByteBuffer writeBuffer, FileChannel dumpChannel) throws IOException { ensureChannelIsOpen(channelToDump); ByteBuffer writeBufferView = writeBuffer.duplicate(); dumpChannel.write(writeBufferView); int nbBytesWritten = channelToDump.write(writeBuffer); return nbBytesWritten; }
/** * Deletes a directory recursively. * * @param directory * directory to delete * @throws IOException * in case deletion is unsuccessful */ private static void deleteDirectory(File directory) throws IOException { if (!directory.exists()) { return; } cleanDirectory(directory); if (!directory.delete()) { String message = "Unable to delete directory " + directory + "."; throw new IOException(message); } }
File file = files[i]; try { forceDelete(file); } catch (IOException ioe) { exception = ioe;
assert file != null; if (file.isDirectory()) { deleteDirectory(file); } else { if (!file.exists()) {
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 File createTempDir() throws IOException { return createTempDir(getSystemTempDir(), "tmp"); }
private static final File createComponentRepositoryRoot() { try { return FileSystemHelper.createTempDir("repository"); } catch (IOException ioe) { throw new UncheckedException(ioe); } }
public static final int dumpAndWrite(WritableByteChannel channelToDump, ByteBuffer writeBuffer, FileChannel dumpChannel) throws IOException { ensureChannelIsOpen(channelToDump); ByteBuffer writeBufferView = writeBuffer.duplicate(); dumpChannel.write(writeBufferView); int nbBytesWritten = channelToDump.write(writeBuffer); return nbBytesWritten; }
/** * 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)); }
/** * Deletes a directory recursively. * * @param directory * directory to delete * @throws IOException * in case deletion is unsuccessful */ private static void deleteDirectory(File directory) throws IOException { if (!directory.exists()) { return; } cleanDirectory(directory); if (!directory.delete()) { String message = "Unable to delete directory " + directory + "."; throw new IOException(message); } }
File file = files[i]; try { forceDelete(file); } catch (IOException ioe) { exception = ioe;
assert file != null; if (file.isDirectory()) { deleteDirectory(file); } else { if (!file.exists()) {
/** * @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(); }
public static final int dumpAndRead(ReadableByteChannel channelToDump, ByteBuffer readBuffer, FileChannel dumpChannel) throws IOException { ensureChannelIsOpen(channelToDump); ByteBuffer readBufferView = readBuffer.duplicate(); int nbBytesRead = channelToDump.read(readBuffer); if (nbBytesRead != -1) { readBufferView.limit(readBufferView.position() + nbBytesRead); dumpChannel.write(readBufferView); } return nbBytesRead; }
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); } }
public static final int dumpAndRead(ReadableByteChannel channelToDump, ByteBuffer readBuffer, FileChannel dumpChannel) throws IOException { ensureChannelIsOpen(channelToDump); ByteBuffer readBufferView = readBuffer.duplicate(); int nbBytesRead = channelToDump.read(readBuffer); if (nbBytesRead != -1) { readBufferView.limit(readBufferView.position() + nbBytesRead); dumpChannel.write(readBufferView); } return nbBytesRead; }