1 21 22 package org.apache.derby.iapi.services.io; 23 24 import java.io.*; 25 26 31 public final class InputStreamUtil { 32 33 43 public static int readUnsignedByte(InputStream in) throws IOException { 44 int b = in.read(); 45 if (b < 0) 46 throw new EOFException(); 47 48 return b; 49 } 50 51 60 public static void readFully(InputStream in, byte b[], 61 int offset, 62 int len) throws IOException 63 { 64 do { 65 int bytesRead = in.read(b, offset, len); 66 if (bytesRead < 0) 67 throw new EOFException(); 68 len -= bytesRead; 69 offset += bytesRead; 70 } while (len != 0); 71 } 72 73 74 83 public static int readLoop(InputStream in, 84 byte b[], 85 int offset, 86 int len) 87 throws IOException 88 { 89 int firstOffset = offset; 90 do { 91 int bytesRead = in.read(b, offset, len); 92 if (bytesRead <= 0) 93 break; 94 len -= bytesRead; 95 offset += bytesRead; 96 } while (len != 0); 97 return offset - firstOffset; 98 } 99 100 101 110 public static long skipBytes(InputStream in, long n) throws IOException { 111 112 while (n > 0) { 113 long delta = in.skip(n); 115 if (delta < 0) 117 throw new EOFException(); 118 n -= delta; 119 } 120 121 return n; 122 } 123 } 124 | Popular Tags |