Ejemplo n.º 1
0
  public static final File writeFileItemToFolder(
      FileItem fileItem, File folder, boolean overwrite, boolean rename) throws IOException {
    if (!folder.isDirectory()) {
      return null;
    }
    File file =
        new File(
            URLHelper.mergePath(
                folder.getAbsolutePath(),
                StringHelper.createFileName(StringHelper.getFileNameFromPath(fileItem.getName()))));

    if (!file.exists()) {
      file.createNewFile();
    } else {
      if (!overwrite && !rename) {
        throw new FileExistsException("File already exists.");
      }
      if (rename) {
        file = ResourceHelper.getFreeFileName(file);
      }
    }
    InputStream in = null;
    try {
      in = fileItem.getInputStream();
      writeStreamToFile(in, file);
      return file;
    } catch (IOException e) {
      ResourceHelper.closeResource(in);
      file.delete();
      throw e;
    } finally {
      ResourceHelper.closeResource(in);
    }
  }
Ejemplo n.º 2
0
 public static boolean isPreviewFile(String file) {
   file = StringHelper.getFileNameFromPath(file);
   return file.startsWith("content_" + ContentContext.PREVIEW_MODE);
 }