コード例 #1
0
  @FXML
  private void handleLoadAction(ActionEvent event) {
    try {
      RandomAccessFile input = new RandomAccessFile("product.txt", "r");
      String line;

      for (int i = 0; ; i++) {
        line = input.readLine();
        if (line == null) break;
        int id = Integer.parseInt(line);
        line = input.readLine();
        String name = line;
        line = input.readLine();
        String category = line;
        line = input.readLine();
        double price = Double.parseDouble(line);

        Product p = new Product(id, name, category, price);
        products[i] = p;
      }
      productIDField.setText(products[0].getId() + "");
      productNameField.setText(products[0].getName());
      productCategoryField.setText(products[0].getCategory());
      unitPriceField.setText(products[0].getPrice() + "");
    } catch (FileNotFoundException ex) {
      Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
      Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
コード例 #2
0
ファイル: Search.java プロジェクト: sjuyal/Search-Wiki
  private static String searchtitle(String ans) throws IOException {
    // TODO Auto-generated method stub

    File f = new File(to + "\\title.txt");
    RandomAccessFile raf = new RandomAccessFile(f, "r");

    long start = 0;
    long end = f.length();
    long middle;

    while (start < end) {
      middle = (start + end) / 2;
      raf.seek(middle);
      raf.readLine();
      String line = raf.readLine();
      String tok[] = line.split(":");
      if (tok[0].equalsIgnoreCase(ans)) {
        return tok[1];
      } else {
        if (tok[0].compareTo(ans) > 0) {
          end = middle - 1;
        } else {
          start = middle + 1;
        }
      }
    }

    return "";
  }
コード例 #3
0
  private void getAgentIcons() {
    try {
      RandomAccessFile participantsFile =
          new RandomAccessFile(
              Simulator.inputFoldersPath + Simulator.inputFolder + "/participants.csv", "r");
      participantsFile.readLine();

      String currentLine = participantsFile.readLine();

      // Set the System Data
      while (!(currentLine == null)) {
        String[] theArgs = StringParseTools.readTokens(currentLine, ",");

        if (theArgs[2].contains("<player>")) {
          try {
            agentIcons.put(theArgs[1], convert(ImageIO.read(new File("images/" + theArgs[3]))));
          } catch (Exception e) {
            logger.warn(
                "Couldn't find the icon file 'images/"
                    + theArgs[3]
                    + "' for agent '"
                    + theArgs[1]
                    + "'.");
          }
        }

        // get next line
        currentLine = participantsFile.readLine();
      }
      participantsFile.close();
    } catch (Exception e) {
      logger.fatal("Error access System I/O file: ", e);
    }
  }
コード例 #4
0
ファイル: FASTQParse.java プロジェクト: jtb/BAMseek_java
  public String[] getNextRecord() {
    try {
      String ans[] = new String[3];
      String line;

      while ((line = filein.readLine()) != null) {
        // get description
        if (!line.substring(0, 1).equals("@")) return null;
        ans[0] = line.substring(1);
        String seq = "";
        String qual = "";
        while ((line = filein.readLine()) != null) {
          if (line.matches("[ACTGNacgtnURYSWKMBDHVN.-]*")) {
            seq += line;
          } else {
            if (!line.substring(0, 1).equals("+")) return null;
            // ans[2] = line.substring(1);
            while ((line = filein.readLine()) != null) {
              qual += line;
              if (seq.length() <= qual.length()) {
                ans[1] = seq;
                ans[2] = qual;
                return ans;
              }
            }
          }
        }
      }
      return null;
    } catch (Exception e) {
      return null;
    }
  }
コード例 #5
0
ファイル: PixGameHandler.java プロジェクト: PomepuyN/irondad
 public String getRandomWord(HandlerContext handlerContext) throws IOException {
   RandomAccessFile file =
       new RandomAccessFile(
           ((PixGameHandlerConfig) handlerContext.getHandlerConfig()).getDictPath(), "r");
   file.seek((long) (Math.random() * file.length()));
   // Eat the characters of the current line to go to beginning of the next line
   file.readLine();
   // Now read and return the line
   return file.readLine();
 }
 private static ArrayList<Share> readSharesFile(RandomAccessFile in)
     throws NumberFormatException, IOException {
   ArrayList<Share> list = new ArrayList<Share>();
   in.seek(0);
   while (in.getFilePointer() < in.length()) {
     list.add(
         new Share(
             Integer.parseInt(in.readLine()), in.readLine(), Integer.parseInt(in.readLine())));
   }
   return list;
 }
コード例 #7
0
ファイル: InteropTest.java プロジェクト: pyronicide/keyczar
  private final void testVerify(String subDir) throws Exception {
    Verifier verifier = new Verifier(testData(subDir));
    RandomAccessFile activeInput = new RandomAccessFile(testData(subDir) + "/1.out", "r");
    String activeSignature = activeInput.readLine();
    activeInput.close();
    RandomAccessFile primaryInput = new RandomAccessFile(testData(subDir) + "/2.out", "r");
    String primarySignature = primaryInput.readLine();
    primaryInput.close();

    assertTrue(verifier.verify(input, activeSignature));
    assertTrue(verifier.verify(input, primarySignature));
  }
コード例 #8
0
 /* (non-Javadoc)
  * @see java.awt.print.Printable#print(java.awt.Graphics, java.awt.print.PageFormat, int)
  */
 public int print(Graphics g, PageFormat pf, int page) throws PrinterException {
   int ret = PAGE_EXISTS;
   String line = null;
   try {
     if (fph.knownPage(page)) {
       in.seek(fph.getFileOffset(page));
       line = in.readLine();
     } else {
       long offset = in.getFilePointer();
       line = in.readLine();
       if (line == null) {
         ret = NO_SUCH_PAGE;
       } else {
         fph.createPage(page);
         fph.setFileOffset(page, offset);
       }
     }
     if (ret == PAGE_EXISTS) {
       // Seite ausgeben, Grafikkontext vorbereiten
       Graphics2D g2 = (Graphics2D) g;
       g2.scale(1.0 / RESMUL, 1.0 / RESMUL);
       int ypos = (int) pf.getImageableY() * RESMUL;
       int xpos = ((int) pf.getImageableX() + 2) * RESMUL;
       int yd = 12 * RESMUL;
       int ymax = ypos + (int) pf.getImageableHeight() * RESMUL - yd;
       // Seitentitel ausgeben
       ypos += yd;
       g2.setColor(Color.black);
       g2.setFont(new Font("Monospaced", Font.BOLD, 10 * RESMUL));
       g.drawString(fbname + " Seite " + (page + 1), xpos, ypos);
       g.drawLine(
           xpos,
           ypos + 6 * RESMUL,
           xpos + (int) pf.getImageableWidth() * RESMUL,
           ypos + 6 * RESMUL);
       ypos += 2 * yd;
       // Zeilen ausgeben
       g2.setColor(new Color(0, 0, 127));
       g2.setFont(new Font("Monospaced", Font.PLAIN, 10 * RESMUL));
       while (line != null) {
         g.drawString(line, xpos, ypos);
         ypos += yd;
         if (ypos >= ymax) {
           break;
         }
         line = in.readLine();
       }
     }
   } catch (IOException e) {
     throw new PrinterException(e.toString());
   }
   return ret;
 }
コード例 #9
0
  /**
   * Search index file for a primary key value
   *
   * @param pkvalue the primary key value to search for
   * @param position [0] = index entry, [1] = table row
   * @throws Exception
   */
  public boolean searchIndex(String pkvalue, Positions pos) throws Exception {
    boolean found = false;
    boolean end = false;
    if (!indexExists(def.getPK())) {
      throw new Exception("No index created");
    }
    int pkindex = def.getColPosition(def.getPK());
    if (pkindex == -1) {
      throw new Exception("Primary key does not exist");
    }

    // calculate index = hash value
    String s_value = pkvalue.trim();
    int index = hash(s_value);

    Integer[] size = def.getSizes();
    int recordSize = idxFixedRecordLength() + size[pkindex];

    indexFile.seek(index * recordSize);
    String line = indexFile.readLine();

    if (line.substring(0, 1).equals(" ")) {
      // Empty record, end of search
      found = false;
      return found;
    }

    String[] parts = line.split("#");
    String s_part = parts[2].trim();
    if (s_part.equals(pkvalue) && !(parts[1].equals("D"))) {
      found = true;
      pos.index = Integer.parseInt(parts[0].trim());
      pos.table = Integer.parseInt(parts[3].trim());
    }
    while (!found && !end) {
      if (parts[4].substring(0, 4).equals("null")) {
        // end of linked list
        end = true;
        found = false;
      } else {
        index = Integer.parseInt(parts[4].trim());
        indexFile.seek(index * recordSize);
        line = indexFile.readLine();
        parts = line.split("#");
        if (parts[2].trim().equals(pkvalue) && !(parts[1].equals("D"))) {
          found = true;
          pos.index = Integer.parseInt(parts[0].trim());
          pos.table = Integer.parseInt(parts[3].trim());
        }
      }
    }
    return found;
  }
コード例 #10
0
ファイル: InteropTest.java プロジェクト: pyronicide/keyczar
 private final void testDecrypt(KeyczarReader reader, String subDir) throws Exception {
   Crypter crypter = new Crypter(reader);
   RandomAccessFile activeInput = new RandomAccessFile(testData(subDir) + "/1.out", "r");
   String activeCiphertext = activeInput.readLine();
   activeInput.close();
   RandomAccessFile primaryInput = new RandomAccessFile(testData(subDir) + "/2.out", "r");
   String primaryCiphertext = primaryInput.readLine();
   primaryInput.close();
   String activeDecrypted = crypter.decrypt(activeCiphertext);
   assertEquals(input, activeDecrypted);
   String primaryDecrypted = crypter.decrypt(primaryCiphertext);
   assertEquals(input, primaryDecrypted);
 }
コード例 #11
0
  @Override
  public float getCpuUsage(int cpu_index) throws CpuSenseException {
    try {
      String load = "";

      /**
       * Example of /proc/stat: cpu 2255 34 2290 22625563 6290 127 456 cpu0 1132 34 1441 11311718
       * 3675 127 438 cpu1 1123 0 849 11313845 2614 0 18 ... Implemented method: [1] user: normal
       * processes executing in user mode [2] nice: niced processes executing in user mode [3]
       * system: processes executing in kernel mode [4] idle: twiddling thumbs find previous_idle
       * ([4]) and previous_cpu (sum of [2][3][1]) Sleep for 360 millis find current_idle ([4]) and
       * current_cpu (sum of [2][3][1]) proc stat return (float)(current_cpu - previous_cpu) /
       * ((current_cpu + current_idle) - (previous_cpu + previous_idle))*100;
       */
      RandomAccessFile reader = new RandomAccessFile(CPU_USAGE_STATS, "r");

      // Skip lines until the right CPU
      for (int i = 0; i <= cpu_index; i++) load = reader.readLine();

      load = reader.readLine();
      String[] toks = load.split(" "); // Parse on white spaces
      long previous_idle = Long.parseLong(toks[4]);
      long previous_cpu =
          Long.parseLong(toks[2]) + Long.parseLong(toks[3]) + Long.parseLong(toks[1]);

      try {
        Thread.sleep(360); // Sleep for an epsilon time
      } catch (Exception e) {
      }

      reader.seek(0); // Go back in the same file

      // Skip lines until the right CPU
      for (int i = 0; i <= cpu_index; i++) load = reader.readLine();

      load = reader.readLine();
      reader.close();

      toks = load.split(" "); // Parse on white spaces
      long current_idle = Long.parseLong(toks[4]);
      long current_cpu =
          Long.parseLong(toks[2]) + Long.parseLong(toks[3]) + Long.parseLong(toks[1]);

      return (float) (current_cpu - previous_cpu)
          / ((current_cpu + current_idle) - (previous_cpu + previous_idle))
          * 100;

    } catch (Exception e) {
      throw new CpuSenseException("Error while getting cpu usage (" + e.getMessage() + ")");
    }
  }
コード例 #12
0
 private static ArrayList<Company> readCompaniesFile(RandomAccessFile in)
     throws NumberFormatException, IOException {
   ArrayList<Company> list = new ArrayList<Company>();
   in.seek(0);
   while (in.getFilePointer() < in.length()) {
     list.add(
         new Company(
             in.readLine(),
             in.readLine(),
             Integer.parseInt(in.readLine()),
             Double.parseDouble(in.readLine())));
   }
   return list;
 }
コード例 #13
0
  @FXML
  private void handleNextAction(ActionEvent event) {
    int pr_id = Integer.parseInt(productIDField.getText());
    String pr_name = productNameField.getText();
    String pr_category = productCategoryField.getText();
    double pr_unit_price = Double.parseDouble(unitPriceField.getText());

    Product pr_product = new Product(pr_id, pr_name, pr_category, pr_unit_price);
    if (pr_product != null) {
      try {
        RandomAccessFile input = new RandomAccessFile("product.txt", "r");
        String line;

        for (int i = 0; ; i++) {
          line = input.readLine();
          //                    if (line == null)
          //                        break;
          int id = Integer.parseInt(line);
          line = input.readLine();
          String name = line;
          line = input.readLine();
          String category = line;
          line = input.readLine();
          double price = Double.parseDouble(line);

          Product p = new Product(id, name, category, price);
          products[i] = p;
          if (products[i].getId() == pr_product.getId() && i < products.length) {
            line = input.readLine();
            int next_id = Integer.parseInt(line);
            line = input.readLine();
            String next_name = line;
            line = input.readLine();
            String next_category = line;
            line = input.readLine();
            double next_unit_price = Double.parseDouble(line);
            Product next_product = new Product(next_id, next_name, next_category, next_unit_price);
            products[i + 1] = next_product;
            productIDField.setText(products[i + 1].getId() + "");
            productNameField.setText(products[i + 1].getName());
            productCategoryField.setText(products[i + 1].getCategory());
            unitPriceField.setText(products[i + 1].getPrice() + "");
            break;
          }
          //                    else if(products[0] == pr_product){
          //                        productIDField.setText(products[0].getId() + "");
          //                        productNameField.setText(products[0].getName());
          //                        productCategoryField.setText(products[0].getCategory());
          //                        unitPriceField.setText(products[0].getPrice() + "");
          //                        break;
          //                    }
        }
      } catch (FileNotFoundException ex) {
        Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
      } catch (IOException ex) {
        Logger.getLogger(FXMLDocumentController.class.getName()).log(Level.SEVERE, null, ex);
      }
    }
  }
コード例 #14
0
ファイル: FillDatabase.java プロジェクト: Letractively/web-rp
 private void addDescriptions() throws IOException {
   RandomAccessFile f = new RandomAccessFile("randomDescription.csv", "r");
   String dataString = null;
   Random random = new Random(1l);
   ArrayList<String> descriptions = new ArrayList<String>();
   while ((dataString = f.readLine()) != null) {
     descriptions.add(dataString);
   }
   f.close();
   try {
     ArrayList<Resource> resources = resourceDAO.getAllResources();
     for (Resource r : resources) {
       r.setDescription(descriptions.get(random.nextInt(descriptions.size())));
       resourceDAO.updateResource(r);
     }
   } catch (DAOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (ResourceNameExistsException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   } catch (ResourceHasActiveProjectException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }
コード例 #15
0
  public void run() {
    long lengthBefore = 0;
    long length = 0;

    try {

      long filePointer = 0;
      if (this.startAtBeginning) {
        filePointer = 0;
      } else {
        filePointer = this.theNewestFile.length();
      }
      this.tailing = true;
      reader = new RandomAccessFile(theNewestFile, "r");
      while (this.tailing) {
        long fileLength = this.theNewestFile.length();
        if (fileLength < filePointer) {

          reader = new RandomAccessFile(theNewestFile, "r");
          filePointer = 0;
        }
        if ((length = theNewestFile.length()) > lengthBefore) {
          reader.seek(lengthBefore);
          lengthBefore = length;
          while (!((linetoRead = reader.readLine()) == null)) {
            callData();
          }
          filePointer = reader.getFilePointer();
        }
        sleep(this.sampleInterval);
        reader.close();
      }
    } catch (Exception e) {
    }
  }
コード例 #16
0
  /**
   * Delete an index entry in the idx file of the specified column.
   *
   * @param colname the column's name
   * @param idxPos index entry (line nr) to be deleted
   * @throws Exception
   */
  protected long deleteIndexEntry(String colname, int idxPos) throws Exception {
    long s = System.currentTimeMillis();
    if (!indexExists(colname)) {
      throw new Exception("No index created");
    }
    int pkindex = def.getColPosition(colname);
    if (pkindex == -1) {
      throw new Exception("Column does not exist");
    }
    Integer[] size = def.getSizes();
    int recordSize = idxFixedRecordLength() + size[pkindex];

    indexFile.seek(idxPos * recordSize);
    String sLine = indexFile.readLine();
    String[] parts = sLine.split("#");
    if (Integer.parseInt(parts[0].trim()) != idxPos) {
      throw new Exception("Index not found in index file");
    } else {
      indexFile.seek(idxPos * recordSize + 6);
      String flag = "D";
      indexFile.write(flag.toString().getBytes());
    }
    long e = System.currentTimeMillis();
    return e - s;
  }
コード例 #17
0
  /**
   * Opens an existing data network from a string and saves as a stream.
   *
   * @throws UdmException
   * @throws IOException
   */
  public void testOpenExistingFromStringSaveToStream() throws UdmException, IOException {
    String xml = new String("");

    RandomAccessFile raf = new RandomAccessFile(BM_FILE_IN, "r");
    String line = null;

    while ((line = raf.readLine()) != null) {
      xml += (line + "\n");
    }

    raf.close();

    ContainerStringFactory gtf = FactoryRepository.getTimeSeriesContainerStringFactory();
    UdmPseudoObject rootUPO = gtf.open(xml);
    Container con = null;

    if (rootUPO instanceof Container) {
      con = (Container) rootUPO;
    } else {
      fail("Unexpected root type: " + rootUPO.getType());
    }

    InputStream a = gtf.saveAsStream();
    System.out.println("\ntestOpenExistingFromStringSaveToStream():\n" + a);
    printInputStream(a);
  }
コード例 #18
0
 private static ArrayList<Transaction> readTransactionsFile(RandomAccessFile in)
     throws NumberFormatException, IOException, ParseException {
   ArrayList<Transaction> list = new ArrayList<Transaction>();
   in.seek(0);
   while (in.getFilePointer() < in.length()) {
     list.add(
         new Transaction(
             Integer.parseInt(in.readLine()),
             Integer.parseInt(in.readLine()),
             in.readLine(),
             Integer.parseInt(in.readLine()),
             Double.parseDouble(in.readLine()),
             DataHandler.dateFormat.parse(in.readLine())));
   }
   return list;
 }
コード例 #19
0
ファイル: InteropTest.java プロジェクト: pyronicide/keyczar
 private final void testVerifyUnversioned(String subDir) throws Exception {
   UnversionedVerifier verifier = new UnversionedVerifier(testData(subDir));
   RandomAccessFile activeInput = new RandomAccessFile(testData(subDir) + "/2.unversioned", "r");
   String activeSignature = activeInput.readLine();
   activeInput.close();
   assertTrue(verifier.verify(input, activeSignature));
 }
コード例 #20
0
ファイル: FillDatabase.java プロジェクト: Letractively/web-rp
 private void addResources() throws IOException {
   RandomAccessFile f = new RandomAccessFile("randomResource.csv", "r");
   String dataString = null;
   ResourceType type = null;
   while ((dataString = f.readLine()) != null) {
     String[] data = dataString.split(";");
     Resource insert = new Resource();
     if (data[0].length() < 45) {
       insert.setResourceName(data[0]);
     } else {
       insert.setResourceName(data[0].substring(0, 44));
     }
     try {
       insert.setResourceTypeID(
           resourceTypeDAO.getResourceTypeByResourceTypeName(data[1]).getResourceTypeID());
     } catch (Exception e1) {
       e1.printStackTrace();
     }
     insert.setDescription("");
     insert.setActive(true);
     System.out.println(insert);
     try {
       resourceDAO.insertResource(insert);
     } catch (Exception e) {
       e.printStackTrace();
     }
   }
   f.close();
 }
コード例 #21
0
ファイル: LogReader.java プロジェクト: cstudioteam/csFrame
  @Override
  public void run() {

    try {
      while (shouldIRun) {
        Thread.sleep(crunchifyRunEveryNSeconds);
        long fileLength = crunchifyFile.length();
        if (fileLength > lastKnownPosition) {

          // Reading and writing file
          RandomAccessFile readWriteFileAccess = new RandomAccessFile(crunchifyFile, "rw");
          readWriteFileAccess.seek(lastKnownPosition);
          String crunchifyLine = null;
          while ((crunchifyLine = readWriteFileAccess.readLine()) != null) {
            for (Session s : AppLogView.sessions) {
              // s.getAsyncRemote().sendText(crunchifyLine);
              s.getBasicRemote().sendText(crunchifyLine);
            }
          }
          lastKnownPosition = readWriteFileAccess.getFilePointer();
          readWriteFileAccess.close();
        }
      }
    } catch (Exception e) {
      shouldIRun = false;
    }
  }
コード例 #22
0
  /**
   * Given an InputFile, and destination temporary directory attempts to split a file using the
   * specified number assuring that lines are not broken into separate chunks. The first line of the
   * <b>inputFile</b> is assumed to be a header and is added to the begining of each chunk.
   *
   * @return an {@link ArrayList} of {@link TransformTask}s each corresponding to a splitted chunk.
   */
  public ArrayList<TransformTask> splitFile(File inputFile, File tmpDirectory) throws IOException {

    ArrayList<TransformTask> tasks = new ArrayList<TransformTask>();

    RandomAccessFile seeakableFile = new RandomAccessFile(inputFile, "r");
    long fileSize = seeakableFile.length();
    long currentPosition = 0L;
    int blockNumber = 1;
    File chunk;

    if (fileSize > 2 * MIN_SPLIT_BLOCK && fSplitFactor > 1) {
      String header = seeakableFile.readLine() + LINE_SEPARATOR;
      long blocksize = fileSize / fSplitFactor;
      long nextEOL = 0L;
      try {
        nextEOL = findNextEOLPosition(seeakableFile, blocksize);

        chunk =
            copy(
                seeakableFile,
                getTempFile(tmpDirectory, blockNumber, inputFile),
                currentPosition,
                nextEOL,
                null);

        tasks.add(new TransformTask(chunk, blockNumber, tmpDirectory));

        for (blockNumber = 2; ; blockNumber++) {
          currentPosition = seeakableFile.getFilePointer();
          nextEOL = findNextEOLPosition(seeakableFile, blocksize);
          chunk =
              copy(
                  seeakableFile,
                  getTempFile(tmpDirectory, blockNumber, inputFile),
                  currentPosition,
                  nextEOL,
                  header);
          tasks.add(new TransformTask(chunk, blockNumber, tmpDirectory));
        }

      } catch (EndReachedException e) {
        chunk =
            copy(
                seeakableFile,
                getTempFile(tmpDirectory, blockNumber, inputFile),
                currentPosition,
                fileSize,
                header);
        tasks.add(new TransformTask(chunk, blockNumber, tmpDirectory));
      } finally {
        Utils.safeClose(seeakableFile);
      }

    } else {
      tasks.add(new TransformTask(inputFile, blockNumber, tmpDirectory));
      Utils.safeClose(seeakableFile);
    }
    return tasks;
  }
コード例 #23
0
 /**
  * ·µ»ØÔÊÐí×¢²á·ñ
  *
  * @param num JQºÅÂë
  * @return ·µ»ØÔÊÐí×¢²á·ñ
  * @throws FileNotFoundException
  * @throws IOException
  */
 private boolean isAllowReged(Integer num) throws FileNotFoundException, IOException {
   RandomAccessFile raf = getFile();
   String s;
   while ((s = raf.readLine()) != null) {
     if (s.indexOf(num + "") != -1) return false;
   }
   return true;
 }
コード例 #24
0
ファイル: InteropTest.java プロジェクト: pyronicide/keyczar
 private final void testTimeoutVerifierExpired(String subDir) throws Exception {
   TimeoutVerifier verifier = new TimeoutVerifier(testData(subDir));
   verifier.setClock(new LateClock());
   RandomAccessFile activeInput = new RandomAccessFile(testData(subDir) + "/2.timeout", "r");
   String activeSignature = activeInput.readLine();
   activeInput.close();
   assertFalse(verifier.verify(input, activeSignature));
 }
コード例 #25
0
ファイル: InteropTest.java プロジェクト: pyronicide/keyczar
 private final void testVerifySize(String subDir, String size) throws Exception {
   Verifier verifier = new Verifier(testData(subDir + "-size"));
   RandomAccessFile activeInput =
       new RandomAccessFile(testData(subDir) + "-size/" + size + ".out", "r");
   String activeSignature = activeInput.readLine();
   activeInput.close();
   assertTrue(verifier.verify(input, activeSignature));
 }
コード例 #26
0
 public void changes(ActionEvent event) throws IOException {
   String new_cat, new_money, temp, dates;
   int new_money1;
   localdate = date.getValue();
   dates = date.getValue().toString();
   new_cat = cat.getText();
   new_money = money.getText();
   if (new_cat == "" || new_money == "") {
     lb2.setText("Enter values");
   }
   new_money1 = Integer.parseInt(new_money);
   if (new_money1 > Available1) {
     lb2.setText("Budget Exceeded");
     lb2.setTextFill(Color.ORANGE);
   } else {
     expense = expense + new_money1;
     lb2.setText("Added");
     lb2.setTextFill(Color.GREEN);
     Available1 = Available1 - new_money1;
     temp = Integer.toString(Available1);
     Expense_Available.setText(temp);
     RandomAccessFile q = new RandomAccessFile("./src/Expenses.txt", "rw");
     q.readLine();
     q.write(("AvailableRs. " + temp).getBytes());
     q.seek(0);
     while (q.readLine() != null) {
       q.readLine();
     }
     q.write(
         (new_cat
                 + " "
                 + new_money
                 + " "
                 + localdate.getYear()
                 + "/"
                 + localdate.getMonthValue()
                 + "/"
                 + localdate.getDayOfMonth()
                 + "\n")
             .getBytes());
     q.close();
     data.add(new Expense(new_cat, new_money1, dates));
     table.setItems(data);
   }
 }
コード例 #27
0
ファイル: CPUInfo.java プロジェクト: Pavel87/DeviceDiag
  private float readUsage() {
    try {
      RandomAccessFile reader = new RandomAccessFile("/proc/stat", "r");
      String load = reader.readLine();

      String[] toks = load.split(" +"); // Split on one or more spaces

      long idle1 = Long.parseLong(toks[4]);
      long cpu1 =
          Long.parseLong(toks[2])
              + Long.parseLong(toks[3])
              + Long.parseLong(toks[5])
              + Long.parseLong(toks[6])
              + Long.parseLong(toks[7])
              + Long.parseLong(toks[8]);

      try {
        Thread.sleep(360);
      } catch (Exception e) {
        e.printStackTrace();
      }

      reader.seek(0);
      load = reader.readLine();
      reader.close();

      toks = load.split(" +");

      long idle2 = Long.parseLong(toks[4]);
      long cpu2 =
          Long.parseLong(toks[2])
              + Long.parseLong(toks[3])
              + Long.parseLong(toks[5])
              + Long.parseLong(toks[6])
              + Long.parseLong(toks[7])
              + Long.parseLong(toks[8]);

      return (float) (cpu2 - cpu1) / ((cpu2 + idle2) - (cpu1 + idle1));

    } catch (IOException ex) {
      ex.printStackTrace();
    }

    return 0;
  }
コード例 #28
0
 private static long findTurtlePrefixEnd(RandomAccessFile file) throws IOException {
   long lastLinePosition = -1;
   String line = "";
   while ((line = file.readLine()) != null) {
     if (!line.trim().startsWith("@")) break;
     lastLinePosition = file.getFilePointer();
   }
   return lastLinePosition;
 }
コード例 #29
0
ファイル: InteropTest.java プロジェクト: pyronicide/keyczar
 private final void testDecryptSize(String subDir, String size) throws Exception {
   Crypter crypter = new Crypter(testData(subDir + "-size"));
   RandomAccessFile activeInput =
       new RandomAccessFile(testData(subDir) + "-size/" + size + ".out", "r");
   String activeCiphertext = activeInput.readLine();
   activeInput.close();
   String activeDecrypted = crypter.decrypt(activeCiphertext);
   assertEquals(input, activeDecrypted);
 }
コード例 #30
0
ファイル: InteropTest.java プロジェクト: pyronicide/keyczar
  private final void testSessionDecrypt(String subDir) throws Exception {
    RandomAccessFile activeInput =
        new RandomAccessFile(testData(subDir) + "/2.session.material", "r");
    String sessionMaterial = activeInput.readLine();
    activeInput.close();

    SessionCrypter crypter =
        new SessionCrypter(
            new Crypter(testData(subDir)), Base64Coder.decodeWebSafe(sessionMaterial));

    RandomAccessFile primaryInput =
        new RandomAccessFile(testData(subDir) + "/2.session.ciphertext", "r");
    String activeCiphertext = primaryInput.readLine();
    primaryInput.close();

    byte[] activeDecrypted = crypter.decrypt(Base64Coder.decodeWebSafe(activeCiphertext));
    assertEquals(input, new String(activeDecrypted, Keyczar.DEFAULT_ENCODING));
  }