Exemple #1
0
  @Override
  public ExitCode run(final SwiftEnvironment environment) {
    if (environment.getParameters().size() < 1) {
      throw new MprcException(
          "Missing path to configuration file.\nUsage: reformat-config <config> [<result>]");
    }

    final File file = new File(environment.getParameters().get(0));

    final PrintWriter printWriter;
    if (environment.getParameters().size() >= 2) {
      String pathname = environment.getParameters().get(1);
      try {
        printWriter = new PrintWriter(new File(pathname));
      } catch (FileNotFoundException e) {
        environment.logCommandError(
            "Could not open file for writing: "
                + pathname
                + "\n"
                + MprcException.getDetailedMessage(e));
        return ExitCode.Error;
      }
    } else {
      printWriter = new PrintWriter(System.out);
    }

    final AppConfigReader reader = new AppConfigReader(file, getFactory());
    try {
      reader.load(environment.getApplicationConfig());
    } finally {
      FileUtilities.closeQuietly(reader);
    }

    AppConfigWriter writer = null;

    try {
      writer = new AppConfigWriter(printWriter, getFactory());
      writer.save(environment.getApplicationConfig());
    } finally {
      FileUtilities.closeQuietly(writer);
      FileUtilities.closeQuietly(printWriter);
    }
    return ExitCode.Ok;
  }
 /**
  * goes to the first sequence in the sequence database file so that the next call to getHeader()
  * will return the first header in the file.
  */
 public void beforeFirst() {
   try {
     FileUtilities.closeQuietly(this.reader);
     reopenReader();
     this.nextHeader = this.reader.readLine();
   } catch (Exception e) {
     throw new MprcException(
         "Cannot open FASTA file [" + this.fastaFile.getAbsolutePath() + "]", e);
   }
 }
Exemple #3
0
  private static void writeWorkerAllocatorInputObject(final File file, final SgePacket object)
      throws IOException {
    BufferedWriter bufferedWriter = null;

    try {
      final XStream xStream = new XStream(new DomDriver());
      bufferedWriter = new BufferedWriter(new FileWriter(file));
      bufferedWriter.write(xStream.toXML(object));
    } finally {
      FileUtilities.closeQuietly(bufferedWriter);
    }
  }
  /** Start reading from the beginning */
  public void resetCurrentRowPointer() throws IOException {
    currentRowValue = null;

    FileUtilities.closeQuietly(reader);

    reader = new BufferedReader(new FileReader(file), BUFFER_SIZE);

    // Initialize by reading the first row
    nextRow();

    // Next call to nextRow will return the line we just read
    previousRow();
  }
Exemple #5
0
 /**
  * @param mgf .mgf file
  * @return List of all spectra titles.
  */
 public static List<String> getTitles(final File mgf) {
   PeakListReader sourceMgfReader = new MgfPeakListReader(mgf, false);
   List<String> titles = new ArrayList<String>(1000);
   try {
     MascotGenericFormatPeakList peakList;
     while ((peakList = sourceMgfReader.nextPeakList()) != null) {
       titles.add(peakList.getTitle());
     }
   } finally {
     FileUtilities.closeQuietly(sourceMgfReader);
   }
   return titles;
 }
  @Override
  protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
      throws ServletException {

    PrintWriter out = null;
    try {

      swiftDao.begin(); // Transaction-per-request

      final SearchRunFilter searchRunFilter = new SearchRunFilter();
      searchRunFilter.setStart("0");
      searchRunFilter.setCount("50");

      out = resp.getWriter();

      final StringBuilder response = new StringBuilder(TYPICAL_RESPONSE_SIZE);
      response.append("[");

      final List<SearchRun> searchRuns = swiftDao.getSearchRunList(searchRunFilter);
      for (int i = 0; i < searchRuns.size(); i++) {
        final SearchRun searchRun = searchRuns.get(i);
        final int runningTasks = swiftDao.getNumberRunningTasksForSearchRun(searchRun);
        JsonWriter.appendSearchRunJson(response, i, searchRun, runningTasks, null, false);
        if (i + 1 < searchRuns.size()) {
          response.append(",\n");
        }
      }
      response.append("]");

      out.print(response.toString());

      swiftDao.commit();

    } catch (Exception e) {
      swiftDao.rollback();
      throw new MprcException("Could not obtain list of search runs", e);
    } finally {
      FileUtilities.closeQuietly(out);
    }
  }
 /**
  * goes through each header in a fasta file and checks to make sure it is a valid fasta header. If
  * any problems are encountered or a header does not check out then false is returned
  *
  * @param toCheck the file you want to see is a valid FASTA file
  * @return true if the file is a valid fasta file else false
  */
 public static boolean isFASTAFileValid(final File toCheck) {
   DBInputStream in = null;
   try {
     in = new FASTAInputStream(toCheck);
     int sequenceCount = 0;
     in.beforeFirst();
     while (in.gotoNextSequence()) {
       if (isHeader(in.getHeader())) {
         sequenceCount++;
       } else {
         return false;
       }
     }
     return (sequenceCount != 0);
   } catch (Exception e) {
     // SWALLOWED: We just return false as in "not valid"
     LOGGER.warn(e);
     return false;
   } finally {
     FileUtilities.closeQuietly(in);
   }
 }
 /** performs any cleaning up that may be necessary. */
 public void close() {
   FileUtilities.closeQuietly(this.out);
 }
 /** performs any cleaning up that may be necessary. Always call when you are done. */
 public void close() {
   FileUtilities.closeQuietly(this.reader);
 }
 @Override
 public void close() throws IOException {
   FileUtilities.closeQuietly(reader);
 }