List of usage examples for java.io OutputStream write
public void write(byte b[], int off, int len) throws IOException
len
bytes from the specified byte array starting at offset off
to this output stream. From source file:com.stratio.decision.unit.engine.action.CassandraServer.java
/** * Copies a resource from within the jar to a directory. * //from w w w . j ava 2s.c o m * @param resource * @param directory * @throws IOException */ private static void copy(String resource, String directory) throws IOException { mkdir(directory); InputStream is = CassandraServer.class.getResourceAsStream(resource); String fileName = resource.substring(resource.lastIndexOf("/") + 1); File file = new File(directory + File.separator + fileName); OutputStream out = new FileOutputStream(file); byte buf[] = new byte[1024]; int len; while ((len = is.read(buf)) > 0) { out.write(buf, 0, len); } out.close(); is.close(); }
From source file:de.handtwerk.android.IoHelper.java
public static void copy(InputStream pIn, OutputStream pOut) throws IOException { byte[] buffer = new byte[1024]; int read;/* w w w. j a va 2s . co m*/ while ((read = pIn.read(buffer)) != -1) { pOut.write(buffer, 0, read); } pIn.close(); pOut.flush(); pOut.close(); }
From source file:fiftyone.mobile.detection.webapp.ImageCache.java
/** * Adds the image at the width and height provided to the cache. * @param imageLocal/*from w w w. j a v a 2s. co m*/ * @param width * @param height * @param imageAsStream * @throws IOException */ synchronized static void add(File physicalPath, File cacheFile, int width, int height, InputStream imageAsStream) throws IOException { new File(cacheFile.getParent()).mkdirs(); cacheFile.createNewFile(); OutputStream outputStream = new FileOutputStream(cacheFile); int read = 0; byte[] bytes = new byte[1024 ^ 2]; while ((read = imageAsStream.read(bytes)) != -1) { outputStream.write(bytes, 0, read); } outputStream.close(); }
From source file:Main.java
public static void copyStream(InputStream is, OutputStream os) { final int buffer_size = 1024; try {/*from w w w . j a v a 2s . c o m*/ byte[] bytes = new byte[buffer_size]; for (;;) { int count = is.read(bytes, 0, buffer_size); if (count == -1) { break; } os.write(bytes, 0, count); } } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
/** * Creates a copy of a file// w w w. j av a 2 s . c om * @param source The file you want to copy * @param destination The destination you want to copy the file to * @throws IOException An error occurred while copying the file */ public static void copyFile(File source, File destination) throws IOException { InputStream in = null; OutputStream out = null; try { in = new FileInputStream(source); out = new FileOutputStream(destination); byte[] buffer = new byte[1024]; int length; while ((length = in.read(buffer)) > 0) { out.write(buffer, 0, length); } } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } }
From source file:Main.java
public static void CopyStream(final InputStream is, final OutputStream os) { final int buffer_size = 1024; try {//from w ww .j av a2s .co m final byte[] bytes = new byte[buffer_size]; for (;;) { final int count = is.read(bytes, 0, buffer_size); if (count == -1) { break; } os.write(bytes, 0, count); } } catch (final Exception ex) { } }
From source file:com.inmobi.conduit.distcp.tools.util.TestThrottledInputStream.java
private static void copyBytesWithOffset(InputStream in, OutputStream out, int buffSize) throws IOException { byte buf[] = new byte[buffSize]; int bytesRead = in.read(buf, 0, buffSize); while (bytesRead >= 0) { out.write(buf, 0, bytesRead); bytesRead = in.read(buf);//from w ww. ja va 2 s . c om } }
From source file:Main.java
/** * write file// w ww . j av a 2 s. c o m * * @param filePath * @param stream * @return return true * @throws IOException * if an error occurs while operator FileWriter */ public static boolean writeFile(String filePath, InputStream stream) { OutputStream o = null; try { o = new FileOutputStream(filePath); byte data[] = new byte[1024]; int length = -1; while ((length = stream.read(data)) != -1) { o.write(data, 0, length); } o.flush(); return true; } catch (FileNotFoundException e) { throw new RuntimeException("FileNotFoundException occurred. ", e); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } finally { if (o != null) { try { o.close(); stream.close(); } catch (IOException e) { throw new RuntimeException("IOException occurred. ", e); } } } }
From source file:Main.java
public static void copyFile(File source, File dest) throws IOException { InputStream inputStream = null; OutputStream outputStream = null; try {/*from w w w . j a v a2 s . c o m*/ inputStream = new FileInputStream(source); outputStream = new FileOutputStream(dest); byte[] buffer = new byte[1024]; int length; while ((length = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, length); } } finally { if (inputStream != null) { inputStream.close(); } if (outputStream != null) { outputStream.close(); } } }
From source file:es.alrocar.map.vector.provider.filesystem.impl.GeoJSONFileSystemProvider.java
public static void copy(InputStream in, OutputStream out) throws IOException { byte[] b = new byte[1024 * 8]; int read;//from www .j a va 2 s .c om while ((read = in.read(b)) != -1) { out.write(b, 0, read); } }