code: public static void readRAMFiles(DataInput in, RAMDirectory dir)
        throws IOException {
      int numFiles = in.readInt();
  
      for (int i = 0; i < numFiles; i++) {
        String name = Text.readString(in);
        long length = in.readLong();
  
        if (length > 0) {
          // can we avoid the extra copy?
          IndexOutput output = null;
          try {
            output = dir.createOutput(name);
  
            int position = 0;
            byte[] buffer = new byte[BUFFER_SIZE];
  
            while (position < length) {
              int len =
                  position + BUFFER_SIZE <= length ? BUFFER_SIZE
                      : (int) (length - position);
              in.readFully(buffer, 0, len);
              output.writeBytes(buffer, 0, len);
              position += len;
            }
          } finally {
            if (output != null) {
              output.close();
            }
          }
        }
      }
    }
docs: Read a number of files from a data input to a ram directory.
  @param in  the data input
  @param dir  the ram directory
  @throws IOException