Exemplo n.º 1
0
  public double loadBinaryFile() throws IOException {
    double time = System.nanoTime();
    File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\jsfweek14.bin");
    FileChannel fileChannel = null;
    MappedByteBuffer map = null;
    int counter = 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);
      double d = map.getDouble();
      currentLevel = (int) d;
      counter = (int) (3 * Math.pow(4, currentLevel - 1));
      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();
    } finally {
      fileChannel.close();
      map.clear();
    }

    return System.nanoTime() - time;
  }
Exemplo n.º 2
0
  public void watchForNewEdges() {
    // File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\jsfweek14.bin");

    // Get the file system
    // FileSystem fs = path.getFileSystem();

    // Create the watchservice
    try {
      Path path = Paths.get("C:/Users/rvanduijnhoven/Documents/jsfoutput/");
      WatchService service = FileSystems.getDefault().newWatchService();
      path.register(service, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY);
      WatchKey key;
      while (true) {
        key = service.take();
        for (WatchEvent<?> event : key.pollEvents()) {
          // Code here that does something when new edges have been generated
          System.out.println(event.context().toString());
          WatchEvent<Path> ev = (WatchEvent<Path>) event;
          WatchEvent.Kind kind = ev.kind();

          if (kind == OVERFLOW) {
            continue; // just to demonstrate
          }

          Path changed = ev.context();
          Path child = path.resolve(changed);
          if (changed.toString().equals("jsfweek14.bin")) {

            clearKochPanel();
            File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\jsfweek14.bin");
            FileChannel fileChannel = null;
            MappedByteBuffer map = null;
            int counter = 0;
            // Now read every edge from the file and draw it.
            try {
              fileChannel = new RandomAccessFile(file, "r").getChannel();
              map = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, 4096 * 128 * 128);
              double d = map.getDouble();
              currentLevel = (int) d;
              counter = (int) (3 * Math.pow(4, currentLevel - 1));
              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);
              }
              key.reset();

            } catch (Exception ex) {
              ex.printStackTrace();
            } finally {
              fileChannel.close();
              map.clear();
            }
          }
          key.reset();
        }
      }

    } catch (IOException ioe) {
      ioe.printStackTrace();
    } catch (Exception ie) {
      ie.printStackTrace();
    }
  }