List of usage examples for java.io BufferedOutputStream write
@Override public synchronized void write(int b) throws IOException
From source file:downloadwolkflow.getWorkFlowList.java
private static void downloadFiles(String downloadUrl, CloseableHttpClient httpclient) { HttpGet httpget = new HttpGet(downloadUrl); HttpEntity entity = null;// ww w . j av a 2 s . c o 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: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; }/*from w ww. j a v a2s . c o m*/ bos.write(data); } bos.flush(); bos.close(); return true; }
From source file:de.jgoestl.massdatagenerator.MassDataGenerator.java
private static void writeOutput(String outputPath, StringBuilder output) { BufferedOutputStream bos = null; try {//from w w w. ja v a 2s. com File f = new File(outputPath); bos = new BufferedOutputStream(new FileOutputStream(f)); bos.write(output.toString().getBytes()); } catch (FileNotFoundException ex) { System.out.println("Output-File \"" + outputPath + "\" not found"); try { System.in.read(); } catch (IOException e) { Logger.getLogger(MassDataGenerator.class.getName()).log(Level.SEVERE, null, e); } System.exit(1); } catch (IOException ex) { Logger.getLogger(MassDataGenerator.class.getName()).log(Level.SEVERE, null, ex); } finally { try { if (bos != null) bos.close(); } catch (IOException ex) { Logger.getLogger(MassDataGenerator.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.jboss.as.test.integration.web.annotationsmodule.WebModuleDeploymentTestCase.java
private static void copyFile(File target, InputStream src) throws IOException { final BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(target)); try {//from w ww.ja v a 2 s .c om int i = src.read(); while (i != -1) { out.write(i); i = src.read(); } } finally { IoUtils.safeClose(out); } }
From source file:Main.java
public static File getFileFromBytes(byte[] b, String outputFile) { BufferedOutputStream stream = null; File file = null;//w ww. j a v a2s . c o m try { file = new File(outputFile); if (!file.getParentFile().exists()) { file.getParentFile().mkdirs(); } FileOutputStream fstream = new FileOutputStream(file); stream = new BufferedOutputStream(fstream); stream.write(b); } catch (Exception e) { e.printStackTrace(); } finally { if (stream != null) { try { stream.close(); } catch (IOException e1) { e1.printStackTrace(); } } } return file; }
From source file:edu.harvard.i2b2.eclipse.plugins.metadataLoader.util.FileUtil.java
public static void download(String workingDir, String URL, String filename) throws IOException { workingDir = workingDir + filename;/*from w w w .ja v a 2 s. c o m*/ DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(URL); HttpResponse response = httpclient.execute(httpget); // System.out.println(response.getStatusLine()); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); try { BufferedInputStream bis = new BufferedInputStream(instream); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(workingDir))); int inByte; while ((inByte = bis.read()) != -1) { bos.write(inByte); } bis.close(); bos.close(); // unzip("ICD10.zip"); } catch (IOException ex) { throw ex; } catch (RuntimeException ex) { httpget.abort(); throw ex; } finally { instream.close(); } httpclient.getConnectionManager().shutdown(); } }
From source file:Main.java
public static File getFileFromBytes(byte[] b, String outputFile) { BufferedOutputStream stream = null; File file = null;//from w w w .ja v a 2 s. co m FileOutputStream fstream = null; try { file = new File(outputFile); if (!file.exists()) { file.createNewFile(); } fstream = new FileOutputStream(file); stream = new BufferedOutputStream(fstream); stream.write(b); } catch (Exception e) { e.printStackTrace(); } if (stream != null) { try { stream.close(); fstream.close(); } catch (Exception e1) { e1.printStackTrace(); } } System.gc(); return file; }
From source file:com.runwaysdk.controller.ErrorUtility.java
private static String compress(String message) { try {//from w w w . j a va2 s . c om ByteArrayOutputStream bos = new ByteArrayOutputStream(); BufferedOutputStream bufos = new BufferedOutputStream(new GZIPOutputStream(bos)); bufos.write(message.getBytes("UTF-8")); bufos.close(); bos.close(); byte[] bytes = bos.toByteArray(); return Base64.encodeToString(bytes, false); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:outfox.dict.contest.util.FileUtils.java
/** * //from ww w . j ava 2 s . c o m * @param b * @param outputFile * @return */ public static File getFileFromBytes(byte[] b, String outputFile) { File file = null; BufferedOutputStream stream = null; try { file = new File(outputFile); FileOutputStream fstream = new FileOutputStream(file); stream = new BufferedOutputStream(fstream); stream.write(b); } catch (Exception e) { LOG.error("FileUtils.getFileFromBytes in catch error...", e); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { LOG.error("FileUtils.getFileFromBytes in finally error...", e); } } } return file; }
From source file:Main.java
public static File getFileFromBytes(byte[] b, String outputFile) { File ret = null;/*from ww w .ja v a 2s .c o m*/ BufferedOutputStream stream = null; try { ret = new File(outputFile); if (!ret.exists()) { if (!ret.mkdirs()) { throw new FileNotFoundException("can't create folder" + outputFile); } } FileOutputStream fstream = new FileOutputStream(ret); stream = new BufferedOutputStream(fstream); stream.write(b); } catch (Exception e) { // log.error("helper:get file from byte process error!"); e.printStackTrace(); } finally { if (stream != null) { try { stream.close(); } catch (IOException e) { // log.error("helper:get file from byte process error!"); e.printStackTrace(); } } } return ret; }