Example usage for java.io BufferedInputStream BufferedInputStream

List of usage examples for java.io BufferedInputStream BufferedInputStream

Introduction

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

Prototype

public BufferedInputStream(InputStream in, int size) 

Source Link

Document

Creates a BufferedInputStream with the specified buffer size, and saves its argument, the input stream in, for later use.

Usage

From source file:com.yqboots.fss.util.ZipUtils.java

/**
 * Compresses the specified directory to a zip file
 *
 * @param dir the directory to compress/*  ww w.  ja v a  2 s  .c  om*/
 * @return the compressed file
 * @throws IOException
 */
public static Path compress(Path dir) throws IOException {
    Assert.isTrue(Files.exists(dir), "The directory does not exist: " + dir.toAbsolutePath());
    Assert.isTrue(Files.isDirectory(dir), "Should be a directory: " + dir.toAbsolutePath());

    Path result = Paths.get(dir.toAbsolutePath() + FileType.DOT_ZIP);
    try (final ZipOutputStream out = new ZipOutputStream(
            new BufferedOutputStream(new FileOutputStream(result.toFile())))) {
        // out.setMethod(ZipOutputStream.DEFLATED);
        final byte data[] = new byte[BUFFER];
        // get a list of files from current directory
        Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(final Path path, final BasicFileAttributes attrs)
                    throws IOException {
                final File file = path.toFile();

                // compress to relative directory, not absolute
                final String root = StringUtils.substringAfter(file.getParent(), dir.toString());
                try (final BufferedInputStream origin = new BufferedInputStream(new FileInputStream(file),
                        BUFFER)) {
                    final ZipEntry entry = new ZipEntry(root + File.separator + path.getFileName());
                    out.putNextEntry(entry);
                    int count;
                    while ((count = origin.read(data, 0, BUFFER)) != -1) {
                        out.write(data, 0, count);
                    }
                }

                return FileVisitResult.CONTINUE;
            }
        });
    }

    return result;
}

From source file:edu.jhu.hlt.concrete.stanford.AnnotatedNYTTest.java

@Before
public void setUp() throws Exception {
    try (InputStream is = Files.newInputStream(p);
            BufferedInputStream bin = new BufferedInputStream(is, 1024 * 8 * 16);) {
        byte[] nytdocbytes = IOUtils.toByteArray(bin);
        this.nytComm = new CommunicationizableAnnotatedNYTDocument(
                new AnnotatedNYTDocument(parser.fromByteArray(nytdocbytes, false))).toCommunication();
    }//from   w  ww . j a va 2s .c  o  m
}