Tabnine Logo
BufferedInputStream
Code IndexAdd Tabnine to your IDE (free)

How to use
BufferedInputStream
in
java.io

Best Java code snippets using java.io.BufferedInputStream (Showing top 20 results out of 43,965)

Refine searchRefine arrow

  • FileInputStream
  • InputStream
  • URL
  • BufferedOutputStream
  • URLConnection
  • FileOutputStream
  • OutputStream
origin: stackoverflow.com

ResultReceiver receiver = (ResultReceiver) intent.getParcelableExtra("receiver");
try {
  URL url = new URL(urlToDownload);
  URLConnection connection = url.openConnection();
  connection.connect();
  int fileLength = connection.getContentLength();
  InputStream input = new BufferedInputStream(connection.getInputStream());
  OutputStream output = new FileOutputStream("/sdcard/BarcodeScanner-debug.apk");
  while ((count = input.read(data)) != -1) {
    total += count;
    resultData.putInt("progress" ,(int) (total * 100 / fileLength));
    receiver.send(UPDATE_PROGRESS, resultData);
    output.write(data, 0, count);
  output.flush();
  output.close();
  input.close();
} catch (IOException e) {
  e.printStackTrace();
origin: facebook/facebook-android-sdk

public static int copyAndCloseInputStream(InputStream inputStream, OutputStream outputStream)
    throws IOException {
  BufferedInputStream bufferedInputStream = null;
  int totalBytes = 0;
  try {
    bufferedInputStream = new BufferedInputStream(inputStream);
    byte[] buffer = new byte[8192];
    int bytesRead;
    while ((bytesRead = bufferedInputStream.read(buffer)) != -1) {
      outputStream.write(buffer, 0, bytesRead);
      totalBytes += bytesRead;
    }
  } finally {
    if (bufferedInputStream != null) {
      bufferedInputStream.close();
    }
    if (inputStream != null) {
      inputStream.close();
    }
  }
  return totalBytes;
}
origin: stackoverflow.com

 BufferedInputStream bis = new BufferedInputStream(inputStream);
bis.mark(2);
int byte1 = bis.read();
int byte2 = bis.read();
bis.reset();
// note: you must continue using the BufferedInputStream instead of the inputStream
origin: stackoverflow.com

 BufferedInputStream bis = new BufferedInputStream(inputStream);
ByteArrayOutputStream buf = new ByteArrayOutputStream();
int result = bis.read();
while(result != -1) {
  buf.write((byte) result);
  result = bis.read();
}
return buf.toString();
origin: apache/storm

/**
 * Tries once to read ahead in the stream to fill the context and
 * resets the stream to its position before the call.
 */
private byte[] tryReadAhead(BufferedInputStream stream, ByteBuffer haystack, int offset, int fileLength, int bytesRead)
    throws IOException {
  int numExpected = Math.min(fileLength - bytesRead, GREP_CONTEXT_SIZE);
  byte[] afterBytes = new byte[numExpected];
  stream.mark(numExpected);
  // Only try reading once.
  stream.read(afterBytes, 0, numExpected);
  stream.reset();
  return afterBytes;
}
origin: apache/zookeeper

public void chop() {
  File targetFile = new File(txnLogFile.getParentFile(), txnLogFile.getName() + ".chopped" + zxid);
  try (
      InputStream is = new BufferedInputStream(new FileInputStream(txnLogFile));
      OutputStream os = new BufferedOutputStream(new FileOutputStream(targetFile))
  ) {
    if (!LogChopper.chop(is, os, zxid)) {
      throw new TxnLogToolkitException(ExitCode.INVALID_INVOCATION.getValue(), "Failed to chop %s", txnLogFile.getName());
    }
  } catch (Exception e) {
    System.out.println("Got exception: " + e.getMessage());
  }
}
origin: stackoverflow.com

 InputStream reader = new BufferedInputStream(
  object.getObjectContent());
File file = new File("localFilename");      
OutputStream writer = new BufferedOutputStream(new FileOutputStream(file));

int read = -1;

while ( ( read = reader.read() ) != -1 ) {
  writer.write(read);
}

writer.flush();
writer.close();
reader.close();
origin: Tencent/tinker

public static void bsdiff(File oldFile, File newFile, File diffFile) throws IOException {
  InputStream oldInputStream = new BufferedInputStream(new FileInputStream(oldFile));
  InputStream newInputStream = new BufferedInputStream(new FileInputStream(newFile));
  OutputStream diffOutputStream = new FileOutputStream(diffFile);
  try {
    byte[] diffBytes = bsdiff(oldInputStream, (int) oldFile.length(), newInputStream, (int) newFile.length());
    diffOutputStream.write(diffBytes);
  } finally {
    diffOutputStream.close();
  }
}
origin: libgdx/libgdx

public SetupPreferences () {		
  if (!file.exists()) return;
  InputStream in = null;
  try {
    in = new BufferedInputStream(new FileInputStream(file));
    properties.loadFromXML(in);
  } catch (Throwable t) {
    t.printStackTrace();
  } finally {
    if (in != null)
      try {
        in.close();
      } catch (IOException e) {
      }
  }
}
origin: apache/flink

jar = new JarFile(new File(jarFile.toURI()));
final List<JarEntry> containedJarFileEntries = new ArrayList<JarEntry>();
      try {
        out = new FileOutputStream(tempFile);
        in = new BufferedInputStream(jar.getInputStream(entry));
        while ((numRead = in.read(buffer)) != -1) {
          out.write(buffer, 0, numRead);
          out.close();
          in.close();
origin: stackoverflow.com

byte[] imageRaw = null;
try {
  URL url = new URL("http://some.domain.tld/somePicture.jpg");
  HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
  InputStream in = new BufferedInputStream(urlConnection.getInputStream());
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  int c;
  while ((c = in.read()) != -1) {
    out.write(c);
  }
  out.flush();
  imageRaw = out.toByteArray();
  urlConnection.disconnect();
  in.close();
  out.close();
} catch (IOException e) {
  // TODO Auto-generated catch block
  e.printStackTrace();
}
String image64 = Base64.encodeToString(imageRaw, Base64.DEFAULT);
String urlStr   = "http://example.com/my.jpg";
String mimeType = "text/html";
String encoding = null;
String pageData = "<img src=\"data:image/jpeg;base64," + image64 + "\" />";
WebView wv;
wv = (WebView) findViewById(R.id.webview);
wv.loadDataWithBaseURL(urlStr, pageData, mimeType, encoding, urlStr);
origin: ethereum/ethereumj

private String postQuery(String endPoint, String json) throws IOException {
  URL url = new URL(endPoint);
  HttpURLConnection conn = (HttpURLConnection) url.openConnection();
  conn.setConnectTimeout(5000);
  conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
  conn.setDoOutput(true);
  conn.setDoInput(true);
  conn.setRequestMethod("POST");
  OutputStream os = conn.getOutputStream();
  os.write(json.getBytes("UTF-8"));
  os.close();
  // read the response
  InputStream in = new BufferedInputStream(conn.getInputStream());
  String result = null;
  try (Scanner scanner = new Scanner(in, "UTF-8")) {
    result =  scanner.useDelimiter("\\A").next();
  }
  in.close();
  conn.disconnect();
  return result;
}
origin: stackoverflow.com

 URL url = new URL("http://www.yahoo.com/image_to_read.jpg");
InputStream in = new BufferedInputStream(url.openStream());
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int n = 0;
while (-1!=(n=in.read(buf)))
{
  out.write(buf, 0, n);
}
out.close();
in.close();
byte[] response = out.toByteArray();
origin: stackoverflow.com

 public static int countLines(String filename) throws IOException {
  InputStream is = new BufferedInputStream(new FileInputStream(filename));
  try {
    byte[] c = new byte[1024];
    int count = 0;
    int readChars = 0;
    boolean empty = true;
    while ((readChars = is.read(c)) != -1) {
      empty = false;
      for (int i = 0; i < readChars; ++i) {
        if (c[i] == '\n') {
          ++count;
        }
      }
    }
    return (count == 0 && !empty) ? 1 : count;
  } finally {
    is.close();
  }
}
origin: cSploit/android

private Bitmap getUserImage(String uri) {
  Bitmap image = null;
  try {
    URL url = new URL(uri);
    URLConnection conn = url.openConnection();
    conn.connect();
    InputStream input = conn.getInputStream();
    BufferedInputStream reader = new BufferedInputStream(input);
    image = Bitmap.createScaledBitmap(
        BitmapFactory.decodeStream(reader), 48, 48, false);
    reader.close();
    input.close();
  } catch (IOException e) {
    System.errorLogging(e);
  }
  return image;
}
origin: stackoverflow.com

URL url = new URL("http://www.android.com/");
 HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
 try {
  InputStream in = new BufferedInputStream(urlConnection.getInputStream());
  readStream(in);
 finally {
  urlConnection.disconnect();
 }
}
origin: loklak/loklak_server

public static void gunzip(File source, File dest, boolean deleteSource) throws IOException {
  byte[] buffer = new byte[2^20];
  FileOutputStream out = new FileOutputStream(dest);
  GZIPInputStream in = new GZIPInputStream(new BufferedInputStream(new FileInputStream(source)));
  int l; while ((l = in.read(buffer)) > 0) out.write(buffer, 0, l);
  in.close(); out.close();
  if (deleteSource && dest.exists()) source.delete();
}

origin: k9mail/k-9

private void copyAttachmentFromFile(String resourceName, int attachmentId, int expectedFilesize) throws IOException {
  File resourceFile = new File(getClass().getResource("/attach/" + resourceName).getFile());
  File attachmentFile = new File(attachmentDir, Integer.toString(attachmentId));
  BufferedInputStream input = new BufferedInputStream(new FileInputStream(resourceFile));
  BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(attachmentFile));
  int copied = IOUtils.copy(input, output);
  input.close();
  output.close();
  Assert.assertEquals(expectedFilesize, copied);
}
origin: spring-projects/spring-loaded

protected void copyFile(File from, File to) {
  try {
    FileInputStream fis = new FileInputStream(from);
    FileOutputStream fos = new FileOutputStream(to);
    BufferedInputStream bis = new BufferedInputStream(fis);
    BufferedOutputStream bos = new BufferedOutputStream(fos);
    byte[] buffer = new byte[4096];
    int len;
    while ((len = bis.read(buffer, 0, 4096)) != -1) {
      bos.write(buffer, 0, len);
    }
    bis.close();
    bos.close();
  }
  catch (IOException ioe) {
    throw new RuntimeException("Copy file failed", ioe);
  }
}
origin: redisson/redisson

final void process(Socket clnt) throws IOException {
  InputStream in = new BufferedInputStream(clnt.getInputStream());
  String cmd = readLine(in);
  logging(clnt.getInetAddress().getHostName(),
      new Date().toString(), cmd);
  while (skipLine(in) > 0){
  }
  OutputStream out = new BufferedOutputStream(clnt.getOutputStream());
  try {
    doReply(in, out, cmd);
  }
  catch (BadHttpRequest e) {
    replyError(out, e);
  }
  out.flush();
  in.close();
  out.close();
  clnt.close();
}
java.ioBufferedInputStream

Javadoc

A BufferedInputStream adds functionality to another input stream-namely, the ability to buffer the input and to support the mark and reset methods. When the BufferedInputStream is created, an internal buffer array is created. As bytes from the stream are read or skipped, the internal buffer is refilled as necessary from the contained input stream, many bytes at a time. The mark operation remembers a point in the input stream and the reset operation causes all the bytes read since the most recent mark operation to be reread before new bytes are taken from the contained input stream.

Most used methods

  • <init>
    Constructs a new BufferedInputStream, providing in with size bytes of buffer. Warning: passing a nul
  • read
    Reads bytes from this byte-input stream into the specified byte array, starting at the given offset.
  • close
    Closes this stream. The source stream is closed and any resources associated with it are released.
  • mark
    Sets a mark position in this stream. The parameter readlimitindicates how many bytes can be read bef
  • reset
    Resets this stream to the last marked location.
  • available
    Returns an estimated number of bytes that can be read or skipped without blocking for more input. Th
  • skip
    Skips byteCount bytes in this stream. Subsequent calls to read will not return these bytes unless re
  • markSupported
    Indicates whether BufferedInputStream supports the mark()and reset() methods.
  • fillbuf
  • streamClosed
  • fill
    Fills the buffer with more data, taking into account shuffling and other tricks for dealing with mar
  • getBufIfOpen
    Check to make sure that buffer has not been nulled out due to close; if not return it;
  • fill,
  • getBufIfOpen,
  • read1,
  • getInIfOpen

Popular in Java

  • Creating JSON documents from java classes using gson
  • getApplicationContext (Context)
  • scheduleAtFixedRate (Timer)
  • getSharedPreferences (Context)
  • Scanner (java.util)
    A parser that parses a text string of primitive types and strings with the help of regular expressio
  • BlockingQueue (java.util.concurrent)
    A java.util.Queue that additionally supports operations that wait for the queue to become non-empty
  • Annotation (javassist.bytecode.annotation)
    The annotation structure.An instance of this class is returned bygetAnnotations() in AnnotationsAttr
  • BoxLayout (javax.swing)
  • IsNull (org.hamcrest.core)
    Is the value null?
  • Join (org.hibernate.mapping)
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now