public OutputStream getOutputStream() {
   try {
     return wrapped.getOutputStream();
   } catch (IOException ex) {
     throw new RuntimeException(ex);
   }
 }
Example #2
0
  private static FileItem prepareFileItemFromInputStream(
      PipelineContext pipelineContext, InputStream inputStream, int scope) {
    // Get FileItem
    final FileItem fileItem = prepareFileItem(pipelineContext, scope);
    // Write to file
    OutputStream os = null;
    try {
      os = fileItem.getOutputStream();
      copyStream(inputStream, os);
    } catch (IOException e) {
      throw new OXFException(e);
    } finally {
      if (os != null) {
        try {
          os.close();
        } catch (IOException e) {
          throw new OXFException(e);
        }
      }
    }
    // Create file if it doesn't exist (necessary when the file size is 0)
    final File storeLocation = ((DiskFileItem) fileItem).getStoreLocation();
    try {
      storeLocation.createNewFile();
    } catch (IOException e) {
      throw new OXFException(e);
    }

    return fileItem;
  }
Example #3
0
  public void Create() throws IOException {

    FileItemFactory factory = new DiskFileItemFactory(fContent.length(), null);

    this.item = factory.createItem("field1", " text/html", true, "temp.txt");

    OutputStream os = item.getOutputStream();
    os.write(fContent.getBytes());
    os.close();

    Class<? extends FileItem> c = item.getClass();
    // Field [] ownFields= c.getDeclaredFields();
    // for (Field field: ownFields){
    // Class fieldType = field.getType();
    // System.out.println(field.getName());
    // System.out.println(fieldType.getName());
    // }

    try {
      File nr = new File(fPathTarget);

      Field field = c.getDeclaredField("repository");
      field.setAccessible(true);
      field.set(item, nr);

      File rep = (File) field.get(item);
      System.out.println("repository: " + rep);

      Field field1 = c.getDeclaredField("sizeThreshold");
      field1.setAccessible(true);
      field1.setInt(item, 1);

      // Integer size = (Integer) field1.get(item);
      // System.out.println("size " + size);
    } catch (SecurityException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (NoSuchFieldException e) {
      // TODO Auto-gnerated catch block
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }