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

How to use
skip
method
in
java.io.InputStream

Best Java code snippets using java.io.InputStream.skip (Showing top 20 results out of 11,421)

Refine searchRefine arrow

  • InputStream.read
  • InputStream.available
  • InputStream.close
origin: google/guava

/**
 * Attempts to skip up to {@code n} bytes from the given input stream, but not more than {@code
 * in.available()} bytes. This prevents {@code FileInputStream} from skipping more bytes than
 * actually remain in the file, something that it {@linkplain java.io.FileInputStream#skip(long)
 * specifies} it can do in its Javadoc despite the fact that it is violating the contract of
 * {@code InputStream.skip()}.
 */
private static long skipSafely(InputStream in, long n) throws IOException {
 int available = in.available();
 return available == 0 ? 0 : in.skip(Math.min(available, n));
}
origin: Tencent/tinker

public static void skipAll(InputStream in) throws IOException {
  do {
    in.skip(Long.MAX_VALUE);
  } while (in.read() != -1);
}
/**
origin: wildfly/wildfly

public static int keyPress(String msg) {
  System.out.println(msg);
  try {
    int ret=System.in.read();
    System.in.skip(System.in.available());
    return ret;
  }
  catch(IOException e) {
    return -1;
  }
}
origin: naman14/Timber

private static int readOgg(byte[] buf, InputStream in, int bytesinpage, int skip) throws IOException {
  int toread = skip!=-1?skip:buf.length;
  int offset = 0;
  while(toread>0){
    if(bytesinpage==0){
      byte magic[] = new byte[4];
      in.read(magic);
      if(!Arrays.equals(magic,new byte[]{'O','g','g','S'})){
        in.close();
        throw new IOException();
      }
      byte header[] = new byte[23];
      in.read(header);
      int count = header[22]& 0xFF;
      while(count-->0){
        bytesinpage += in.read();
      }
    }
    int read = toread;
    if(bytesinpage-toread<0)read = bytesinpage;
    if(skip != -1)
      in.skip(read);
    else
      in.read(buf, offset, read);
    offset += read;
    toread -= read;
    bytesinpage -= read;
  }
  return bytesinpage;
}
origin: apache/avro

 /**
  * Skips any unread bytes from InputStream and closes it.
  */
 static void skipAndCloseQuietly(InputStream stream) {
  try {
   if (stream instanceof KnownLength && stream.available() > 0) {
    stream.skip(stream.available());
   } else {
    //don't expect this for an inputStream provided by gRPC but just to be on safe side.
    byte[] skipBuffer = new byte[4096];
    while (true) {
     int read = stream.read(skipBuffer);
     if (read < skipBuffer.length) {
      break;
     }
    }
   }
   stream.close();
  } catch (Exception e) {
   log.log(Level.WARNING, "failed to skip/close the input stream, may cause memory leak", e);
  }
 }
}
origin: jMonkeyEngine/jmonkeyengine

  public void setTime(float time) {
    if (time != 0f) {
      throw new UnsupportedOperationException("Seeking WAV files not supported");
    }
    InputStream newStream = info.openStream();
    try {
      newStream.skip(resetOffset);
      this.in = new BufferedInputStream(newStream);
    } catch (IOException ex) {
      // Resource could have gotten lost, etc.
      try {
        newStream.close();
      } catch (IOException ex2) {
      }
      throw new RuntimeException(ex);
    }
  }
}
origin: jfinal/jfinal

long end = range[1];
inputStream = new BufferedInputStream(new FileInputStream(file));
if (inputStream.skip(start) != start)
    throw new RuntimeException("File skip error");
outputStream = response.getOutputStream();
byte[] buffer = new byte[1024];
long position = start;
for (int len; position <= end && (len = inputStream.read(buffer)) != -1;) {
  if (position + len <= end) {
    outputStream.write(buffer, 0, len);
  try {inputStream.close();} catch (IOException e) {LogKit.error(e.getMessage(), e);}
origin: bumptech/glide

@Override
public long skip(long total) throws IOException {
 if (total < 0) {
  return 0;
 }
 long toSkip = total;
 while (toSkip > 0) {
  long skipped = is.skip(toSkip);
  if (skipped > 0) {
   toSkip -= skipped;
  } else {
   // Skip has no specific contract as to what happens when you reach the end of
   // the stream. To differentiate between temporarily not having more data and
   // having finished the stream, we read a single byte when we fail to skip any
   // amount of data.
   int testEofByte = is.read();
   if (testEofByte == -1) {
    break;
   } else {
    toSkip--;
   }
  }
 }
 return total - toSkip;
}
origin: hierynomus/sshj

  private void checkAndFlushProxyResponse()throws IOException {
    InputStream socketInput = getInputStream();
    byte[] tmpBuffer = new byte[512];
    int len = socketInput.read(tmpBuffer, 0, tmpBuffer.length);

    if (len == 0) {
      throw new SocketException("Empty response from proxy");
    }

    String proxyResponse = new String(tmpBuffer, 0, len, IOUtils.UTF8);

    // Expecting HTTP/1.x 200 OK
    if (proxyResponse.contains("200")) {
      // Flush any outstanding message in buffer
      if (socketInput.available() > 0) {
        socketInput.skip(socketInput.available());
      }
      // Proxy Connect Successful
    } else {
      throw new SocketException("Fail to create Socket\nResponse was:" + proxyResponse);
    }
  }
}
origin: apache/avro

private void validateInputStreamReads(InputStream test, InputStream check)
  throws IOException {
 byte[] bt = new byte[7];
 byte[] bc = new byte[7];
 while (true) {
  int t = test.read();
  int c = check.read();
  Assert.assertEquals(c, t);
  if (-1 == t) break;
  t = test.read(bt);
  c = check.read(bc);
  Assert.assertEquals(c, t);
  Assert.assertArrayEquals(bt, bc);
  if (-1 == t) break;
  t = test.read(bt, 1, 4);
  c = check.read(bc, 1, 4);
  Assert.assertEquals(c, t);
  Assert.assertArrayEquals(bt, bc);
  if (-1 == t) break;
 }
 Assert.assertEquals(0, test.skip(5));
 Assert.assertEquals(0, test.available());
 Assert.assertFalse(test.getClass() != ByteArrayInputStream.class && test.markSupported());
 test.close();
}
origin: Tencent/tinker

in.skip(BSUtil.HEADER_SIZE);
DataInputStream ctrlBlockIn = new DataInputStream(new GZIPInputStream(in));
in.skip(ctrlBlockLen + BSUtil.HEADER_SIZE);
InputStream diffBlockIn = new GZIPInputStream(in);
in.skip(diffBlockLen + ctrlBlockLen + BSUtil.HEADER_SIZE);
InputStream extraBlockIn = new GZIPInputStream(in);
diffBlockIn.close();
extraBlockIn.close();
origin: apache/incubator-dubbo

  public static void skipUnusedStream(InputStream is) throws IOException {
    if (is.available() > 0) {
      is.skip(is.available());
    }
  }
}
origin: cmusphinx/sphinx4

try {
  InputStream dataStream = new FileInputStream(file);
  dataStream.skip(startOffset * bytesPerFrame);
  if (dataStream.read(data) != data.length) {
    dataStream.close();
    throw new CTLException("Unable to read " + data.length + " bytes of utterance " + name);
  dataStream.close();
origin: robovm/robovm

public static void skipAll(InputStream in) throws IOException {
  do {
    in.skip(Long.MAX_VALUE);
  } while (in.read() != -1);
}
origin: sannies/mp4parser

private void find(InputStream fis) throws IOException {
  while (fis.available() > 0) {
    byte[] header = new byte[8];
    fis.read(header);
      if (type.equals("tkhd")) {
        lastTkhd = new byte[(int) (size - 8)];
        fis.read(lastTkhd);
      } else {
        if (type.equals("hdlr")) {
          byte[] hdlr = new byte[(int) (size - 8)];
          fis.read(hdlr);
          if (hdlr[8] == 0x76 && hdlr[9] == 0x69 && hdlr[10] == 0x64 && hdlr[11] == 0x65) {
            System.out.println("Video Track Header identified");
          fis.skip(size - 8);
origin: apache/mina

@Test
public void testSkip() throws IOException {
  byte[] src = "HELLO MINA!".getBytes();
  ByteBuffer bb = ByteBuffer.wrap(src);
  InputStream is = new ByteBufferInputStream(bb);
  is.skip(6);
  assertEquals(5, is.available());
  assertEquals('M', is.read());
  assertEquals('I', is.read());
  assertEquals('N', is.read());
  assertEquals('A', is.read());
  is.skip((long) Integer.MAX_VALUE + 1);
  assertEquals(-1, is.read());
  is.close();
}
origin: Tencent/tinker

in.skip(BSUtil.HEADER_SIZE);
DataInputStream ctrlBlockIn = new DataInputStream(new GZIPInputStream(in));
in.skip(ctrlBlockLen + BSUtil.HEADER_SIZE);
InputStream diffBlockIn = new GZIPInputStream(in);
in.skip(diffBlockLen + ctrlBlockLen + BSUtil.HEADER_SIZE);
InputStream extraBlockIn = new GZIPInputStream(in);
  diffBlockIn.close();
  extraBlockIn.close();
} finally {
  oldFile.close();
origin: apache/incubator-dubbo

  public static void skipUnusedStream(InputStream is) throws IOException {
    if (is.available() > 0) {
      is.skip(is.available());
    }
  }
}
origin: commons-io/commons-io

@Test
public void testSkipWithoutBOM() throws Exception {
  final byte[] data = new byte[] { 'A', 'B', 'C', 'D' };
  final InputStream in = new BOMInputStream(createUtf8DataStream(data, false));
  in.skip(2L);
  assertEquals('C', in.read());
  in.close();
}
origin: Yalantis/uCrop

@Override
public long skip(long total) throws IOException {
  if (total < 0) {
    return 0;
  }
  long toSkip = total;
  while (toSkip > 0) {
    long skipped = is.skip(toSkip);
    if (skipped > 0) {
      toSkip -= skipped;
    } else {
      // Skip has no specific contract as to what happens when you reach the end of
      // the stream. To differentiate between temporarily not having more data and
      // having finished the stream, we read a single byte when we fail to skip any
      // amount of data.
      int testEofByte = is.read();
      if (testEofByte == -1) {
        break;
      } else {
        toSkip--;
      }
    }
  }
  return total - toSkip;
}
java.ioInputStreamskip

Javadoc

Skips at most n bytes in this stream. This method does nothing and returns 0 if n is negative, but some subclasses may throw.

Note the "at most" in the description of this method: this method may choose to skip fewer bytes than requested. Callers should always check the return value.

This default implementation reads bytes into a temporary buffer. Concrete subclasses should provide their own implementation.

Popular methods of InputStream

  • close
    Closes this input stream and releases any system resources associated with the stream. The close met
  • read
    Reads up to len bytes of data from the input stream into an array of bytes. An attempt is made to re
  • available
    Returns the number of bytes that can be read (or skipped over) from this input stream without blocki
  • 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

  • Reading from database using SQL prepared statement
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getApplicationContext (Context)
  • compareTo (BigDecimal)
  • SecureRandom (java.security)
    This class generates cryptographically secure pseudo-random numbers. It is best to invoke SecureRand
  • Calendar (java.util)
    Calendar is an abstract base class for converting between a Date object and a set of integer fields
  • Hashtable (java.util)
    A plug-in replacement for JDK1.5 java.util.Hashtable. This version is based on org.cliffc.high_scale
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • Notification (javax.management)
  • Get (org.apache.hadoop.hbase.client)
    Used to perform Get operations on a single row. To get everything for a row, instantiate a Get objec
  • Best plugins for Eclipse
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