private static double[] loadRawDouble(String source) throws Exception {
   System.out.println("Loading data...");
   long time = System.nanoTime();
   RandomAccessFile raf = new RandomAccessFile(source, "r");
   FileChannel inChannel = raf.getChannel();
   MappedByteBuffer buffer = inChannel.map(FileChannel.MapMode.READ_ONLY, 0, inChannel.size());
   DoubleBuffer dbuf = buffer.asDoubleBuffer();
   double[] dest = new double[dbuf.remaining()];
   dbuf.get(dest);
   long elapsed = System.nanoTime() - time;
   System.out.println("Load complete... " + (elapsed / 1000000) + "ms");
   raf.close();
   return dest;
 }
Ejemplo n.º 2
0
 public void readFile(File file) {
   try {
     FileChannel channel = new FileInputStream(file).getChannel();
     MappedByteBuffer bb = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
     IntBuffer ib = bb.asIntBuffer();
     _nx = ib.get();
     _ny = ib.get();
     _nz = ib.get();
     bb.position(4 * ib.position());
     DoubleBuffer db = bb.asDoubleBuffer();
     if (_a == null || _a.length != _nx * _ny * _nz) _a = new double[_nx * _ny * _nz];
     db.get(_a);
     channel.close();
   } catch (IOException e) {
     System.out.println(e.getMessage());
   }
 }