Code example for BufferedInputStream

Methods: close, read

0
 
                HttpResponse response = client.execute(request);
                HttpEntity entity = response.getEntity();
                File outputFile = mTempFile != null ? mTempFile : mDestination;
 
                in = new BufferedInputStream(entity.getContent());
                out = new BufferedOutputStream(new FileOutputStream(outputFile));
 
                byte[] buffer = new byte[2048];
                int count, total = 0;
                long length = entity.getContentLength();
 
                while ((count = in.read(buffer, 0, buffer.length)) != -1) {
                    if (isCancelled()) {
                        result = RESULT_CANCELLED;
                        break; 
                    } 
                    out.write(buffer, 0, count);
                    total += count;
 
                    if (length > 0) {
                        float progress = (float) total * 100 / length;
                        publishProgress((int) progress);
                    } 
                } 
 
                Log.d(TAG, "Downloaded " + total + "/" + length + " bytes of LTO data");
                if (total == 0 || (length > 0 && total != length)) {
                    result = RESULT_FAILURE;
                } 
                in.close();
                out.close();
            } catch (IOException e) {
                Log.e(TAG, "Failed downloading LTO data", e);
                result = RESULT_FAILURE;
            } catch (URISyntaxException e) {
                Log.e(TAG, "URI syntax wrong", e);
                result = RESULT_FAILURE;
            } finally { 
                try { 
                    if (in != null) {
                        in.close();
                    } 
                    if (out != null) {
                        out.close();
                    } 
                } catch (IOException e) {