Esempio n. 1
0
  public static String store(InputStream in, String basePath, long userId, String imgName)
      throws IOException {
    String filePath =
        MessageFormat.format(
            Config.getString(Config.KEY_STORAGE_PATH_FORMAT),
            basePath,
            userId,
            DateUtils.date2Str(
                new Date(),
                Config.getString(
                    Config.KEY_STORAGE_DATE_FORMAT, DateUtils.DEFAULT_DATE_SIMPLE_FORMAT)),
            imgName);

    File file = new File(filePath);
    file.getParentFile().mkdirs();
    BufferedOutputStream bufOut = new BufferedOutputStream(new FileOutputStream(file));
    byte[] block = new byte[BUF_SIZE];
    int n = -1;
    while ((n = in.read(block)) != -1) {
      bufOut.write(block, 0, n);
    }
    bufOut.flush();
    bufOut.close();
    in.close();
    return filePath;
  }
Esempio n. 2
0
 public static String store(FormFile formFile, long userId) throws IOException {
   return store(formFile, Config.getString(Config.KEY_STORAGE_UPLOAD_BASE), userId);
 }