Пример #1
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();
    }
  }
Пример #2
0
 /**
  * Return a FileItem which is going to be automatically destroyed upon destruction of the request,
  * session or application.
  */
 public static FileItem prepareFileItem(PipelineContext pipelineContext, int scope) {
   // We use the commons file upload utilities to save a file
   if (fileItemFactory == null)
     fileItemFactory = new DiskFileItemFactory(0, SystemUtils.getTemporaryDirectory());
   final FileItem fileItem = fileItemFactory.createItem("dummy", "dummy", false, null);
   // Make sure the file is deleted appropriately
   if (scope == REQUEST_SCOPE) {
     deleteFileOnRequestEnd(pipelineContext, fileItem);
   } else if (scope == SESSION_SCOPE) {
     deleteFileOnSessionTermination(pipelineContext, fileItem);
   } else if (scope == APPLICATION_SCOPE) {
     deleteFileOnContextDestroyed(pipelineContext, fileItem);
   } else {
     throw new OXFException("Invalid context requested: " + scope);
   }
   // Return FileItem object
   return fileItem;
 }