@Test public void testSkipFully() throws IOException { byte inArray[] = new byte[] {0, 1, 2, 3, 4}; ByteArrayInputStream in = new ByteArrayInputStream(inArray); try { in.mark(inArray.length); IOUtils.skipFully(in, 2); IOUtils.skipFully(in, 2); try { IOUtils.skipFully(in, 2); fail("expected to get a PrematureEOFException"); } catch (EOFException e) { assertEquals("Premature EOF from inputStream " + "after skipping 1 byte(s).",e.getMessage()); } in.reset(); try { IOUtils.skipFully(in, 20); fail("expected to get a PrematureEOFException"); } catch (EOFException e) { assertEquals("Premature EOF from inputStream " + "after skipping 5 byte(s).",e.getMessage()); } in.reset(); IOUtils.skipFully(in, 5); try { IOUtils.skipFully(in, 10); fail("expected to get a PrematureEOFException"); } catch (EOFException e) { assertEquals("Premature EOF from inputStream " + "after skipping 0 byte(s).",e.getMessage()); } } finally { in.close(); } }
public static void skipFully(InputStream in, long len) throws IOException { long amt = len; while (amt > 0) { long ret = in.skip(amt); if (ret == 0) { int b = in.read(); if (b == -1) { throw new EOFException( "Premature EOF from inputStream after " + "skipping " + (len - amt) + " byte(s)."); } ret = 1; } amt -= ret; } }
IOUtils { public static void skipFully(InputStream in, long len) throws IOException { long amt = len; while (amt > 0) { long ret = in.skip(amt); if (ret == 0) { int b = in.read(); if (b == -1) { throw new EOFException( "Premature EOF from inputStream after " + "skipping " + (len - amt) + " byte(s)."); } ret = 1; } amt -= ret; } } }
IOUtils { public static void skipFully(InputStream in, long len) throws IOException { long amt = len; while (amt > 0) { long ret = in.skip(amt); if (ret == 0) { int b = in.read(); if (b == -1) { throw new EOFException( "Premature EOF from inputStream after " + "skipping " + (len - amt) + " byte(s)."); } ret = 1; } amt -= ret; } }  }
IOUtils { public static void skipFully(InputStream in, long len) throws IOException { long amt = len; while (amt > 0) { long ret = in.skip(amt); if (ret == 0) { int b = in.read(); if (b == -1) { throw new EOFException( "Premature EOF from inputStream after " + "skipping " + (len - amt) + " byte(s)."); } ret = 1; } amt -= ret; } }  static void copyBytes(InputStream in, OutputStream out, int buffSize, boolean close); static void copyBytes(InputStream in, OutputStream out, int buffSize); static void copyBytes(InputStream in, OutputStream out, Configuration conf); static void copyBytes(InputStream in, OutputStream out, Configuration conf, boolean close); static void copyBytes(InputStream in, OutputStream out, long count,
      boolean close); static int wrappedReadForCompressedData(InputStream is, byte[] buf,
      int off, int len); static void readFully(InputStream in, byte buf[],
      int off, int len); static void skipFully(InputStream in, long len); static void cleanup(Log log, java.io.Closeable... closeables); static void closeStream(java.io.Closeable stream); static void closeSocket(Socket sock); static void writeFully(WritableByteChannel bc, ByteBuffer buf); static void writeFully(FileChannel fc, ByteBuffer buf,
      long offset); }
IOUtils { public static void skipFully(InputStream in, long len) throws IOException { long amt = len; while (amt > 0) { long ret = in.skip(amt); if (ret == 0) { int b = in.read(); if (b == -1) { throw new EOFException( "Premature EOF from inputStream after " + "skipping " + (len - amt) + " byte(s)."); } ret = 1; } amt -= ret; } }  static void copyBytes(InputStream in, OutputStream out, int buffSize, boolean close); static void copyBytes(InputStream in, OutputStream out, int buffSize); static void copyBytes(InputStream in, OutputStream out, Configuration conf); static void copyBytes(InputStream in, OutputStream out, Configuration conf, boolean close); static void copyBytes(InputStream in, OutputStream out, long count,
      boolean close); static int wrappedReadForCompressedData(InputStream is, byte[] buf,
      int off, int len); static void readFully(InputStream in, byte buf[],
      int off, int len); static void skipFully(InputStream in, long len); static void cleanup(Log log, java.io.Closeable... closeables); static void closeStream(java.io.Closeable stream); static void closeSocket(Socket sock); static void writeFully(WritableByteChannel bc, ByteBuffer buf); static void writeFully(FileChannel fc, ByteBuffer buf,
      long offset);  }