예제 #1
0
  public static void main(String[] args) {

    /////////////////////////////////////////////////////////////////////////////
    // 複数の例外をマルチキャッチ
    /////////////////////////////////////////////////////////////////////////////

    try {
      Date date = new SimpleDateFormat("yyyyMMdd").parse("20140401");
      new File(String.format("新規ファイル%s.txt", date.getTime())).createNewFile();

      // ParseExceptionまたはIOExceptionが発生した場合
    } catch (ParseException | IOException e) {
      System.out.println("例外発生: " + e.getMessage());
    }
  }
예제 #2
0
파일: User.java 프로젝트: Syndek/Root
  public void loadData() {
    try {
      JSONObject data =
          (JSONObject)
              new JSONParser()
                  .parse(new FileReader("plugins/Root/users/" + base.getUniqueId() + "/data.json"));
      JSONObject user = (JSONObject) data.get("user");
      JSONObject stat = (JSONObject) data.get("stat");
      JSONObject attributes = (JSONObject) user.get("attributes");

      fill = (boolean) attributes.get("fill");
      muted = (boolean) attributes.get("muted");
      frozen = (boolean) attributes.get("frozen"); // Let It Go
      undercover = (boolean) attributes.get("undercover");
    } catch (ParseException | IOException e) {
      Bukkit.getLogger()
          .warning("Error while loading data for " + getName() + ": " + e.getMessage());
    }
  }
  @Override
  public String save() {
    SimpleDateFormat format = new SimpleDateFormat("yyyy");
    Date data = null;
    try {
      data = new Date(format.parse(year).getTime());
      if (file != null && !file.getFileName().equals("")) {
        FacesMessage msg = new FacesMessage("Succesful" + file.getFileName() + " is uploaded.");
        FacesContext.getCurrentInstance().addMessage(null, msg);
        copyFile(file.getFileName(), file.getInputstream());
      }
    } catch (ParseException | IOException e) {
      e.printStackTrace();
    }
    super.selectedEntity.setYear(data);
    super.selectedEntity.setName(super.selectedEntity.getTitle());
    super.selectedEntity.setDescription(super.selectedEntity.getAbstract());
    saveAuthors(this.authors);
    super.selectedEntity.setFilepath(destination + file.getFileName());
    managePublicationsService.getDAO().save(super.selectedEntity);

    super.selectedEntity = new Publication();
    return list();
  }
예제 #4
0
  private JSONArray sendRequest(String param) {
    List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
    params.add(new BasicNameValuePair("content", param));
    params.add(new BasicNameValuePair("longestOnly", "true"));
    URI uri = null;
    try {
      uri = new URI(SCIGRAPH_ENTITIES_REQUEST_URL + "?" + URLEncodedUtils.format(params, "utf-8"));
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
    final HttpGet request = new HttpGet(uri);
    final DefaultHttpClient client = new DefaultHttpClient();
    HttpResponse response = null;
    try {
      response = new DefaultHttpClient().execute(request);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          null,
          "Network connection unable to be established.",
          "Network Error",
          JOptionPane.ERROR_MESSAGE);
      e.printStackTrace();
      return null;
    }
    client.getConnectionManager().shutdown();
    String json = null;
    try {
      json = EntityUtils.toString(response.getEntity());
    } catch (ParseException | IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    JSONArray responseJSON = new JSONArray(json);
    return responseJSON;
  }
예제 #5
0
  /** @param args */
  public static void main(String[] args) {
    initOptions();
    try {
      parse(args, false);

      String comm = args[1];

      String buildOption = null;

      // no needed to check as 'build' arg is required in Options
      if (!commandLine.hasOption("build") || commandLine.getOptionValue("build").equals("")) {}

      buildOption = commandLine.getOptionValue("build");

      if (buildOption.equals("genome-sequence")) {
        System.out.println("In genome-sequence");
        String indir = commandLine.getOptionValue("indir");
        String outfile = commandLine.getOptionValue("outfile", "/tmp/genome_sequence.json");
        if (indir != null) {
          GenomeSequenceFastaParser genomeSequenceFastaParser = new GenomeSequenceFastaParser();
          genomeSequenceFastaParser.parseFastaGzipFilesToJson(new File(indir), new File(outfile));
        }
      }

      if (buildOption.equals("core")) {
        System.out.println("In core");
        String gtfFile = commandLine.getOptionValue("gtf-file");
        String geneDescriptionFile = commandLine.getOptionValue("gene-description", "");
        String xrefFile = commandLine.getOptionValue("xref-file", "");
        String tfbsFile = commandLine.getOptionValue("tfbs-file", "");
        String mirnaFile = commandLine.getOptionValue("mirna-file", "");
        String genomeSequenceDir = commandLine.getOptionValue("genome-sequence-dir", "");
        String outfile = commandLine.getOptionValue("outfile", "/tmp/gene.json");
        if (gtfFile != null) {
          try {
            GeneParser geneParser = new GeneParser();
            geneParser.parse(
                new File(gtfFile),
                new File(geneDescriptionFile),
                new File(xrefFile),
                new File(tfbsFile),
                new File(mirnaFile),
                new File(genomeSequenceDir),
                new File(outfile));
          } catch (SecurityException | NoSuchMethodException | FileFormatException e) {
            e.printStackTrace();
          }
        }
      }

      if (buildOption.equals("variation")) {
        System.out.println("In variation");
        String indir = commandLine.getOptionValue("indir");
        int chunksize = Integer.parseInt(commandLine.getOptionValue("chunksize", "0"));
        System.out.println("chunksize: " + chunksize);
        String outfile = commandLine.getOptionValue("outfile", "/tmp/variation.json");
        if (indir != null) {
          VariationParser vp = new VariationParser();
          vp.createVariationDatabase(Paths.get(indir));

          vp.connect(Paths.get(indir));
          //					List<String> res = vp.queryByVariationId(13, "variation_synonym",
          // Paths.get(indir));
          //					System.out.println("a");
          //					 res = vp.queryByVariationId(4, "variation_synonym", Paths.get(indir));
          //					System.out.println("b");
          //					res = vp.queryByVariationId(8, "variation_synonym", Paths.get(indir));
          //					System.out.println("c");
          vp.parseVariationToJson("", "", "", "", Paths.get(indir), Paths.get(outfile));
          vp.disconnect();
        }
      }

      if (buildOption.equals("regulation")) {
        System.out.println("In regulation");
        String indir = commandLine.getOptionValue("indir");
        int chunksize = Integer.parseInt(commandLine.getOptionValue("chunksize", "0"));
        System.out.println("chunksize: " + chunksize);
        String outfile = commandLine.getOptionValue("outfile", "/tmp/regulations.json");
        if (indir != null) {
          try {
            RegulatoryParser.parseRegulatoryGzipFilesToJson(
                Paths.get(indir), chunksize, Paths.get(outfile));
          } catch (ClassNotFoundException | NoSuchMethodException | SQLException e) {
            e.printStackTrace();
          }
        }
      }

      if (buildOption.equals("conservation")) {
        System.out.println("In conservation");
        String indir = commandLine.getOptionValue("indir");
        int chunksize = Integer.parseInt(commandLine.getOptionValue("chunksize", "0"));
        String outfile = commandLine.getOptionValue("outfile", "/tmp/conservation.json");
        if (indir != null) {
          ConservedRegionParser.parseConservedRegionFilesToJson(
              Paths.get(indir), chunksize, Paths.get(outfile));
        }
      }

    } catch (ParseException | IOException | SQLException | ClassNotFoundException e) {
      e.printStackTrace();
    }
  }