コード例 #1
0
ファイル: DataQueueImpl.java プロジェクト: varhatia/ola
  protected void initializeTasks() {

    // read the file line by line and create Node to insert in dll
    BufferedReader br = null;
    try {
      br = new BufferedReader(new FileReader(storageFile));

      String line = br.readLine();
      StringBuilder stringBuilder = null;
      while (line != null) {
        stringBuilder = new StringBuilder();
        Node tNode = new Node(String.valueOf(line));
        nodeList.add(tNode);

        stringBuilder.append(Integer.getInteger(line));
        stringBuilder.append('\n');

        line = br.readLine();
      }
      if (stringBuilder != null) {
        FileUtil.writeFile(stringBuilder.toString().getBytes(), storageFile.getPath());
      }
    } catch (IOException e) {
      e.printStackTrace();
    } finally {
      try {
        if (br != null) br.close();
      } catch (IOException e) {
        e
            .printStackTrace(); // To change body of catch statement use File | Settings | File
                                // Templates.
      }
    }
  }
コード例 #2
0
ファイル: DataQueueImpl.java プロジェクト: varhatia/ola
  public synchronized void push(Node node) {
    // add to list
    nodeList.add(node);

    // write to file
    BufferedReader br = null;
    try {
      br = new BufferedReader(new FileReader(storageFile));

      String line = br.readLine();
      StringBuilder stringBuilder = new StringBuilder();
      ;
      while (line != null) {
        stringBuilder.append(String.valueOf(line));
        stringBuilder.append('\n');

        line = br.readLine();
      }

      stringBuilder.append(String.valueOf(node.getValue()));
      stringBuilder.append('\n');

      if (stringBuilder != null) {
        FileUtil.writeFile(stringBuilder.toString().getBytes(), storageFile.getPath());
      }

    } catch (IOException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } finally {
      if (br != null)
        try {
          br.close();
        } catch (IOException e) {
          e
              .printStackTrace(); // To change body of catch statement use File | Settings | File
                                  // Templates.
        }
    }
  }
コード例 #3
0
ファイル: DataQueueImpl.java プロジェクト: varhatia/ola
  private void updateFile() {
    // write to file
    BufferedReader br = null;
    try {
      br = new BufferedReader(new FileReader(storageFile));

      String line = br.readLine();
      line = br.readLine(); // for next line
      StringBuilder stringBuilder = new StringBuilder();

      while (line != null) {
        stringBuilder.append(String.valueOf(line));
        stringBuilder.append('\n');

        line = br.readLine();
      }

      if (stringBuilder != null) {
        FileUtil.writeFile(stringBuilder.toString().getBytes(), storageFile.getPath());
      }
    } catch (IOException e) {
      e
          .printStackTrace(); // To change body of catch statement use File | Settings | File
                              // Templates.
    } finally {
      if (br != null) {
        try {
          br.close();
        } catch (IOException e) {
          e
              .printStackTrace(); // To change body of catch statement use File | Settings | File
                                  // Templates.
        }
      }
    }
  }