/** * Reads a null-terminated string of bytes from the specified input stream. * @param in The <code>InputStream</code> to read from. * @return The <code>String</code> read from the file. * @throws IOException If an I/O error occurs * @throws EOFException If the end of the file is reached before a null * byte is read. */ public static String readNullTerminatedString(InputStream in) throws IOException, EOFException { return readNullTerminatedString((DataInput) new DataInputStream(in)); }
public boolean visit(File file) throws IOException { if (file.isFile()) { String name = getRelativePath(file, contents); zs.putNextEntry(new ZipEntry(name)); FileInputStream fs = new FileInputStream(file); StreamUtil.writeStream(fs, zs); fs.close(); zs.closeEntry(); } return true; }
/** * Writes the specified byte array to a file. * @param file The <code>File</code> to write. * @param contents The byte array to write to the file. * @param createDirectory A value indicating whether the directory * containing the file to be written should be created if it does * not exist. * @throws IOException If the file could not be written. */ public static void setFileContents(File file, ByteBuffer contents, boolean createDirectory) throws IOException { if (createDirectory) { File directory = file.getParentFile(); if (!directory.exists()) { directory.mkdirs(); } } FileOutputStream stream = new FileOutputStream(file); StreamUtil.writeBytes(contents, stream); stream.close(); }
/** * Writes a class' bytecode to an <code>OutputStream</code>. * @param cl The <code>Class</code> to write. * @param out The <code>OutputStream</code> to write to. * @throws IOException If unable to write to <code>out</code>. */ public static void writeClassToStream(Class<?> cl, OutputStream out) throws IOException { InputStream in = getClassAsStream(cl); StreamUtil.writeStream(in, out); out.flush(); }