public static byte[] serialize(final Serializable object) throws IOException, ClassNotFoundException { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(object); out.flush(); Misc.close(out); // Get the bytes of the serialized object return bos.toByteArray(); }
public static byte[] serialize(final Serializable object) throws IOException, ClassNotFoundException { final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final ObjectOutputStream out = new ObjectOutputStream(bos); out.writeObject(object); out.flush(); Misc.close(out); // Get the bytes of the serialized object return bos.toByteArray(); }
public static byte[] generateJar(final Map<String, byte[]> resources) throws IOException { if (resources == null || resources.size() == 0) { throw new IOException("No Resources available"); } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final JarOutputStream out = new JarOutputStream(new BufferedOutputStream(baos)); for (final Map.Entry<String, byte[]> resource : resources.entrySet()) { out.putNextEntry(new JarEntry(resource.getKey())); out.write(resource.getValue()); } out.flush(); Misc.close(out); return baos.toByteArray(); }
public static void write(final File file, final byte[] fileContent) throws IOException { Misc.checkArgsNotNull(file, fileContent); if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); } OutputStream os = null; try { os = new FileOutputStream(file); os.write(fileContent); os.flush(); } finally { Misc.close(os); } }
public static void write(final File file, final byte[] fileContent) throws IOException { Misc.checkArgsNotNull(file, fileContent); if (!file.exists()) { file.getParentFile().mkdirs(); file.createNewFile(); } OutputStream os = null; try { os = new FileOutputStream(file); os.write(fileContent); os.flush(); } finally { Misc.close(os); } }
public static void write(final File file, final byte[] fileContent) throws IOException { Misc.checkArgsNotNull(file, fileContent); if (!file.exists()) { if (file.mkdirs()) { throw new IOException("Can't create some directories in: " + file.getCanonicalPath()); } } OutputStream os = null; try { os = new FileOutputStream(file); os.write(fileContent); os.flush(); } finally { Misc.close(os); } }
/** * Equivalent to {@link #getAllContentFrom(InputStream) getAllContentFrom(new * FileInputStream(file))}; * * @param file the file to read * @return the whole content of the file in a single String. * @throws IOException If an I/O exception occured */ public static byte[] getAllContentFrom(final File file) throws IOException { InputStream in = null; try { in = new FileInputStream(file); return Misc.getAllContentFrom(in); } finally { Misc.close(in); } }
public static Map<String, byte[]> getJarEntries(final String jarFile, final byte[] jar) { JarInputStream jis = null; try { jis = new JarInputStream(new ByteArrayInputStream(jar)); return getJarEntries(jis, jarFile); } catch (final IOException e) { throw new BonitaRuntimeException("Unable to load jar entries from jar file: " + jarFile, e); } finally { Misc.close(jis); } }
public static Map<String, byte[]> getJarEntries(final String jarFile, final byte[] jar) { JarInputStream jis = null; try { jis = new JarInputStream(new ByteArrayInputStream(jar)); return getJarEntries(jis, jarFile); } catch (final IOException e) { throw new BonitaRuntimeException("Unable to load jar entries from jar file: " + jarFile, e); } finally { Misc.close(jis); } }
/** * Equivalent to {@link #getAllContentFrom(InputStream) * getAllContentFrom(source.getByteStream(source))}; * * @param file the file to read * @return the whole content of the file in a single String. * @throws IOException If an I/O exception occured */ public static byte[] getAllContentFrom(final InputSource source) throws IOException { InputStream in = null; try { in = source.getByteStream(); return Misc.getAllContentFrom(in); } finally { Misc.close(in); } }
/** * Write the given String to the given file using the default encoding. * * @param s the string to be written * @param f the file to write the given string to * @throws IOException if an IO error is encoutered (file not found, read-only * file, and so on). */ public static void write(final String s, final File f) throws IOException { Misc.checkArgsNotNull(s, f); final FileWriter writer = new FileWriter(f); try { writer.write(s); writer.flush(); } finally { Misc.close(writer); } }
public static Map<String, byte[]> getResourcesFromZip(final byte[] barContent) throws IOException { final Map<String, byte[]> resources = new HashMap<String, byte[]>(); final InputStream in = new ByteArrayInputStream(barContent); final ZipInputStream zis = new ZipInputStream(in); ZipEntry zipEntry = null; while ((zipEntry = zis.getNextEntry()) != null) { if (!zipEntry.isDirectory()) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); int c; final byte[] buffer = new byte[512]; while ((c = zis.read(buffer)) != -1) { baos.write(buffer, 0, c); } baos.flush(); resources.put(zipEntry.getName(), baos.toByteArray()); Misc.close(baos); } } zis.close(); in.close(); return resources; }
/** * Equivalent to {@link #getAllContentFrom(InputStream) getAllContentFrom(new FileInputStream(file))}; * * @param file * the file to read * @return the whole content of the file in a single String. * @throws IOException * If an I/O exception occurs */ public static byte[] getAllContentFrom(final File file) throws IOException { InputStream in = null; try { in = new FileInputStream(file); return Misc.getAllContentFrom(in); } finally { Misc.close(in); } }
/** * Equivalent to {@link #getAllContentFrom(InputStream) getAllContentFrom(source.getByteStream(source))}; * * @param source * the file to read * @return the whole content of the file in a single String. * @throws IOException * IOException If an I/O exception occurs */ public static byte[] getAllContentFrom(final InputSource source) throws IOException { InputStream in = null; try { in = source.getByteStream(); return Misc.getAllContentFrom(in); } finally { Misc.close(in); } }
/** * Equivalent to {@link #getAllContentFrom(InputStream) getAllContentFrom(new FileInputStream(file))}; * * @param file * the file to read * @return the whole content of the file in a single String. * @throws IOException * If an I/O exception occurs */ public static byte[] getAllContentFrom(final File file) throws IOException { InputStream in = null; try { in = new FileInputStream(file); return Misc.getAllContentFrom(in); } finally { Misc.close(in); } }
/** * Equivalent to {@link #getAllContentFrom(InputStream) getAllContentFrom(source.getByteStream(source))}; * * @param source * the file to read * @return the whole content of the file in a single String. * @throws IOException * IOException If an I/O exception occurs */ public static byte[] getAllContentFrom(final InputSource source) throws IOException { InputStream in = null; try { in = source.getByteStream(); return Misc.getAllContentFrom(in); } finally { Misc.close(in); } }
public static byte[] generateJar(final Map<String, byte[]> resources) throws IOException { if (resources == null || resources.size() == 0) { final String message = ExceptionManager.getInstance().getFullMessage("buc_M_14"); throw new IOException(message); } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final JarOutputStream out = new JarOutputStream(new BufferedOutputStream(baos)); for (final Map.Entry<String, byte[]> resource : resources.entrySet()) { out.putNextEntry(new JarEntry(resource.getKey())); out.write(resource.getValue()); } out.flush(); Misc.close(out); final byte[] jar = baos.toByteArray(); Misc.close(baos); return jar; }
public static byte[] generateJar(final Map<String, byte[]> resources) throws IOException { if (resources == null || resources.size() == 0) { final String message = ExceptionManager.getInstance().getFullMessage("buc_M_14"); throw new IOException(message); } final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final JarOutputStream out = new JarOutputStream(new BufferedOutputStream(baos)); for (final Map.Entry<String, byte[]> resource : resources.entrySet()) { out.putNextEntry(new JarEntry(resource.getKey())); out.write(resource.getValue()); } out.flush(); Misc.close(out); final byte[] jar = baos.toByteArray(); Misc.close(baos); return jar; }
/** * Write the given String to the given file using the default encoding. * * @param s * the string to be written * @param f * the file to write the given string to * @throws IOException * if an IO error is encountered (file not found, read-only file, and so on). */ public static void write(final String s, final File f) throws IOException { Misc.checkArgsNotNull(s, f); final FileWriter writer = new FileWriter(f); try { writer.write(s); writer.flush(); } finally { Misc.close(writer); } }
/** * Write the given String to the given file using the default encoding. * * @param s * the string to be written * @param f * the file to write the given string to * @throws IOException * if an IO error is encountered (file not found, read-only file, and so on). */ public static void write(final String s, final File f) throws IOException { Misc.checkArgsNotNull(s, f); final FileWriter writer = new FileWriter(f); try { writer.write(s); writer.flush(); } finally { Misc.close(writer); } }