/** * Write all class bytes to a file. * * @param fileName file where the bytes will be written * @param bytes bytes representing the class * @throws IOException if we fail to write the class */ public static void writeClass(String fileName, byte[] bytes) throws IOException { BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(fileName)); try { out.write(bytes); } finally { out.close(); } }
public static void toJSON(final Object obj, final File file, final boolean prettyPrint) throws IOException { final BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(file)); try { toJSON(obj, stream, prettyPrint); } finally { stream.close(); } }
@Override public void saveConfiguration(ByteBuffer buffer) throws IOException { PersistentStorage storage = context.createPersistentStorage(); BufferedOutputStream os = new BufferedOutputStream(storage.openForWrite(path)); byte[] data = new byte[buffer.remaining()]; buffer.get(data); LOG.trace("Writing {} bytes to output stream", data.length); os.write(data); os.close(); }
/** Helper method which uses xstream to persist an object as xml on disk. */ void persist(XStreamPersister xp, Object obj, Resource f) throws Exception { BufferedOutputStream out = new BufferedOutputStream(f.out()); xp.save(obj, out); out.flush(); out.close(); }
public static void writeToFile(InputStream dataIns, File target) throws IOException { final int BUFFER = 1024; BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(target)); int count; byte data[] = new byte[BUFFER]; while ((count = dataIns.read(data, 0, BUFFER)) != -1) { bos.write(data, 0, count); } bos.close(); }
/** * Store all properties, those local and also those in parent props * * @param file The file to store to * @throws IOException If there is an error writing */ public void storeFlattened(final File file) throws IOException { final BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file)); try { storeFlattened(out); } finally { out.close(); } }
/** * 生成该图片对应的 Base64 编码的字符串 * * @param targetFile * 图片文件 * @return 图片对应的 Base64 编码的字符串 */ public static String encodeBase64(File targetFile) { BufferedImage image = null; try { image = ImageIO.read(targetFile); } catch (IOException e) { throw Lang.wrapThrow(e); } ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos); image.flush(); try { ImageIO.write(image, Files.getSuffixName(targetFile), bos); bos.flush(); bos.close(); } catch (IOException e) { throw Lang.wrapThrow(e); } byte[] bImage = baos.toByteArray(); return Base64.encodeToString(bImage, false); }
@Override protected void writeValueToDisk(File file, byte[] imageData) throws IOException { BufferedOutputStream ostream = new BufferedOutputStream(new FileOutputStream(file)); ostream.write(imageData); ostream.close(); } }
/** * Store only those properties defined at this local level * * @param file The file to write to * @throws IOException If the file can't be found or there is an io error */ public void storeLocal(final File file) throws IOException { final BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(file)); try { storeLocal(out); } finally { out.close(); } }
public static String encodeBinaryData( byte[] val ) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gzos = new GZIPOutputStream( baos ); BufferedOutputStream bos = new BufferedOutputStream( gzos ); bos.write( val ); bos.flush(); bos.close(); return new String( Base64.encodeBase64( baos.toByteArray() ) ); }
/** * Save an ndarray to the given file * @param arr the array to save * @param saveTo the file to save to * @throws IOException */ public static void saveBinary(INDArray arr, File saveTo) throws IOException { BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(saveTo)); DataOutputStream dos = new DataOutputStream(bos); Nd4j.write(arr, dos); dos.flush(); dos.close(); bos.close(); }
public void write(String file, String text) throws IOException { BufferedOutputStream out = null; try { out = new BufferedOutputStream(new FileOutputStream(file)); out.write(42); } finally { if (out != null) out.close(); } }
/** * Store all properties, those local and also those in parent props * * @param file * The file to store to * @throws IOException * If there is an error writing */ public void storeFlattened(File file) throws IOException { BufferedOutputStream out = new BufferedOutputStream( new FileOutputStream(file)); try { storeFlattened(out); } finally { out.close(); } }
public static void convert_to_small_img(String frompath, String topath, Bitmap bitmap, int pix) throws IOException { long size = new File(frompath).length(); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = (int) Math.sqrt(size / 100 / 1025.0); File tofile = new File(topath); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(tofile)); bitmap = BitmapFactory.decodeFile(frompath, options); bitmap.compress(Bitmap.CompressFormat.JPEG, pix, bos); bos.close(); }
/** * Generates the drawing on canvas to the dot file. * * @param filename * the name for the output file. By convention, it should end with DOT_EXTENSION, but this is not enforced. */ public void plot(String filename) { try { BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(filename)); render(out, 0); out.close(); } catch (IOException ioe) { logger.debug("" + ioe.getMessage()); } }
public void write() throws IOException { final BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(khFile)); try { for (KnownHostEntry entry : entries) bos.write((entry.getLine() + LS).getBytes(IOUtils.UTF8)); } finally { bos.close(); } }
private byte[] getBytesFromInputStream(InputStream is) throws Exception { BufferedInputStream bufIn = new BufferedInputStream(is); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos); int c = bufIn.read(); while (c != -1) { bos.write(c); c = bufIn.read(); } bos.flush(); baos.flush(); //bufIn.close(); //don't do that, since it closes the ZipInputStream after we've read an entry! bos.close(); return baos.toByteArray(); }
public static byte[] getBytesFromInputStream(InputStream is) throws Exception { BufferedInputStream bufIn = new BufferedInputStream(is); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(baos); int c = bufIn.read(); while (c != -1) { bos.write(c); c = bufIn.read(); } bos.flush(); baos.flush(); //bufIn.close(); //don't do that, since it closes the ZipInputStream after we've read an entry! bos.close(); return baos.toByteArray(); }
ZipEntry entry = (ZipEntry) enumeration.nextElement(); if (entry.isDirectory()) { new File(filePath, entry.getName()).mkdirs(); continue; BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry)); File file = new File(filePath + File.separator + entry.getName()); BufferedOutputStream bos = null; try { fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos, TypedValue.BUFFER_SIZE); bos.flush(); bos.close();