private void unzipPlugin(Path zip, Path target) throws IOException { Files.createDirectories(target); try (ZipInputStream zipInput = new ZipInputStream(Files.newInputStream(zip))) { ZipEntry entry; byte[] buffer = new byte[8192]; while ((entry = zipInput.getNextEntry()) != null) { Path targetFile = target.resolve(entry.getName()); // be on the safe side: do not rely on that directories are always extracted // before their children (although this makes sense, but is it guaranteed?) Files.createDirectories(targetFile.getParent()); if (entry.isDirectory() == false) { try (OutputStream out = Files.newOutputStream(targetFile)) { int len; while ((len = zipInput.read(buffer)) >= 0) { out.write(buffer, 0, len); } } } zipInput.closeEntry(); } } }
public static void main(String[] args) throws MessagingException, IOException { Properties props = new Properties(); try (InputStream in = Files.newInputStream(Paths.get("mail", "mail.properties"))) { props.load(in); } List<String> lines = Files.readAllLines(Paths.get(args[0]), Charset.forName("UTF-8")); String from = lines.get(0); String to = lines.get(1); String subject = lines.get(2); StringBuilder builder = new StringBuilder(); for (int i = 3; i < lines.size(); i++) { builder.append(lines.get(i)); builder.append("\n"); } Console console = System.console(); String password = new String(console.readPassword("Password: ")); Session mailSession = Session.getDefaultInstance(props); // mailSession.setDebug(true); MimeMessage message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(from)); message.addRecipient(RecipientType.TO, new InternetAddress(to)); message.setSubject(subject); message.setText(builder.toString()); Transport tr = mailSession.getTransport(); try { tr.connect(null, password); tr.sendMessage(message, message.getAllRecipients()); } finally { tr.close(); } }
public static void main(String[] args) throws IOException { Properties props = new Properties(); try (InputStream in = Files.newInputStream(Paths.get(args[0]))) { props.load(in); } String url = props.remove("url").toString(); String result = doPost(url, props); System.out.println(result); }
/** * Gets a connection from the properties specified in the file database.properties * * @return the database connection */ public static Connection getConnection() throws SQLException, IOException { Properties props = new Properties(); try (InputStream in = Files.newInputStream(Paths.get("database.properties"))) { props.load(in); } String drivers = props.getProperty("jdbc.drivers"); if (drivers != null) System.setProperty("jdbc.drivers", drivers); String url = props.getProperty("jdbc.url"); String username = props.getProperty("jdbc.username"); String password = props.getProperty("jdbc.password"); return DriverManager.getConnection(url, username, password); }
private void processFile(Path inGzPath, String conservedType) throws IOException { BufferedReader br = new BufferedReader( new InputStreamReader(new GZIPInputStream(Files.newInputStream(inGzPath)))); String line = null; String chromosome = ""; int start = 0, end = 0; float value; Map<String, String> attributes = new HashMap<>(); // ConservedRegion conservedRegion = null; List<Float> values = new ArrayList<>(); ConservedRegionChunk conservedRegion = null; while ((line = br.readLine()) != null) { if (line.startsWith("fixedStep")) { // new group, save last if (conservedRegion != null) { conservedRegion.setEnd(end); conservedRegion = new ConservedRegionChunk( chromosome, start, end, conservedType, start / CHUNKSIZE, values); fileSerializer.serialize(conservedRegion, getOutputFileName(chromosome)); } // offset = 0; attributes.clear(); String[] attrFields = line.split(" "); String[] attrKeyValue; for (String attrField : attrFields) { if (!attrField.equalsIgnoreCase("fixedStep")) { attrKeyValue = attrField.split("="); attributes.put(attrKeyValue[0].toLowerCase(), attrKeyValue[1]); } } chromosome = attributes.get("chrom").replace("chr", ""); start = Integer.parseInt(attributes.get("start")); end = Integer.parseInt(attributes.get("start")); values = new ArrayList<>(2000); } else { int startChunk = start / CHUNKSIZE; end++; int endChunk = end / CHUNKSIZE; if (startChunk != endChunk) { conservedRegion = new ConservedRegionChunk( chromosome, start, end - 1, conservedType, startChunk, values); fileSerializer.serialize(conservedRegion, getOutputFileName(chromosome)); values.clear(); start = end; } value = Float.parseFloat(line.trim()); values.add(value); } } // write last conservedRegion = new ConservedRegionChunk(chromosome, start, end, conservedType, start / CHUNKSIZE, values); fileSerializer.serialize(conservedRegion, getOutputFileName(chromosome)); br.close(); }