Example usage for java.io BufferedOutputStream BufferedOutputStream

List of usage examples for java.io BufferedOutputStream BufferedOutputStream

Introduction

In this page you can find the example usage for java.io BufferedOutputStream BufferedOutputStream.

Prototype

public BufferedOutputStream(OutputStream out) 

Source Link

Document

Creates a new buffered output stream to write data to the specified underlying output stream.

Usage

From source file:net.sourceforge.atunes.utils.ZipUtils.java

/**
 * Unzips a zip entry in a directory/* ww  w . ja  va 2 s .c  o m*/
 * 
 * @param zipfile
 * @param entry
 * @param outputDir
 * @throws IOException
 */
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException {
    if (entry.isDirectory()) {
        createDir(new File(outputDir, entry.getName()));
        return;
    }
    File outputFile = new File(outputDir, entry.getName());
    if (!outputFile.getParentFile().exists()) {
        createDir(outputFile.getParentFile());
    }
    BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
    BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile));
    try {
        IOUtils.copy(inputStream, outputStream);
    } finally {
        ClosingUtils.close(outputStream);
        ClosingUtils.close(inputStream);
    }
}

From source file:com.mesosphere.dcos.cassandra.executor.compress.SnappyCompressionDriver.java

@Override
public void compress(final String sourcePath, final String destinationPath) throws IOException {
    BufferedInputStream inputStream = null;
    SnappyOutputStream compressedStream = null;
    try {/* w  w  w  .j  a v a  2  s . c o m*/
        inputStream = new BufferedInputStream(new FileInputStream(sourcePath));
        compressedStream = new SnappyOutputStream(
                new BufferedOutputStream(new FileOutputStream(destinationPath)));
        IOUtils.copy(inputStream, compressedStream);
    } catch (IOException e) {
        LOGGER.error("Failed to compress {} to {} due to: {}", sourcePath, destinationPath, e);
    } finally {
        IOUtils.closeQuietly(inputStream);
        IOUtils.closeQuietly(compressedStream);
    }
}

From source file:com.sec.ose.osi.util.tools.FileOperator.java

public static void copyFile(File pSource, File pDest) throws FileNotFoundException {

    if (pSource == null)
        throw new FileNotFoundException("Source file is not found");

    if (pSource.exists() == false)
        throw new FileNotFoundException(pSource.getPath());

    if (pDest == null)
        throw new FileNotFoundException("Report file is not found");

    BufferedInputStream bi = null;
    BufferedOutputStream bo = null;

    try {/*from w  w  w  .j av  a 2 s.  c o  m*/
        bi = new BufferedInputStream(new FileInputStream(pSource)); // FileNotFoundExeption
        bo = new BufferedOutputStream(new FileOutputStream(pDest));

        byte buffer[] = new byte[BUF_SIZE];

        int readByte = 0;

        while ((readByte = bi.read(buffer)) != -1) { // IOException
            bo.write(buffer, 0, readByte);

        }

    } catch (FileNotFoundException e) {
        log.warn(e);
        throw e;
    } catch (IOException e) {
        log.warn(e);
    } finally {

        if (bo != null) {
            try {
                bo.flush();

            } catch (IOException e) {
                // TODO Auto-generated catch block
                log.warn(e);
            }
            try {
                bo.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                log.warn(e);
            }

            bo = null;
        }
        if (bi != null) {
            try {
                bi.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                log.warn(e);
            }
            bi = null;
        }
    }

}

From source file:com.fizzed.stork.assembly.AssemblyUtils.java

static public TarArchiveOutputStream createTGZStream(File tgzFile) throws IOException {
    TarArchiveOutputStream tgzout = new TarArchiveOutputStream(
            new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(tgzFile))));
    tgzout.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
    tgzout.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
    return tgzout;
}

From source file:co.com.soinsoftware.altablero.utils.FileUtils.java

public boolean savePhotoInServer(final MultipartFile file, final String name) {
    boolean saved = false;
    final String fileName = PATH + name;
    if (file != null && !file.isEmpty()) {
        try {/*from   w  w w  .ja  v  a 2 s.c om*/
            final String directory = fileName.substring(0, fileName.lastIndexOf(File.separator));
            final File dirFile = new File(directory);
            if (!dirFile.exists()) {
                dirFile.mkdirs();
            }
            final byte[] bytes = file.getBytes();
            final OutputStream os = new FileOutputStream(new File(fileName));
            try (final BufferedOutputStream stream = new BufferedOutputStream(os)) {
                stream.write(bytes);
                saved = true;
            }
        } catch (Exception ex) {
            LOGGER.error(ex.getMessage(), ex);
        }
    }
    return saved;
}

From source file:org.crazydog.util.spring.FileCopyUtils.java

/**
 * Copy the contents of the given byte array to the given output File.
 * @param in the byte array to copy from
 * @param out the file to copy to/*from   w  ww . ja  v a  2 s  .c  om*/
 * @throws IOException in case of I/O errors
 */
public static void copy(byte[] in, File out) throws IOException {
    org.springframework.util.Assert.notNull(in, "No input byte array specified");
    org.springframework.util.Assert.notNull(out, "No output File specified");
    ByteArrayInputStream inStream = new ByteArrayInputStream(in);
    OutputStream outStream = new BufferedOutputStream(new FileOutputStream(out));
    copy(inStream, outStream);
}

From source file:abfab3d.io.output.SVXWriter.java

/**
 * Writes a grid out to an svx file//ww  w.j  ava2 s  .  co  m
 * @param grid
 * @param file
 */
public void write(AttributeGrid grid, String file) {
    FileOutputStream fos = null;
    BufferedOutputStream bos = null;

    try {
        fos = new FileOutputStream(file);
        bos = new BufferedOutputStream(fos);
        write(grid, bos);
    } catch (IOException ioe) {

        ioe.printStackTrace();

    } finally {
        IOUtils.closeQuietly(bos);
        IOUtils.closeQuietly(fos);
    }

}

From source file:librarymanagementsystem.Base64Converter.java

/**
 * This method writes byte array content into a file.
 *//*from w  ww . j  ava 2  s.c o m*/
public static void writeByteArraysToFile(String fileName, byte[] content) throws IOException {

    File file = new File(fileName);
    BufferedOutputStream writer = new BufferedOutputStream(new FileOutputStream(file));
    writer.write(content);
    writer.flush();
    writer.close();

}

From source file:de.bfs.radon.omsimulation.gui.data.OMExports.java

/**
 * /*from   www .  j a  va  2  s. c  om*/
 * Method to export charts as PDF files using the defined path.
 * 
 * @param path
 *          The filename and absolute path.
 * @param chart
 *          The JFreeChart object.
 * @param width
 *          The width of the PDF file.
 * @param height
 *          The height of the PDF file.
 * @param mapper
 *          The font mapper for the PDF file.
 * @param title
 *          The title of the PDF file.
 * @throws IOException
 *           If writing a PDF file fails.
 */
@SuppressWarnings("deprecation")
public static void exportPdf(String path, JFreeChart chart, int width, int height, FontMapper mapper,
        String title) throws IOException {
    File file = new File(path);
    FileOutputStream pdfStream = new FileOutputStream(file);
    BufferedOutputStream pdfOutput = new BufferedOutputStream(pdfStream);
    Rectangle pagesize = new Rectangle(width, height);
    Document document = new Document();
    document.setPageSize(pagesize);
    document.setMargins(50, 50, 50, 50);
    document.addAuthor("OMSimulationTool");
    document.addSubject(title);
    try {
        PdfWriter pdfWriter = PdfWriter.getInstance(document, pdfOutput);
        document.open();
        PdfContentByte contentByte = pdfWriter.getDirectContent();
        PdfTemplate template = contentByte.createTemplate(width, height);
        Graphics2D g2D = template.createGraphics(width, height, mapper);
        Double r2D = new Rectangle2D.Double(0, 0, width, height);
        chart.draw(g2D, r2D);
        g2D.dispose();
        contentByte.addTemplate(template, 0, 0);
    } catch (DocumentException de) {
        JOptionPane.showMessageDialog(null, "Failed to write PDF document.\n" + de.getMessage(), "Failed",
                JOptionPane.ERROR_MESSAGE);
        de.printStackTrace();
    }
    document.close();
}

From source file:com.mobeelizer.java.sync.MobeelizerOutputData.java

public MobeelizerOutputData(final File file, final File tmpFile) {
    try {/*from w w w. j  a v a2  s. com*/
        zip = new ZipOutputStream(new FileOutputStream(file));
        dataFile = tmpFile;
        dataOutputStream = new BufferedOutputStream(new FileOutputStream(dataFile));
        deletedFiles = new LinkedList<String>();
    } catch (IOException e) {
        closeQuietly(zip);
        closeQuietly(dataOutputStream);
        throw new IllegalStateException(e.getMessage(), e);
    }
}