/** * @see #writeBytes(File, byte[], int, int) */ public static void writeBytes(final File dest, final byte[] data) throws IOException { writeBytes(dest, data, ZERO, data.length); }
/** * @see #writeBytes(File, byte[], int, int) */ public static void writeBytes(final String dest, final byte[] data, final int off, final int len) throws IOException { writeBytes(file(dest), data, off, len); }
/** * @see #writeBytes(File, byte[]) */ public static void writeBytes(final String dest, final byte[] data) throws IOException { writeBytes(file(dest), data); }
private File file(String fileName, int size) throws IOException { byte[] bytes = new byte[size]; for (int i = 0; i < size; i++) { bytes[i] = (byte) i; } File file = new File(tempFolder, fileName); file.deleteOnExit(); FileUtil.writeBytes(file, bytes); return file; }
/** * Writes file upload item to destination folder or to destination file. * Returns the destination file. */ public File write(File destination) throws IOException { if (destination.isDirectory()) { destination = new File(destination, this.header.getFileName()); } if (data != null) { FileUtil.writeBytes(destination, data); } else { if (tempFile != null) { FileUtil.move(tempFile, destination); } } return destination; }
/** * Writes created class content to output folder for debugging purposes. */ protected void dumpClassInDebugFolder(final byte[] bytes) { File debugFolder = proxetta.getDebugFolder(); if (debugFolder == null) { return; } if (!debugFolder.exists() || !debugFolder.isDirectory()) { log.warn("Invalid debug folder: " + debugFolder); } String fileName = proxyClassName; if (fileName == null) { fileName = "proxetta-" + System.currentTimeMillis(); } fileName += ".class"; File file = new File(debugFolder, fileName); try { FileUtil.writeBytes(file, bytes); } catch (IOException ioex) { log.warn("Error writing class as " + file, ioex); } }
try { File tempFile = FileUtil.createTempFile(); FileUtil.writeBytes(tempFile, (byte[])value); return tempFile; } catch (IOException ioex) {
@Test void testZipEmptyFolder() throws IOException { byte[] bytes = ZipBuilder .createZipInMemory() .addFolder("myEmptyFolder") .toBytes(); File tempDir = FileUtil.createTempDirectory(); tempDir.deleteOnExit(); File zipFile = new File(tempDir, "test.zip"); FileUtil.writeBytes(zipFile, bytes); // read zip List<String> entries = ZipUtil.listZip(zipFile); assertEquals(1, entries.size()); assertEquals("myEmptyFolder/", entries.get(0)); }
@Test void check_against_created_binary_file() throws Exception { final File input = FileUtil.createTempFile(); // first bytes of a zip / jar file FileUtil.writeBytes(input, new byte[] {0x50, 0x4b, 0x03, 0x04, 0x14, 0x20, 0x08, 0x08, 0x08, 0x20, 0x09, 0x76, 0x19, 0x45, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }); final boolean actual = FileUtil.isBinary(input); // asserts assertEquals(true, actual); }
FileUtil.writeBytes(zipFile, bytes);
try { File tempFile = FileUtil.createTempFile(); FileUtil.writeBytes(tempFile, (byte[])value); return tempFile; } catch (IOException ioex) {
/** * @see #writeBytes(File, byte[], int, int) */ public static void writeBytes(final File dest, final byte[] data) throws IOException { writeBytes(dest, data, ZERO, data.length); }
/** * @see #writeBytes(File, byte[], int, int) */ public static void writeBytes(final String dest, final byte[] data, final int off, final int len) throws IOException { writeBytes(file(dest), data, off, len); }
/** * @see #writeBytes(File, byte[]) */ public static void writeBytes(final String dest, final byte[] data) throws IOException { writeBytes(file(dest), data); }
/** * Writes file upload item to destination folder or to destination file. * Returns the destination file. */ public File write(File destination) throws IOException { if (destination.isDirectory()) { destination = new File(destination, this.header.getFileName()); } if (data != null) { FileUtil.writeBytes(destination, data); } else { if (tempFile != null) { FileUtil.move(tempFile, destination); } } return destination; }
/** * Writes created class content to output folder for debugging purposes. */ protected void dumpClass(byte[] bytes) { String debugFolder = proxetta.getDebugFolder(); if (debugFolder == null) { return; } File folder = new File(debugFolder); if (!folder.exists()) { folder.mkdirs(); } String fileName = proxyClassName; if (fileName == null) { fileName = "proxetta-" + System.currentTimeMillis(); } fileName += ".class"; File file = new File(folder, fileName); try { FileUtil.writeBytes(file, bytes); } catch (IOException ioex) { log.warn("Error dumping class", ioex); } }
/** * Writes created class content to output folder for debugging purposes. */ protected void dumpClassInDebugFolder(final byte[] bytes) { File debugFolder = proxetta.getDebugFolder(); if (debugFolder == null) { return; } if (!debugFolder.exists() || !debugFolder.isDirectory()) { log.warn("Invalid debug folder: " + debugFolder); } String fileName = proxyClassName; if (fileName == null) { fileName = "proxetta-" + System.currentTimeMillis(); } fileName += ".class"; File file = new File(debugFolder, fileName); try { FileUtil.writeBytes(file, bytes); } catch (IOException ioex) { log.warn("Error writing class as " + file, ioex); } }
try { File tempFile = FileUtil.createTempFile(); FileUtil.writeBytes(tempFile, (byte[])value); return tempFile; } catch (IOException ioex) {