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:com.example.facebook_photo.Utility.java

public static Bitmap getBitmap(String url) {
    Bitmap bm = null;//w ww . j  av a2s . c o  m
    try {
        URL aURL = new URL(url);
        URLConnection conn = aURL.openConnection();
        conn.connect();
        InputStream is = conn.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        bm = BitmapFactory.decodeStream(new FlushedInputStream(is));
        bis.close();
        is.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (httpclient != null) {
            httpclient.close();
        }
    }
    return bm;
}

From source file:com.compomics.pladipus.core.control.util.ZipUtils.java

private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDir) throws IOException {

    if (entry.isDirectory()) {
        createDir(new File(outputDir, entry.getName()));
        return;//from  w ww.  ja  v  a  2 s  .com
    }

    File outputFile = new File(outputDir, entry.getName());
    if (!outputFile.getParentFile().exists()) {
        createDir(outputFile.getParentFile());
    }

    LOGGER.debug("Extracting: " + entry);

    try (BufferedInputStream inputStream = new BufferedInputStream(zipfile.getInputStream(entry));
            BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(outputFile))) {
        IOUtils.copy(inputStream, outputStream);
        outputStream.flush();
    }
}

From source file:cn.mdict.utils.IOUtil.java

public static boolean streamDuplicate(InputStream is, OutputStream os, int bufferSize,
        StatusReport statusReport) {/*  w ww . j  a  v  a2 s .  c  om*/
    is = new BufferedInputStream(is);
    os = new BufferedOutputStream(os);
    byte[] buffer = new byte[bufferSize];
    int length;
    int count = 0;
    boolean result = false;
    try {
        while (((statusReport == null) || !statusReport.isCanceled()) && (length = is.read(buffer)) > 0) {
            os.write(buffer, 0, length);
            count += length;
            if (statusReport != null)
                statusReport.onProgressUpdate(count);
        }
        os.flush();
        result = true;
        if (statusReport != null) {
            if (statusReport.isCanceled())
                statusReport.onInterrupted();
            else
                statusReport.onComplete();
        }
    } catch (Exception e) {
        if (statusReport != null)
            statusReport.onError(e);
        else
            e.printStackTrace();
    } finally {
        forceClose(is);
        forceClose(os);
    }
    return result;
}

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

@Override
public ArchiveEntry getNextEntry() throws IOException {

    ArchiveEntry nextEntry = archiveInputStream.getNextEntry();
    this.buffered = new BufferedInputStream(archiveInputStream);
    return nextEntry;
}

From source file:com.amazonaws.services.simpleworkflow.flow.examples.deployment.DeploymentInitiator.java

public static String loadFile(String fileName) throws IOException {
    int length = (int) new File(fileName).length();
    byte[] buffer = new byte[length];
    BufferedInputStream is = null;
    try {// ww w. j  a  va 2s  . c om
        is = new BufferedInputStream(new FileInputStream(fileName));
        is.read(buffer);
    } finally {
        if (is != null) {
            is.close();
        }
    }
    return new String(buffer);
}

From source file:facturacion.ftp.FtpServer.java

public static int sendTokenInputStream(String fileNameServer, String hostDirServer, InputStream localFile) {
    FTPClient ftpClient = new FTPClient();
    boolean success = false;
    BufferedInputStream buffIn = null;
    try {//w w  w  .  j  a v a  2s .  c  o  m
        ftpClient.connect(Config.getInstance().getProperty(Config.ServerFtpToken),
                Integer.parseInt(Config.getInstance().getProperty(Config.PortFtpToken)));
        ftpClient.login(Config.getInstance().getProperty(Config.UserFtpToken),
                Config.getInstance().getProperty(Config.PassFtpToken));
        ftpClient.enterLocalPassiveMode();
        /*ftpClient.connect("127.0.0.1", 21);
          ftpClient.login("erpftp", "Tribut@2014");*/
        ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

        int reply = ftpClient.getReplyCode();

        System.out.println("Respuesta recibida de conexin FTP:" + reply);

        if (!FTPReply.isPositiveCompletion(reply)) {
            System.out.println("Imposible conectarse al servidor");
            return -1;
        }

        buffIn = new BufferedInputStream(localFile);//Ruta del archivo para enviar
        ftpClient.enterLocalPassiveMode();
        //crear directorio
        System.out.println(hostDirServer);
        success = ftpClient.makeDirectory(hostDirServer);
        System.out.println("sucess 1133 = " + success);
        //showServerReply(ftpClient);
        success = ftpClient.makeDirectory(hostDirServer + "/token");
        /*
        System.out.println("sucess 1 = "+success);
        success = ftpClient.makeDirectory("casa111");
        System.out.println("sucess 111 = "+success);
        success = ftpClient.makeDirectory("/usr/erp/token/casa");
        System.out.println("sucess 111 = "+success);
        success = ftpClient.makeDirectory("/casa2");
        System.out.println("sucess 1 = "+success);
        */
        success = ftpClient.storeFile(hostDirServer + "/token/" + fileNameServer, buffIn);
        //success = ftpClient.storeFile("prueba", buffIn);
        System.out.println("sucess 2 = " + success);
        //return (success)? 1:0;
    } catch (IOException ex) {

    } finally {
        try {
            if (ftpClient.isConnected()) {
                buffIn.close(); //Cerrar envio de arcivos al FTP
                ftpClient.logout();
                ftpClient.disconnect();
            }
        } catch (IOException ex) {
            return -1;
            //ex.printStackTrace();
        }
    }
    return (success) ? 1 : 0;
}

From source file:org.trustedanalytics.metadata.parser.ParserService.java

public Metadata parse(MetadataParseRequest request, String storeId, InputStream in) throws IOException {
    BufferedInputStream bin = new BufferedInputStream(in);

    Metadata metadata = new Metadata(request, storeId);

    metadata.setFormat(ContentDetectionUtils.bestGuessFileType(bin, metadata.getSourceUri()));

    if (isCsv(metadata)) {
        metadata = ContentParsingUtils.parseCsv(metadata, bin);
    } else {//from  www  . j a  v a  2 s .  com
        metadata = ContentParsingUtils.parseGenericFile(metadata, bin);
    }

    return metadata;
}

From source file:com.ibuildapp.romanblack.CataloguePlugin.imageloader.Utils.java

public static String downloadFile(Context context, String url, String md5) {
    final int BYTE_ARRAY_SIZE = 8024;
    final int CONNECTION_TIMEOUT = 30000;
    final int READ_TIMEOUT = 30000;

    try {/*ww  w. j  a  va  2 s. c om*/
        for (int i = 0; i < 3; i++) {
            URL fileUrl = new URL(URLDecoder.decode(url));
            HttpURLConnection connection = (HttpURLConnection) fileUrl.openConnection();
            connection.setConnectTimeout(CONNECTION_TIMEOUT);
            connection.setReadTimeout(READ_TIMEOUT);
            connection.connect();

            int status = connection.getResponseCode();

            if (status >= HttpStatus.SC_BAD_REQUEST) {
                connection.disconnect();

                continue;
            }

            BufferedInputStream bufferedInputStream = new BufferedInputStream(connection.getInputStream());
            File file = new File(StaticData.getCachePath(context) + md5);

            if (!file.exists()) {
                new File(StaticData.getCachePath(context)).mkdirs();
                file.createNewFile();
            }

            FileOutputStream fileOutputStream = new FileOutputStream(file, false);
            int byteCount;
            byte[] buffer = new byte[BYTE_ARRAY_SIZE];

            while ((byteCount = bufferedInputStream.read(buffer, 0, BYTE_ARRAY_SIZE)) != -1)
                fileOutputStream.write(buffer, 0, byteCount);

            bufferedInputStream.close();
            fileOutputStream.flush();
            fileOutputStream.close();

            return file.getAbsolutePath();
        }
    } catch (Exception e) {
        e.printStackTrace();

        return null;
    }

    return null;
}

From source file:it.geosolutions.tools.compress.file.reader.TarReader.java

/**
 * A method to read tar file://  w  ww .  j av  a2 s .  c  om
 * extract its content to the 'destDir' file (which could be
 * a directory or a file depending on the srcF file content)
 * @throws CompressorException 
 */
public static void readTar(File srcF, File destDir) throws Exception {
    if (destDir == null)
        throw new IllegalArgumentException("Unable to extract to a null destination dir");
    if (!destDir.canWrite() && !destDir.mkdirs())
        throw new IllegalArgumentException("Unable to extract to a not writeable destination dir: " + destDir);

    FileInputStream fis = null;
    TarArchiveInputStream tis = null;
    BufferedInputStream bis = null;
    try {
        fis = new FileInputStream(srcF);
        bis = new BufferedInputStream(fis);
        tis = new TarArchiveInputStream(bis);

        TarArchiveEntry te = null;
        while ((te = tis.getNextTarEntry()) != null) {

            File curr_dest = new File(destDir, te.getName());
            if (te.isDirectory()) {
                // create destination folder
                if (!curr_dest.exists())
                    curr_dest.mkdirs();
            } else {
                writeFile(curr_dest, tis);
            }
        }
    } finally {
        if (tis != null) {
            try {
                tis.close();
            } catch (IOException ioe) {
            }
        }
        if (bis != null) {
            try {
                bis.close();
            } catch (IOException ioe) {
            }
        }
        if (fis != null) {
            try {
                fis.close();
            } catch (IOException ioe) {
            }
        }

    }
}

From source file:com.googlecode.lineblog.websocket.TokenThread.java

public TokenThread(Socket socket) throws IOException {
    if (socket == null)
        throw new RuntimeException("socket is not null!");
    this.socket = socket;
    this.in = new BufferedInputStream(this.socket.getInputStream());
    this.out = new BufferedOutputStream(this.socket.getOutputStream());
    this.accept();//?
}