Esempio n. 1
1
  public double saveBinaryFileWithBuffer() {
    double time = System.nanoTime();
    File file = new File("C:\\Users\\rvanduijnhoven\\Documents\\jsfoutput\\binFileWithBuffer.bin");
    DataOutputStream outPut = null;
    DataInputStream inPut = null;
    FileOutputStream fileOut = null;
    FileInputStream fileIn = null;
    BufferedInputStream buffInput = null;
    BufferedOutputStream buffOut = null;
    try {
      fileOut = new FileOutputStream(file);
      buffOut = new BufferedOutputStream(fileOut);
      outPut = new DataOutputStream(buffOut);
      for (Edge e : edges) {
        outPut.writeDouble(e.X1);
        outPut.writeDouble(e.Y1);
        outPut.writeDouble(e.X2);
        outPut.writeDouble(e.Y2);
        outPut.writeDouble(e.color.getRed());
        outPut.writeDouble(e.color.getGreen());
        outPut.writeDouble(e.color.getBlue());
        outPut.flush();
      }
      outPut.close();
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    edges.clear();
    // Now read every edge from the file and draw it.
    try {
      fileIn = new FileInputStream(file);
      buffInput = new BufferedInputStream(fileIn);
      inPut = new DataInputStream(buffInput);

      if (inPut.available() > 0) {
        while (inPut.available() > 0) {
          double X1 = inPut.readDouble();
          double Y1 = inPut.readDouble();
          double X2 = inPut.readDouble();
          double Y2 = inPut.readDouble();
          double red = inPut.readDouble();
          double green = inPut.readDouble();
          double blue = inPut.readDouble();

          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;
  }
Esempio n. 2
0
  public void parse() {
    usecpluginAAAstore.setdataBroker(dataBroker);
    try {
      getTheNewestFile();
      ParsingLog parsinglog = new ParsingLog();
      parsinglog.start();

    } catch (Exception ioe) {
      ioe.printStackTrace();
    }
  }
Esempio n. 3
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;
  }
Esempio n. 4
0
  public void callData() {
    workingDir = System.getProperty("user.dir");
    String fileName =
        workingDir
            + File.separator
            + "data"
            + File.separator
            + "log"
            + File.separator
            + "karaf.log";
    WatchedDir = workingDir + File.separator + "data" + File.separator + "log";
    try {

      LOG.info("log enabled ...");
      Thread.sleep(10000);
      infile = new File(theNewestFile.toString());
      LOG.info("karaf file ..." + theNewestFile);
      Thread.sleep(1000);
      LOG.info("parsing karaf file ...");
      Thread.sleep(9000);
      Scanner scanner = new Scanner(infile);

      while (scanner.hasNext()) {
        line = scanner.nextLine();
        if (line.contains("DEBUG") && line.contains("from")) {

          String phrase1 = line;
          String delims = "[,]+";
          String[] tokens = phrase1.split(delims);
          String phrase2 = line;
          String delims2 = "[|]+";
          String[] tokens2 = phrase2.split(delims2);
          time = tokens[0];
          attempt = tokens2[5];
          String phrase3 = line;
          String[] parts = phrase3.split(" ");
          srcIP = parts[parts.length - 1];
          usecpluginAAAstore.addData(time, srcIP, attempt);
          LOG.info("Information stored in datastore is" + time + " " + srcIP + " " + attempt);
        }
      }
      PublishNotif publishNotif = new PublishNotif();
      publishNotif.setdataBroker(dataBroker);
      publishNotif.Notify();

    } catch (Exception e) {

      e.printStackTrace();
    }
  }
Esempio n. 5
0
  public File getTheNewestFile() {

    workingDir = System.getProperty("user.dir");
    String fileName =
        workingDir
            + File.separator
            + "data"
            + File.separator
            + "log"
            + File.separator
            + "karaf.log";
    WatchedDir = workingDir + File.separator + "data" + File.separator + "log";

    try {
      LOG.info("log enabled ...");
      File dir = new File(WatchedDir);
      Thread.sleep(10000);
      files = dir.listFiles();
      Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_COMPARATOR);
      for (int i = 0; i < files.length; i++) {
        file = files[i];
        karafFiles += file.getName();
      }
      LOG.info("karaf files:" + karafFiles);
      Arrays.sort(files, LastModifiedFileComparator.LASTMODIFIED_REVERSE);
      for (int i = 0; i < files.length; i++) {
        file = files[i];
        RevOrder_ofFiles += file.getName();
      }
      LOG.info("list of karaf File in reverse order" + " " + RevOrder_ofFiles);
      theNewestFile = files[0];
      LOG.info("Latest karaf File" + theNewestFile);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return theNewestFile;
  }
Esempio n. 6
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;
  }
Esempio n. 7
0
 /**
  * Updates FSML database instance to reflect file modification.
  *
  * @param path regular file that was changed
  * @param isDir whether path is a directory
  */
 private void modifyEvent(final Path path, final boolean isDir) {
   if (isDir) {
     System.err.println(NAME + " No directory handling so far.");
     return;
   }
   try {
     // XPath expression to select affected file node.
     String xp = FSML.pn2xp(path.toAbsolutePath().toString(), false);
     // FSML fragment read from changed file
     ArrayOutput ao = new ArrayOutput();
     FSML.out = new PrintWriter(ao, true);
     fsml.visitFile(path, null); // print new file entry in ao
     String fsentry = ao.toString();
     // Update query
     StringBuilder sb = new StringBuilder();
     sb.append("xquery replace node " + xp + " with " + fsentry);
     String query = sb.toString();
     System.err.println(NAME + " Query: " + query);
     //            System.err.println(session.execute(query));
     //            System.err.println(session.info());
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Esempio n. 8
0
  @Override
  public void start(Stage primaryStage) {
    // Create four buttons, for each of the read/writing ways.
    Button btnTextNoBuffer = new Button();
    btnTextNoBuffer.setText("Save and load to text file, no buffer.");
    Button btnTextWithBuffer = new Button();
    btnTextWithBuffer.setText("Save and load to text file, with buffer.");
    Button btnBinaryNoBuffer = new Button();
    btnBinaryNoBuffer.setText("Save and load to Mapped file.");
    Button btnBinaryWithBuffer = new Button();
    btnBinaryWithBuffer.setText("Save and load to binary file, with buffer.");

    // Textfield to enter the number of edges + label
    TextField nrOfEdges = new TextField();
    Label lbl = new Label();
    lbl.setText("Enter your desired level.");

    // Label to present the read/write time.
    Label speed = new Label();
    speed.setText("The write speed will be shown here.");
    // New canvas
    kochPanel = new Canvas(kpWidth, kpHeight);
    kochPanel.setTranslateX(100);

    // position the elements
    btnTextNoBuffer.setTranslateY(-80);
    btnTextWithBuffer.setTranslateY(-40);
    btnBinaryWithBuffer.setTranslateY(40);
    btnTextNoBuffer.setTranslateX(-240);
    btnTextWithBuffer.setTranslateX(-240);
    btnBinaryNoBuffer.setTranslateX(-240);
    btnBinaryWithBuffer.setTranslateX(-240);
    nrOfEdges.setTranslateY(-220);
    nrOfEdges.setTranslateX(-310);
    nrOfEdges.setMaxWidth(50);
    lbl.setTranslateX(-240);
    lbl.setTranslateY(-200);
    speed.setTranslateY(-240);

    StackPane root = new StackPane();
    // root.getChildren().add(btnTextNoBuffer);
    // root.getChildren().add(btnTextWithBuffer);
    root.getChildren().add(btnBinaryNoBuffer);
    // root.getChildren().add(btnBinaryWithBuffer);
    // root.getChildren().add(nrOfEdges);
    // root.getChildren().add(lbl);
    root.getChildren().add(kochPanel);
    root.getChildren().add(speed);

    Scene scene = new Scene(root, 700, 500);

    primaryStage.setTitle("Edges and stuff");
    primaryStage.setScene(scene);
    primaryStage.show();

    // Event handlers for buttons
    //        btnTextNoBuffer.setOnMouseClicked(event -> {
    //            int i = Integer.parseInt(nrOfEdges.getText());
    //            currentLevel = i;
    //            clearKochPanel();
    //            createKochFractal(i);
    //            double x = 0;
    //            try {
    //                x = saveTextFileNoBuffer();
    //            } catch (IOException e) {
    //                e.printStackTrace();
    //            }
    //            speed.setText(String.valueOf((x / 1000000)));
    //            //drawAllEdges();
    //        });

    //        btnTextWithBuffer.setOnMouseClicked(event -> {
    //            int i = Integer.parseInt(nrOfEdges.getText());
    //            currentLevel = i;
    //            clearKochPanel();
    //            createKochFractal(i);
    //            double x = 0;
    //            try {
    //                x = saveTextFileWithBuffer();
    //            }
    //            catch (Exception ex)
    //            {
    //                ex.printStackTrace();
    //            }
    //            speed.setText(String.valueOf(x / 1000000));
    //            //drawAllEdges();
    //        });

    btnBinaryNoBuffer.setOnMouseClicked(
        event -> {
          // int i = Integer.parseInt(nrOfEdges.getText());
          // currentLevel = i;
          //            if (i > 10)
          //            {
          //                speed.setText("Too high of a level count!");
          //                throw new UnsupportedOperationException();
          //            }
          clearKochPanel();
          // createKochFractal(i);
          double x = 0;
          try {
            x = loadBinaryFile();
          } catch (Exception e) {
            e.printStackTrace();
          }
          speed.setText(String.valueOf(x / 1000000));
          // drawAllEdges();
        });

    btnBinaryWithBuffer.setOnMouseClicked(
        event -> {
          int i = Integer.parseInt(nrOfEdges.getText());
          currentLevel = i;
          clearKochPanel();
          createKochFractal(i);
          double x = 0;
          try {
            x = saveBinaryFileWithBuffer();
          } catch (Exception e) {
            e.printStackTrace();
          }
          speed.setText(String.valueOf(x / 1000000));
        });
    Thread t =
        new Thread() {
          public void run() {
            watchForNewEdges();
          }
        };
    t.start();
  }
Esempio n. 9
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();
    }
  }