Beispiel #1
0
 public static byte[] input(String fileName) {
   try {
     return input(Files.newInputStream(IO.path(fileName)));
   } catch (IOException e) {
     return Exceptions.handle(byte[].class, e);
   }
 }
Beispiel #2
0
  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();
    }
  }
Beispiel #3
0
 public static InputStream inputStream(String resource) {
   Path path = path(resource);
   try {
     return Files.newInputStream(path);
   } catch (IOException e) {
     return Exceptions.handle(InputStream.class, "unable to open " + resource, e);
   }
 }
Beispiel #4
0
 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);
 }
  public static long checksumBufferedInputStream(Path filename) throws IOException {
    try (InputStream in = new BufferedInputStream(Files.newInputStream(filename))) {
      CRC32 crc = new CRC32();

      int c;
      while ((c = in.read()) != -1) crc.update(c);
      return crc.getValue();
    }
  }
Beispiel #6
0
  /**
   * 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);
  }