List of usage examples for java.io BufferedInputStream read
public synchronized int read() throws IOException
read
method of InputStream
. From source file:Main.java
public static String InputStreamToString(InputStream theInput) { BufferedInputStream inputBuffer = new BufferedInputStream(theInput); int byteRead = -1; StringBuilder builder = new StringBuilder(); try {//from ww w .j a v a2 s .co m while ((byteRead = inputBuffer.read()) != -1) { builder.append((char) byteRead); } } catch (IOException e) { e.printStackTrace(); } return builder.toString(); }
From source file:in.xebia.poc.FileUploadUtils.java
public static boolean bufferedCopyStream(InputStream inStream, OutputStream outStream) throws Exception { BufferedInputStream bis = new BufferedInputStream(inStream); BufferedOutputStream bos = new BufferedOutputStream(outStream); while (true) { int data = bis.read(); if (data == -1) { break; }/* ww w. j a v a 2 s . c o m*/ bos.write(data); } bos.flush(); bos.close(); return true; }
From source file:Main.java
private static File saveFile(InputStream is, String destDir, String fileName) throws IOException { File dir = new File(destDir); fileName = getString(fileName);/*from w w w .ja v a2 s .c o m*/ if (!dir.exists()) { dir.mkdirs(); } BufferedInputStream bis = new BufferedInputStream(is); BufferedOutputStream bos = null; try { File saveFile = new File(destDir, fileName); bos = new BufferedOutputStream(new FileOutputStream(saveFile)); int len = -1; while ((len = bis.read()) != -1) { bos.write(len); bos.flush(); } bos.close(); bis.close(); return saveFile; } catch (FileNotFoundException e) { e.printStackTrace(); } return null; }
From source file:net.sf.ginp.util.GinpUtil.java
/** * Writes the entire input stream to the output stream * then closes the input stream./*from w w w . ja v a 2s.c om*/ * @param sos output stream * @param is input stream * @throws IOException if there is an error reading or writing */ public static void writeInputStreamToOutputStream(final OutputStream sos, final InputStream is) throws IOException { BufferedInputStream in = new BufferedInputStream(is); int data; while ((data = in.read()) != -1) { sos.write(data); } is.close(); }
From source file:com.apps.android.viish.encyclolpedia.tools.ImageManager.java
private static void downloadAndSaveImageWithPrefix(Context context, String prefix, String fileName) throws IOException { String stringUrl = BASE_URL + prefix + fileName; URL url = new URL(stringUrl); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); InputStream is = urlConnection.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); FileOutputStream fos = getFileOutputStream(context, fileName); ByteArrayBuffer baf = new ByteArrayBuffer(65535); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); }//from w w w .j ava 2 s. co m fos.write(baf.toByteArray()); fos.close(); bis.close(); }
From source file:it.unicaradio.android.utils.NetworkUtils.java
public static byte[] httpGet(String urlString) throws IOException { URL url = new URL(urlString); URLConnection ucon = url.openConnection(); InputStream is = ucon.getInputStream(); BufferedInputStream bis = new BufferedInputStream(is); // Read bytes to the Buffer until there is nothing more to read(-1). ByteArrayBuffer baf = new ByteArrayBuffer(50); int current = 0; while ((current = bis.read()) != -1) { baf.append((byte) current); }/* w ww . j a va 2 s . c o m*/ return baf.toByteArray(); }
From source file:edu.caltech.ipac.firefly.server.network.HttpServices.java
static void readBody(OutputStream os, InputStream body) { BufferedInputStream bis = new BufferedInputStream(body); BufferedOutputStream bos = new BufferedOutputStream(os); try {//from w w w. ja v a2 s . c o m int b; while ((b = bis.read()) != -1) { bos.write(b); } bos.flush(); } catch (IOException e) { LOG.error(e, "Error while reading response body"); } }
From source file:downloadwolkflow.getWorkFlowList.java
private static void downloadFiles(String downloadUrl, CloseableHttpClient httpclient) { HttpGet httpget = new HttpGet(downloadUrl); HttpEntity entity = null;//w w w . j a va 2 s .co m try { HttpResponse response = httpclient.execute(httpget); entity = response.getEntity(); if (entity != null) { InputStream is = entity.getContent(); String filename = downloadUrl.split("/")[downloadUrl.split("/").length - 1].split("\\?")[0]; System.out.println(filename); BufferedInputStream bis = new BufferedInputStream(is); BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(new File("data/" + filename))); int readedByte; while ((readedByte = bis.read()) != -1) { bos.write(readedByte); } bis.close(); bos.close(); } } catch (IOException ex) { Logger.getLogger(DownloadFileTest.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.atlbike.etl.service.ClientFormLogin.java
private static void saveEntity(HttpEntity loginEntity) throws IOException, FileNotFoundException { InputStream inStream = loginEntity.getContent(); BufferedInputStream bis = new BufferedInputStream(inStream); String path = "localFile.csv"; BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(path))); int byteCount = 0; int inByte;/*from w w w.j av a 2s . co m*/ while ((inByte = bis.read()) != -1) { bos.write(inByte); byteCount++; } bis.close(); bos.close(); System.out.println("Byte Count: " + byteCount); }
From source file:burstcoin.jminer.core.checker.util.OCLChecker.java
public static String readInputStreamAsString(InputStream in) throws IOException { BufferedInputStream bis = new BufferedInputStream(in); ByteArrayOutputStream buf = new ByteArrayOutputStream(); int result = bis.read(); while (result != -1) { byte b = (byte) result; buf.write(b);//ww w .j av a2 s . c om result = bis.read(); } return buf.toString(); }