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) 

Source Link

Document

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

Usage

From source file:io.github.blindio.prospero.core.browserdrivers.phantomjs.TarBZip2UnArchiver.java

public void extract() {
    /** create a TarArchiveInputStream object. **/

    try {//  w  w  w .j a  v a2  s  .  c  om
        FileInputStream fin = new FileInputStream(getSourceFile());
        BufferedInputStream in = new BufferedInputStream(fin);
        BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in);
        ArchiveInputStream arcIn = new TarArchiveInputStream(bzIn);

        extract(arcIn);
    } catch (IOException ioe) {
        throw new ProsperoIOException(ioe);
    }
}

From source file:backend.translator.GTranslator.java

private File downloadFile(String url) throws IOException {
    HttpClient client = HttpClientBuilder.create().build();
    HttpGet request = new HttpGet(url);
    request.addHeader("User-Agent", "Mozilla/5.0");
    HttpResponse response = client.execute(request);
    HttpEntity entity = response.getEntity();
    BufferedInputStream bis = new BufferedInputStream(entity.getContent());
    File f = new File(R.TRANS_RESULT_PATH);
    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f));
    int inByte;//w w  w  .j a  va  2  s.  c  o  m
    while ((inByte = bis.read()) != -1)
        bos.write(inByte);

    bis.close();
    bos.close();
    return f;
}

From source file:de.rub.syssec.saaf.analysis.steps.extract.ApkUnzipper.java

/**
 * Extracts the given archive into the given destination directory
 * /*from   w  w  w .ja  v a2s. co  m*/
 * @param archive
 *            - the file to extract
 * @param dest
 *            - the destination directory
 * @throws Exception
 */
public static void extractArchive(File archive, File destDir) throws IOException {

    if (!destDir.exists()) {
        destDir.mkdir();
    }

    ZipFile zipFile = new ZipFile(archive);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();

    byte[] buffer = new byte[16384];
    int len;
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();

        String entryFileName = entry.getName();

        File dir = buildDirectoryHierarchyFor(entryFileName, destDir);
        if (!dir.exists()) {
            dir.mkdirs();
        }

        if (!entry.isDirectory()) {

            File file = new File(destDir, entryFileName);

            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));

            BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));

            while ((len = bis.read(buffer)) > 0) {
                bos.write(buffer, 0, len);
            }

            bos.flush();
            bos.close();
            bis.close();
        }
    }
    zipFile.close();
}

From source file:com.tempescope.wunderground.WeatherLocationManager.java

public static WeatherLocationManager getManager(File file) {
    if (!file.exists()) {
        WeatherLocationManager manager = new WeatherLocationManager();
        manager.file = file;/*  w  w  w. jav a 2  s. c  o m*/
        return manager;
    }
    try {
        ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)));
        WeatherLocationManager manager = (WeatherLocationManager) in.readObject();
        in.close();
        manager.file = file;
        return manager;
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
}

From source file:net.orpiske.ssps.common.archive.CompressedArchiveUtils.java

/**
 * Decompress a file// w  w  w .j a  v a  2s.  c om
 * @param source the source file to be uncompressed
 * @param destination the destination directory
 * @return the number of bytes read
 * @throws IOException for lower level I/O errors
 */
public static long gzDecompress(File source, File destination) throws IOException {
    FileOutputStream out;

    prepareDestination(destination);
    out = new FileOutputStream(destination);

    FileInputStream fin = null;
    BufferedInputStream bin = null;
    GzipCompressorInputStream gzIn = null;

    try {
        fin = new FileInputStream(source);
        bin = new BufferedInputStream(fin);
        gzIn = new GzipCompressorInputStream(bin);

        IOUtils.copy(gzIn, out);

        gzIn.close();

        fin.close();
        bin.close();
        out.close();
    } catch (IOException e) {
        IOUtils.closeQuietly(out);

        IOUtils.closeQuietly(fin);
        IOUtils.closeQuietly(bin);
        IOUtils.closeQuietly(gzIn);

        throw e;
    }

    return gzIn.getBytesRead();
}

From source file:de.fanero.uncompress.stream.DeepArchiveInputStreamTest.java

private InputStream load(String resourceName) {
    return new BufferedInputStream(DeepArchiveInputStreamTest.class.getResourceAsStream(resourceName));
}

From source file:net.sf.ehcache.config.ConfigurationFactory.java

/**
 * Configures a bean from an XML file./*  www  . j  a v  a2 s  .co m*/
 */
public static Configuration parseConfiguration(final File file) throws CacheException {
    if (file == null) {
        throw new CacheException("Attempt to configure ehcache from null file.");
    }

    if (LOG.isDebugEnabled()) {
        LOG.debug("Configuring ehcache from file: " + file.toString());
    }
    Configuration configuration = null;
    InputStream input = null;
    try {
        input = new BufferedInputStream(new FileInputStream(file));
        configuration = parseConfiguration(input);
    } catch (Exception e) {
        throw new CacheException("Error configuring from " + file + ". Initial cause was " + e.getMessage(), e);
    } finally {
        try {
            if (input != null) {
                input.close();
            }
        } catch (IOException e) {
            LOG.error("IOException while closing configuration input stream. Error was " + e.getMessage());
        }
    }
    return configuration;
}

From source file:net.chuzarski.crowdednews.activities.LicenseActivity.java

private String readLicenses() {
    InputStream file = null;/*from   w  w  w. j  a v a2  s  .  c  om*/
    String license;

    try {
        file = getAssets().open("LICENSES.txt");
        license = IOUtils.toString(new BufferedInputStream(file));
        file.close();
    } catch (IOException e) {
        return "Licenses are broken";
    }

    return license;
}

From source file:jm.web.Ftp.java

public boolean subirArchivo(String rutaArchivo, String rutaArchivoRemoto) {
    try {/*from w ww .j  a v  a  2 s. com*/
        BufferedInputStream buffIn = new BufferedInputStream(new FileInputStream(rutaArchivo));//Ruta del archivo para enviar
        this.ftp.enterLocalPassiveMode();
        this.ftp.storeFile(rutaArchivoRemoto, buffIn);//Ruta completa de alojamiento en el FTP
        buffIn.close(); //Cerrar envio de arctivos al FTP
        return true;
    } catch (Exception e) {
        this.error = e.getMessage();
    }
    return false;
}

From source file:com.foreignreader.util.WordNetExtractor.java

@Override
protected Void doInBackground(InputStream... streams) {
    assert streams.length == 1;

    try {/*from  w w w.  j ava 2s  .  c  o m*/

        BufferedInputStream in = new BufferedInputStream(streams[0]);
        GzipCompressorInputStream gzIn = new GzipCompressorInputStream(in);

        TarArchiveInputStream tar = new TarArchiveInputStream(gzIn);

        TarArchiveEntry tarEntry;

        File dest = LongTranslationHelper.getWordNetDict().getParentFile();

        while ((tarEntry = tar.getNextTarEntry()) != null) {
            File destPath = new File(dest, tarEntry.getName());
            if (tarEntry.isDirectory()) {
                destPath.mkdirs();
            } else {
                destPath.createNewFile();
                byte[] btoRead = new byte[1024 * 10];

                BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(destPath));
                int len = 0;

                while ((len = tar.read(btoRead)) != -1) {
                    bout.write(btoRead, 0, len);
                }

                bout.close();

            }
        }

        tar.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    return null;
}