List of usage examples for java.io BufferedOutputStream BufferedOutputStream
public BufferedOutputStream(OutputStream out)
From source file:mpimp.assemblxweb.util.J5FileUtils.java
public static void zipDirectory(String dirPath, String targetPath) throws Exception { BufferedInputStream origin = null; FileOutputStream dest = new FileOutputStream(targetPath); ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(dest)); out.setMethod(ZipOutputStream.DEFLATED); int BUFFER = 2048; byte data[] = new byte[BUFFER]; zipDirectoryRecursively(dirPath, origin, BUFFER, out, data, new File(dirPath).getName()); out.close();/*from w w w. j av a 2 s .c o m*/ }
From source file:ezbake.frack.submitter.util.JarUtilTest.java
@Test public void addFileToJar() throws IOException { File tmpDir = new File("jarUtilTest"); try {/*www.jav a 2 s. c o m*/ tmpDir.mkdirs(); // Push the example jar to a file byte[] testJar = IOUtils.toByteArray(this.getClass().getResourceAsStream("/example.jar")); File jarFile = new File(tmpDir, "example.jar"); BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(jarFile)); os.write(testJar); os.close(); // Push the test content to a file byte[] testContent = IOUtils.toByteArray(this.getClass().getResourceAsStream("/test.txt")); String stringTestContent = new String(testContent); File testFile = new File(tmpDir, "test.txt"); os = new BufferedOutputStream(new FileOutputStream(testFile)); os.write(testContent); os.close(); assertTrue(jarFile.exists()); assertTrue(testFile.exists()); // Add the new file to the jar File newJar = JarUtil.addFilesToJar(jarFile, Lists.newArrayList(testFile)); assertTrue("New jar file exists", newJar.exists()); assertTrue("New jar is a file", newJar.isFile()); // Roll through the entries of the new jar and JarInputStream is = new JarInputStream(new FileInputStream(newJar)); JarEntry entry = is.getNextJarEntry(); boolean foundNewFile = false; String content = ""; while (entry != null) { String name = entry.getName(); if (name.endsWith("test.txt")) { foundNewFile = true; byte[] buffer = new byte[1]; while ((is.read(buffer)) > 0) { content += new String(buffer); } break; } entry = is.getNextJarEntry(); } is.close(); assertTrue("New file was in repackaged jar", foundNewFile); assertEquals("Content of added file is the same as the retrieved new file", stringTestContent, content); } finally { FileUtils.deleteDirectory(tmpDir); } }
From source file:net.sf.jabref.exporter.OpenOfficeDocumentCreator.java
private static void storeOpenOfficeFile(File file, InputStream source) throws Exception { try (ZipOutputStream out = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(file)))) { ZipEntry zipEntry = new ZipEntry("content.xml"); out.putNextEntry(zipEntry);//from ww w . j av a2 s . c o m int c; while ((c = source.read()) >= 0) { out.write(c); } out.closeEntry(); // Add manifest (required for OOo 2.0), "meta.xml", "mimetype" files. These are in the // resource/openoffice directory, and are copied verbatim into the zip file. OpenOfficeDocumentCreator.addResourceFile("meta.xml", "/resource/openoffice/meta.xml", out); OpenOfficeDocumentCreator.addResourceFile("mimetype", "/resource/openoffice/mimetype", out); OpenOfficeDocumentCreator.addResourceFile("META-INF/manifest.xml", "/resource/openoffice/manifest.xml", out); } }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.common.logging.LoggerDestinationFastTest.java
@Test public void stdoutLoggerDestination() throws IOException, LoggerDestination.LoggerException { PrintStream outStream = null; try {//from ww w .j av a 2 s.co m // redirect stdout to a file String outfile = OUTPUT_PATH + "stdout.txt"; //noinspection IOResourceOpenedButNotSafelyClosed outStream = new PrintStream(new BufferedOutputStream(new FileOutputStream(outfile))); System.setOut(outStream); // send message to logger destination StdoutLoggerDestination dest = new StdoutLoggerDestination(); dest.setMinLevel(Level.DEBUG); String message = "THIS IS AN ERROR MESSAGE"; dest.logToDestination(Level.ERROR, message); outStream.close(); // read in output file and compare to expected assertEquals(message, readFirstLine(outfile)); new File(outfile).deleteOnExit(); } finally { IOUtils.closeQuietly(outStream); } }
From source file:mase.me.MEFinalRepertoireStat.java
@Override public void finalStatistics(EvolutionState state, int result) { super.finalStatistics(state, result); if (compress) { try {/*from www. j av a 2 s. co m*/ taos = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(archiveFile)))); } catch (IOException ex) { Logger.getLogger(BestSolutionGenStat.class.getName()).log(Level.SEVERE, null, ex); } } if (!compress && !archiveFile.exists()) { archiveFile.mkdirs(); } MESubpopulation sub = (MESubpopulation) state.population.subpops[0]; Collection<Entry<Integer, Individual>> entries = sub.map.entries(); for (Entry<Integer, Individual> e : entries) { PersistentSolution p = SolutionPersistence.createPersistentController(state, e.getValue(), 0, e.getKey()); p.setUserData(sub.getBehaviourVector(state, e.getValue())); try { if (compress) { SolutionPersistence.writeSolutionToTar(p, taos); } else { SolutionPersistence.writeSolutionInFolder(p, archiveFile); } } catch (IOException ex) { Logger.getLogger(BestSolutionGenStat.class.getName()).log(Level.SEVERE, null, ex); } } if (compress) { try { taos.close(); } catch (IOException ex) { Logger.getLogger(MEFinalRepertoireStat.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:net.zcarioca.jmx.servlet.handlers.RestRequestHandler.java
public void respond(HttpServletRequest request, HttpServletResponse response) throws IOException { try {//from www.j a va 2 s .com Object value = getResponse(request); if (value != null) { response.setContentType(MediaType.APPLICATION_JSON); response.setCharacterEncoding("UTF-8"); BufferedOutputStream out = new BufferedOutputStream(response.getOutputStream()); ObjectMapper mapper = new ObjectMapper(); mapper.writeValue(out, value); out.flush(); out.close(); } else { response.sendError(HttpServletResponse.SC_NOT_FOUND); } } catch (InvalidObjectException exc) { response.sendError(HttpServletResponse.SC_BAD_REQUEST); } catch (IOException exc) { throw exc; } catch (Exception exc) { response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } }
From source file:de.nrw.hbz.deepzoomer.fileUtil.FileUtil.java
/** * <p><em>Title: Create a temporary File from a Base64 encoded byteStream</em></p> * <p>Description: Method creates a temporary file from the bytestream * representing the orginal PDF, that should be converted</p> * /*from w w w. j a v a 2 s . c om*/ * @param stream <code>String</code> * @return <code>String</code> Filename of newly created temporary File */ public static String saveStreamToTempFile(String fileName, String stream) { FileOutputStream fos = null; BufferedOutputStream bos = null; try { //System.out.println("Base64 kodierter Stream: " + stream.length()); inputFile = new File(Configuration.getTempDirPath() + fileName); log.debug(Configuration.getTempDirPath()); fos = new FileOutputStream(inputFile); bos = new BufferedOutputStream(fos); bos.write(Base64.decodeBase64(stream.getBytes("UTF-8"))); } catch (IOException ioExc) { log.error(ioExc); } finally { if (bos != null) { try { bos.close(); } catch (IOException ioExc) { log.error(ioExc); } } if (fos != null) { try { fos.close(); } catch (IOException ioExc) { log.error(ioExc); } } } log.debug("File-Size: " + inputFile.length()); return inputFile.getName(); }
From source file:joachimeichborn.geotag.io.writer.kml.KmlWriter.java
/** * Create the output KML file containing: * <ul>/*from w ww. j av a2 s . c o m*/ * <li>placemarks for all positions * <li>a path connecting all positions in chronological order * <li>circles showing the accuracy information for all positions * </ul> * * @throws IOException */ public void write(final Track aTrack, final Path aOutputFile) throws IOException { final String documentTitle = FilenameUtils.removeExtension(aOutputFile.getFileName().toString()); final GeoTagKml kml = createKml(documentTitle, aTrack); try (final Writer kmlWriter = new OutputStreamWriter( new BufferedOutputStream(new FileOutputStream(aOutputFile.toFile())), StandardCharsets.UTF_8)) { kml.marshal(kmlWriter); } logger.fine("Wrote track to " + aOutputFile); }
From source file:io.cloudslang.orchestrator.services.ExecutionSerializationUtil.java
public byte[] objToBytes(Execution obj) { ObjectOutputStream oos;//ww w. java 2 s . c o m try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); BufferedOutputStream bos = new BufferedOutputStream(bout); oos = new ObjectOutputStream(bos); oos.writeObject(obj); oos.close(); @SuppressWarnings({ "UnnecessaryLocalVariable" }) byte[] bytes = bout.toByteArray(); return bytes; } catch (IOException ex) { throw new RuntimeException("Failed to serialize execution . Error: ", ex); } }
From source file:ja.lingo.engine.searchindex.NodeSerializer.java
public NodeSerializer(String fileName) throws IOException { Arguments.assertNotNull("fileName", fileName); this.fileName = fileName; tempFileName = EngineFiles.createTemp("search.index"); tempDos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(tempFileName))); timeMeasurer = new TimeMeasurer(false); }