code: protected long copyFrom(final InputStream is, final long recordLength,
              boolean enforceLength) throws IOException {
          int read = scratchbuffer.length;
          long tot = 0;
          while ((tot < recordLength)
                  && (read = is.read(scratchbuffer)) != -1) {
              int write = read; 
              // never write more than enforced length
              write = (int) Math.min(write, recordLength - tot);
              tot += read;
              write(scratchbuffer, 0, write);
          }
          if (enforceLength && tot != recordLength) {
              // throw exception if desired for read vs. declared mismatches
              throw new IOException("Read " + tot + " but expected "
                      + recordLength);
          }
          
          return tot;
      }
docs: Copy bytes from the provided InputStream to the target file/stream being
  written.
  
  @return number of bytes written (normally equal to {@code enforceLength})
  @param is
  InputStream to copy bytes from
  @param recordLength
  expected number of bytes to copy
  @param enforceLength
  whether to throw an exception if too many/too few bytes are
  available from stream
  @throws IOException