Ejemplo n.º 1
0
  public double saveBinaryFileNoBuffer() throws IOException {
    double time = System.nanoTime();
    File file =
        new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\binFileWithoutBuffer.bin");
    FileChannel fileChannel = null;
    MappedByteBuffer map = null;
    int counter = 0;
    try {
      //            fileOut = new FileOutputStream(file);
      //            outPut = new DataOutputStream(fileOut);
      fileChannel = new RandomAccessFile(file, "rw").getChannel();
      map = fileChannel.map(FileChannel.MapMode.READ_WRITE, 0, 4096 * 128 * 128);
      counter = edges.size();
      for (Edge e : edges) {
        map.putDouble(e.X1);
        map.putDouble(e.Y1);
        map.putDouble(e.X2);
        map.putDouble(e.Y2);
        map.putDouble(e.color.getRed());
        map.putDouble(e.color.getGreen());
        map.putDouble(e.color.getBlue());
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    edges.clear();
    map.position(0);
    // Now read every edge from the file and draw it.
    try {
      //            fileIn = new FileInputStream(file);
      //            inPut = new DataInputStream(fileIn);
      fileChannel = new RandomAccessFile(file, "r").getChannel();
      map = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, 4096 * 128 * 128);
      for (int i = 0; i <= counter; i++) {
        double X1 = map.getDouble();
        double Y1 = map.getDouble();
        double X2 = map.getDouble();
        double Y2 = map.getDouble();
        double red = map.getDouble();
        double green = map.getDouble();
        double blue = map.getDouble();

        Edge e = new Edge(X1, Y1, X2, Y2, new Color(red, green, blue, 1));
        drawEdge(e);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
    }

    return System.nanoTime() - time;
  }