Пример #1
0
 /**
  * Read a single byte.
  *
  * @return The byte read, or -1 on end of file.
  * @throws IOException
  */
 public int read() throws IOException {
   // return read(nfd.getNativeFD());
   int result = FileSystem.readByte(nfd.getNativeFD());
   if (result < -1) {
     throw new IOException("Error code " + Integer.toString(result));
   }
   return result;
 }
Пример #2
0
 /**
  * Read a byte buffer, given a starting position and length. Looks at the type of buffer and
  * decides which is the fastest way to perform the write. If the buffer is backed by a byte array,
  * use the internal method, otherwise push it out to classpath's native function (the slow way).
  *
  * @param dst
  * @param pos
  * @param len
  * @return the number of bytes actually read
  * @throws IOException
  */
 private int read(ByteBuffer dst, int pos, int len) throws IOException {
   int bytes;
   if (len == 1) {
     int b = FileSystem.readByte(nfd.getNativeFD());
     if (b >= 0) {
       dst.put((byte) (b & 0xFF));
       dst.position(pos + 1);
       return 1;
     } else bytes = b;
   } else if (dst.hasArray()) {
     bytes = read(dst.array(), pos, len);
   } else {
     return read(nfd.getNativeFD(), dst);
   }
   if (bytes > 0) dst.position(pos + bytes);
   return bytes;
 }