Tabnine Logo
InputStream.read
Code IndexAdd Tabnine to your IDE (free)

How to use
read
method
in
java.io.InputStream

Best Java code snippets using java.io.InputStream.read (Showing top 20 results out of 81,666)

Refine searchRefine arrow

  • InputStream.close
  • OutputStream.write
  • OutputStream.close
  • FileOutputStream.<init>
  • ByteArrayOutputStream.write
  • ByteArrayOutputStream.<init>
  • ByteArrayOutputStream.toByteArray
  • File.<init>
origin: skylot/jadx

public static void copyStream(InputStream input, OutputStream output) throws IOException {
  byte[] buffer = new byte[READ_BUFFER_SIZE];
  while (true) {
    int count = input.read(buffer);
    if (count == -1) {
      break;
    }
    output.write(buffer, 0, count);
  }
}
origin: bumptech/glide

public static byte[] isToBytes(InputStream is) throws IOException {
 ByteArrayOutputStream os = new ByteArrayOutputStream();
 byte[] buffer = new byte[1024];
 int read;
 try {
  while ((read = is.read(buffer)) != -1) {
   os.write(buffer, 0, read);
  }
 } finally {
  is.close();
 }
 return os.toByteArray();
}
origin: stackoverflow.com

 public void copy(File src, File dst) throws IOException {
  InputStream in = new FileInputStream(src);
  OutputStream out = new FileOutputStream(dst);

  // Transfer bytes from in to out
  byte[] buf = new byte[1024];
  int len;
  while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
  }
  in.close();
  out.close();
}
origin: stackoverflow.com

File f = new File(getCacheDir()+"/m1.map");
if (!f.exists()) try {
 InputStream is = getAssets().open("m1.map");
 int size = is.available();
 byte[] buffer = new byte[size];
 is.read(buffer);
 is.close();
 FileOutputStream fos = new FileOutputStream(f);
 fos.write(buffer);
 fos.close();
} catch (Exception e) { throw new RuntimeException(e); }
mapView.setMapFile(f.getPath());
origin: spring-projects/spring-framework

@Test
public void nonClosingInputStream() throws Exception {
  InputStream source = mock(InputStream.class);
  InputStream nonClosing = StreamUtils.nonClosing(source);
  nonClosing.read();
  nonClosing.read(bytes);
  nonClosing.read(bytes, 1, 2);
  nonClosing.close();
  InOrder ordered = inOrder(source);
  ordered.verify(source).read();
  ordered.verify(source).read(bytes, 0, bytes.length);
  ordered.verify(source).read(bytes, 1, 2);
  ordered.verify(source, never()).close();
}
origin: commonsguy/cw-omnibus

 static void copy(InputStream in, File dst)
                           throws IOException {
  FileOutputStream out=new FileOutputStream(dst);
  byte[] buf=new byte[1024];
  int len;

  while ((len=in.read(buf)) >= 0) {
   out.write(buf, 0, len);
  }

  in.close();
  out.close();
 }
}
origin: robolectric/robolectric

private static File copyResourceToFile(String resourcePath) throws IOException {
 if (tempDir == null){
  File tempFile = File.createTempFile("prefix", "suffix");
  tempFile.deleteOnExit();
  tempDir = tempFile.getParentFile();
 }
 InputStream jarIn = SdkStore.class.getClassLoader().getResourceAsStream(resourcePath);
 File outFile = new File(tempDir, new File(resourcePath).getName());
 outFile.deleteOnExit();
 try (FileOutputStream jarOut = new FileOutputStream(outFile)) {
  byte[] buffer = new byte[4096];
  int len;
  while ((len = jarIn.read(buffer)) != -1) {
   jarOut.write(buffer, 0, len);
  }
 }
 return outFile;
}
origin: org.testng/testng

public static void copyFile(InputStream from, File to) throws IOException {
 if (! to.getParentFile().exists()) {
  to.getParentFile().mkdirs();
 }
 try (OutputStream os = new FileOutputStream(to)) {
  byte[] buffer = new byte[65536];
  int count = from.read(buffer);
  while (count > 0) {
   os.write(buffer, 0, count);
   count = from.read(buffer);
  }
 }
}
origin: robolectric/robolectric

public static void copy(InputStream in, OutputStream out) throws IOException {
 byte[] buffer = new byte[8196];
 int len;
 try {
  while ((len = in.read(buffer)) != -1) {
   out.write(buffer, 0, len);
  }
 } finally {
  in.close();
 }
}
origin: alibaba/arthas

public static String toString(InputStream inputStream) throws IOException {
  ByteArrayOutputStream result = new ByteArrayOutputStream();
  byte[] buffer = new byte[1024];
  int length;
  while ((length = inputStream.read(buffer)) != -1) {
    result.write(buffer, 0, length);
  }
  return result.toString("UTF-8");
}
origin: Tencent/tinker

public static void copyResourceUsingStream(String name, File dest) throws IOException {
  FileOutputStream os = null;
  File parent = dest.getParentFile();
  if (parent != null && (!parent.exists())) {
    parent.mkdirs();
  }
  InputStream is = null;
  try {
    is = FileOperation.class.getResourceAsStream("/" + name);
    os = new FileOutputStream(dest, false);
    byte[] buffer = new byte[TypedValue.BUFFER_SIZE];
    int length;
    while ((length = is.read(buffer)) > 0) {
      os.write(buffer, 0, length);
    }
  } finally {
    StreamUtil.closeQuietly(os);
    StreamUtil.closeQuietly(is);
  }
}
origin: jenkinsci/jenkins

  @Override
  public void run() {
    try {
      try {
        byte[] buf = new byte[8192];
        int len;
        while ((len = in.read(buf)) >= 0)
          out.write(buf, 0, len);
      } finally {
        // it doesn't make sense not to close InputStream that's already EOF-ed,
        // so there's no 'closeIn' flag.
        in.close();
        if(closeOut)
          out.close();
      }
    } catch (IOException e) {
      // TODO: what to do?
    }
  }
}
origin: libgdx/libgdx

private static byte[] readAllBytes(InputStream input) throws IOException {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  int numRead;
  byte[] buffer = new byte[16384];
  while ((numRead = input.read(buffer, 0, buffer.length)) != -1) {
    out.write(buffer, 0, numRead);
  }
  return out.toByteArray();
}
origin: stackoverflow.com

 InputStream is = entity.getContent();
String filePath = "sample.txt";
FileOutputStream fos = new FileOutputStream(new File(filePath));
int inByte;
while((inByte = is.read()) != -1)
   fos.write(inByte);
is.close();
fos.close();
origin: google/guava

@GwtIncompatible // Reader
private static void testStreamingDecodes(BaseEncoding encoding, String encoded, String decoded)
  throws IOException {
 byte[] bytes = decoded.getBytes(UTF_8);
 InputStream decodingStream = encoding.decodingStream(new StringReader(encoded));
 for (int i = 0; i < bytes.length; i++) {
  assertThat(decodingStream.read()).isEqualTo(bytes[i] & 0xFF);
 }
 assertThat(decodingStream.read()).isEqualTo(-1);
 decodingStream.close();
}
origin: commonsguy/cw-omnibus

 static void copy(InputStream in, File dst)
                           throws IOException {
  FileOutputStream out=new FileOutputStream(dst);
  byte[] buf=new byte[1024];
  int len;

  while ((len=in.read(buf)) >= 0) {
   out.write(buf, 0, len);
  }

  in.close();
  out.close();
 }
}
origin: alibaba/druid

public static long copy(InputStream input, OutputStream output) throws IOException {
  final int EOF = -1;
  byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
  long count = 0;
  int n = 0;
  while (EOF != (n = input.read(buffer))) {
    output.write(buffer, 0, n);
    count += n;
  }
  return count;
}
origin: iBotPeaches/Apktool

public void publicizeResources(File arscFile) throws AndrolibException {
  byte[] data = new byte[(int) arscFile.length()];
  try(InputStream in = new FileInputStream(arscFile);
    OutputStream out = new FileOutputStream(arscFile)) {
    in.read(data);
    publicizeResources(data);
    out.write(data);
  } catch (IOException ex){
    throw new AndrolibException(ex);
  }
}
origin: stanfordnlp/CoreNLP

 public void run() {
  try {
   byte[] b = new byte[bufferSize];
   int bytesRead;
   while ((bytesRead = inStream.read(b)) >= 0) {
    if (bytesRead > 0) {
     outStream.write(b, 0, bytesRead);
    }
   }
   inStream.close();
  } catch (Exception ex) {
   System.out.println("Problem reading stream :"+inStream.getClass().getCanonicalName()+ " "+ ex);
   ex.printStackTrace();
  }
 }
}
origin: jenkinsci/jenkins

  @Override
  public void run() {
    try {
      try {
        byte[] buf = new byte[8192];
        int len;
        while ((len = in.read(buf)) >= 0) {
          out.write(buf, 0, len);
          out.flush();
        }
      } finally {
        in.close();
        out.close();
      }
    } catch (IOException e) {
      // TODO: what to do?
    }
  }
}
java.ioInputStreamread

Javadoc

Reads a single byte from this stream and returns it as an integer in the range from 0 to 255. Returns -1 if the end of the stream has been reached. Blocks until one byte has been read, the end of the source stream is detected or an exception is thrown.

Popular methods of InputStream

  • close
    Closes this input stream and releases any system resources associated with the stream. The close met
  • available
    Returns the number of bytes that can be read (or skipped over) from this input stream without blocki
  • skip
    Skips over and discards n bytes of data from this input stream. The skip method may, for a variety o
  • reset
    Repositions this stream to the position at the time themark method was last called on this input str
  • mark
    Marks the current position in this input stream. A subsequent call to the reset method repositions
  • markSupported
    Tests if this input stream supports the mark andreset methods. Whether or not mark andreset are sup
  • transferTo
  • <init>
    This constructor does nothing. It is provided for signature compatibility.
  • readAllBytes
  • readNBytes

Popular in Java

  • Making http requests using okhttp
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getApplicationContext (Context)
  • compareTo (BigDecimal)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • JarFile (java.util.jar)
    JarFile is used to read jar entries and their associated data from jar files.
  • JLabel (javax.swing)
  • Top plugins for WebStorm
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