org.apache.commons.fileupload.disk.DiskFileItem Java Examples
The following examples show how to use
org.apache.commons.fileupload.disk.DiskFileItem.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PopupForm.java From sakai with Educational Community License v2.0 | 6 votes |
public static PopupForm fromRequest(String uuid, HttpServletRequest request) { String descriptor = request.getParameter("descriptor"); boolean isOpenCampaign = "open-campaign".equals(request.getParameter("open-campaign")); long startTime = "".equals(request.getParameter("start_time")) ? 0 : parseTime(request.getParameter("start_time_selected_datetime")); long endTime = "".equals(request.getParameter("end_time")) ? 0 : parseTime(request.getParameter("end_time_selected_datetime")); List<String> assignToEids = new ArrayList<String>(); if (request.getParameter("distribution") != null) { for (String user : request.getParameter("distribution").split("[\r\n]+")) { if (!user.isEmpty()) { assignToEids.add(user); } } } Optional<DiskFileItem> templateItem = Optional.empty(); DiskFileItem dfi = (DiskFileItem) request.getAttribute("template"); if (dfi != null && dfi.getSize() > 0) { templateItem = Optional.of(dfi); } return new PopupForm(uuid, descriptor, startTime, endTime, isOpenCampaign, assignToEids, templateItem); }
Example #2
Source File: ClassUploadManagerTest.java From CodeDefenders with GNU Lesser General Public License v3.0 | 6 votes |
/** * Create an instance of FileItem in a temporary file. * * @param fieldName * @param fileName * @param classPathResource * @return * @throws IOException * @throws URISyntaxException */ private FileItem createFileItemFromClassPathResource(String fieldName, String fileName, String classPathResource) throws IOException, URISyntaxException { InputStream inputStream = getClass().getResourceAsStream(classPathResource); Path inputPath = Paths.get(getClass().getResource(classPathResource).toURI()); int availableBytes = inputStream.available(); // Write the inputStream to a FileItem File outFile = codedefendersHome.createTempFile("ClassUploadManagerTest",""); outFile.deleteOnExit(); String contentType = null; if( classPathResource.endsWith(".zip") ){ contentType = "application/zip"; } else { contentType = "plain/text"; } FileItem fileItem = new DiskFileItem(fieldName, contentType, false, fileName, availableBytes, outFile); Files.copy(inputPath, fileItem.getOutputStream()); return fileItem; }
Example #3
Source File: FileUpload1.java From ysoserial with MIT License | 6 votes |
public DiskFileItem getObject ( String command ) throws Exception { String[] parts = command.split(";"); if ( parts.length == 3 && "copyAndDelete".equals(parts[ 0 ]) ) { return copyAndDelete(parts[ 1 ], parts[ 2 ]); } else if ( parts.length == 3 && "write".equals(parts[ 0 ]) ) { return write(parts[ 1 ], parts[ 2 ].getBytes("US-ASCII")); } else if ( parts.length == 3 && "writeB64".equals(parts[ 0 ]) ) { return write(parts[ 1 ], Base64.decodeBase64(parts[ 2 ])); } else if ( parts.length == 3 && "writeOld".equals(parts[ 0 ]) ) { return writePre131(parts[ 1 ], parts[ 2 ].getBytes("US-ASCII")); } else if ( parts.length == 3 && "writeOldB64".equals(parts[ 0 ]) ) { return writePre131(parts[ 1 ], Base64.decodeBase64(parts[ 2 ])); } else { throw new IllegalArgumentException("Unsupported command " + command + " " + Arrays.toString(parts)); } }
Example #4
Source File: PopupForm.java From sakai with Educational Community License v2.0 | 6 votes |
public static PopupForm fromRequest(String uuid, HttpServletRequest request) { String descriptor = request.getParameter("descriptor"); boolean isOpenCampaign = "open-campaign".equals(request.getParameter("open-campaign")); long startTime = "".equals(request.getParameter("start_time")) ? 0 : parseTime(request.getParameter("start_time_selected_datetime")); long endTime = "".equals(request.getParameter("end_time")) ? 0 : parseTime(request.getParameter("end_time_selected_datetime")); List<String> assignToEids = new ArrayList<String>(); if (request.getParameter("distribution") != null) { for (String user : request.getParameter("distribution").split("[\r\n]+")) { if (!user.isEmpty()) { assignToEids.add(user); } } } Optional<DiskFileItem> templateItem = Optional.empty(); DiskFileItem dfi = (DiskFileItem) request.getAttribute("template"); if (dfi != null && dfi.getSize() > 0) { templateItem = Optional.of(dfi); } return new PopupForm(uuid, descriptor, startTime, endTime, isOpenCampaign, assignToEids, templateItem); }
Example #5
Source File: FileUpload1.java From ysoserial-modified with MIT License | 6 votes |
public DiskFileItem getObject ( CmdExecuteHelper cmdHelper ) throws Exception { String[] parts = cmdHelper.getCommand().split(";"); if ( parts.length == 3 && "copyAndDelete".equals(parts[ 0 ]) ) { return copyAndDelete(parts[ 1 ], parts[ 2 ]); } else if ( parts.length == 3 && "write".equals(parts[ 0 ]) ) { return write(parts[ 1 ], parts[ 2 ].getBytes("US-ASCII")); } else if ( parts.length == 3 && "writeB64".equals(parts[ 0 ]) ) { return write(parts[ 1 ], Base64.decodeBase64(parts[ 2 ])); } else if ( parts.length == 3 && "writeOld".equals(parts[ 0 ]) ) { return writePre131(parts[ 1 ], parts[ 2 ].getBytes("US-ASCII")); } else if ( parts.length == 3 && "writeOldB64".equals(parts[ 0 ]) ) { return writePre131(parts[ 1 ], Base64.decodeBase64(parts[ 2 ])); } else { throw new IllegalArgumentException("Unsupported command " + cmdHelper.getCommand() + " " + Arrays.toString(parts)); } }
Example #6
Source File: AdminUserJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testDoImportUsersFromFileNoToken( ) throws AccessDeniedException, UserNotSignedException, IOException { AdminUserJspBean bean = new AdminUserJspBean( ); MockHttpServletRequest request = new MockHttpServletRequest( ); AdminUser user = getUserToModify( ); AdminAuthenticationService.getInstance( ).registerUser( request, user ); bean.init( request, "CORE_USERS_MANAGEMENT" ); Map<String, List<FileItem>> multipartFiles = new HashMap<>( ); List<FileItem> fileItems = new ArrayList<>( ); FileItem file = new DiskFileItem( "import_file", "application/csv", true, "junit.csv", 1024, new File( System.getProperty( "java.io.tmpdir" ) ) ); OutputStreamWriter writer = new OutputStreamWriter( file.getOutputStream( ), Charset.forName( "UTF-8" ) ); writer.write( "test;test;test;[email protected];" + AdminUser.ACTIVE_CODE + ";" + Locale.FRANCE + ";0;false;false;;;" ); writer.close( ); fileItems.add( file ); multipartFiles.put( "import_file", fileItems ); Map<String, String [ ]> parameters = request.getParameterMap( ); MultipartHttpServletRequest multipartRequest = new MultipartHttpServletRequest( request, multipartFiles, parameters ); bean.getImportUsersFromFile( request ); // initialize _importAdminUserService AdminUser importedUser = null; try { bean.doImportUsersFromFile( multipartRequest ); fail( "Should have thrown" ); } catch( AccessDeniedException e ) { importedUser = AdminUserHome.findUserByLogin( "test" ); assertNull( importedUser ); } finally { if ( importedUser != null ) { disposeOfUser( importedUser ); } disposeOfUser( user ); } }
Example #7
Source File: CommonsMultipartFile.java From spring4-understanding with Apache License 2.0 | 5 votes |
/** * Return a description for the storage location of the multipart content. * Tries to be as specific as possible: mentions the file location in case * of a temporary file. */ public String getStorageDescription() { if (this.fileItem.isInMemory()) { return "in memory"; } else if (this.fileItem instanceof DiskFileItem) { return "at [" + ((DiskFileItem) this.fileItem).getStoreLocation().getAbsolutePath() + "]"; } else { return "on disk"; } }
Example #8
Source File: CommonsMultipartFile.java From spring-analysis-note with MIT License | 5 votes |
/** * Determine whether the multipart content is still available. * If a temporary file has been moved, the content is no longer available. */ protected boolean isAvailable() { // If in memory, it's available. if (this.fileItem.isInMemory()) { return true; } // Check actual existence of temporary file. if (this.fileItem instanceof DiskFileItem) { return ((DiskFileItem) this.fileItem).getStoreLocation().exists(); } // Check whether current file size is different than original one. return (this.fileItem.getSize() == this.size); }
Example #9
Source File: FileUpload1.java From ysoserial with MIT License | 5 votes |
private static DiskFileItem makePayload ( int thresh, String repoPath, String filePath, byte[] data ) throws IOException, Exception { // if thresh < written length, delete outputFile after copying to repository temp file // otherwise write the contents to repository temp file File repository = new File(repoPath); DiskFileItem diskFileItem = new DiskFileItem("test", "application/octet-stream", false, "test", 100000, repository); File outputFile = new File(filePath); DeferredFileOutputStream dfos = new DeferredFileOutputStream(thresh, outputFile); OutputStream os = (OutputStream) Reflections.getFieldValue(dfos, "memoryOutputStream"); os.write(data); Reflections.getField(ThresholdingOutputStream.class, "written").set(dfos, data.length); Reflections.setFieldValue(diskFileItem, "dfos", dfos); Reflections.setFieldValue(diskFileItem, "sizeThreshold", 0); return diskFileItem; }
Example #10
Source File: SecurityUIUtil.java From carbon-identity with Apache License 2.0 | 5 votes |
public static String getTextParameter(DiskFileItem diskFileItem, String characterEncoding) throws Exception { String encoding = diskFileItem.getCharSet(); if (encoding == null) { encoding = characterEncoding; } String textValue; if (encoding == null) { textValue = new String(diskFileItem.get()); } else { textValue = new String(diskFileItem.get(), encoding); } return textValue; }
Example #11
Source File: AdminUserJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testDoImportUsersFromFile( ) throws AccessDeniedException, UserNotSignedException, IOException { AdminUserJspBean bean = new AdminUserJspBean( ); MockHttpServletRequest request = new MockHttpServletRequest( ); request.addParameter( SecurityTokenService.PARAMETER_TOKEN, SecurityTokenService.getInstance( ).getToken( request, "jsp/admin/user/ImportUser.jsp" ) ); AdminUser user = getUserToModify( ); AdminAuthenticationService.getInstance( ).registerUser( request, user ); bean.init( request, "CORE_USERS_MANAGEMENT" ); Map<String, List<FileItem>> multipartFiles = new HashMap<>( ); List<FileItem> fileItems = new ArrayList<>( ); FileItem file = new DiskFileItem( "import_file", "application/csv", true, "junit.csv", 1024, new File( System.getProperty( "java.io.tmpdir" ) ) ); OutputStreamWriter writer = new OutputStreamWriter( file.getOutputStream( ), Charset.forName( "UTF-8" ) ); writer.write( "test;test;test;[email protected];" + AdminUser.ACTIVE_CODE + ";" + Locale.FRANCE + ";0;false;false;;;" ); writer.close( ); fileItems.add( file ); multipartFiles.put( "import_file", fileItems ); Map<String, String [ ]> parameters = request.getParameterMap( ); MultipartHttpServletRequest multipartRequest = new MultipartHttpServletRequest( request, multipartFiles, parameters ); bean.getImportUsersFromFile( request ); // initialize _importAdminUserService AdminUser importedUser = null; try { bean.doImportUsersFromFile( multipartRequest ); importedUser = AdminUserHome.findUserByLogin( "test" ); assertNotNull( importedUser ); assertEquals( "test", importedUser.getAccessCode( ) ); assertEquals( "test", importedUser.getFirstName( ) ); assertEquals( "test", importedUser.getLastName( ) ); assertEquals( "[email protected]", importedUser.getEmail( ) ); assertEquals( AdminUser.ACTIVE_CODE, importedUser.getStatus( ) ); } finally { if ( importedUser != null ) { disposeOfUser( importedUser ); } disposeOfUser( user ); } }
Example #12
Source File: AdminUserJspBeanTest.java From lutece-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void testDoImportUsersFromFileInvalidToken( ) throws AccessDeniedException, UserNotSignedException, IOException { AdminUserJspBean bean = new AdminUserJspBean( ); MockHttpServletRequest request = new MockHttpServletRequest( ); request.addParameter( SecurityTokenService.PARAMETER_TOKEN, SecurityTokenService.getInstance( ).getToken( request, "jsp/admin/user/ImportUser.jsp" ) + "b" ); AdminUser user = getUserToModify( ); AdminAuthenticationService.getInstance( ).registerUser( request, user ); bean.init( request, "CORE_USERS_MANAGEMENT" ); Map<String, List<FileItem>> multipartFiles = new HashMap<>( ); List<FileItem> fileItems = new ArrayList<>( ); FileItem file = new DiskFileItem( "import_file", "application/csv", true, "junit.csv", 1024, new File( System.getProperty( "java.io.tmpdir" ) ) ); OutputStreamWriter writer = new OutputStreamWriter( file.getOutputStream( ), Charset.forName( "UTF-8" ) ); writer.write( "test;test;test;[email protected];" + AdminUser.ACTIVE_CODE + ";" + Locale.FRANCE + ";0;false;false;;;" ); writer.close( ); fileItems.add( file ); multipartFiles.put( "import_file", fileItems ); Map<String, String [ ]> parameters = request.getParameterMap( ); MultipartHttpServletRequest multipartRequest = new MultipartHttpServletRequest( request, multipartFiles, parameters ); bean.getImportUsersFromFile( request ); // initialize _importAdminUserService AdminUser importedUser = null; try { bean.doImportUsersFromFile( multipartRequest ); fail( "Should have thrown" ); } catch( AccessDeniedException e ) { importedUser = AdminUserHome.findUserByLogin( "test" ); assertNull( importedUser ); } finally { if ( importedUser != null ) { disposeOfUser( importedUser ); } disposeOfUser( user ); } }
Example #13
Source File: PopupForm.java From sakai with Educational Community License v2.0 | 5 votes |
private PopupForm(String uuid, String descriptor, long startTime, long endTime, boolean isOpenCampaign, List<String> assignToEids, Optional<DiskFileItem> templateItem) { this.uuid = uuid; this.descriptor = descriptor; this.startTime = startTime; this.endTime = endTime; this.isOpenCampaign = isOpenCampaign; this.assignToEids = assignToEids; this.templateItem = templateItem; }
Example #14
Source File: ApacheMultipartParser.java From restcommander with Apache License 2.0 | 5 votes |
/** * Returns an identifier that is unique within the class loader used to * load this class, but does not have random-like apearance. * * @return A String with the non-random looking instance identifier. */ private static String getUniqueId() { int current; synchronized (DiskFileItem.class) { current = counter++; } String id = Integer.toString(current); // If you manage to get more than 100 million of ids, you'll // start getting ids longer than 8 characters. if (current < 100000000) { id = ("00000000" + id).substring(id.length()); } return id; }
Example #15
Source File: PopupForm.java From sakai with Educational Community License v2.0 | 5 votes |
private PopupForm(String uuid, String descriptor, long startTime, long endTime, boolean isOpenCampaign, List<String> assignToEids, Optional<DiskFileItem> templateItem) { this.uuid = uuid; this.descriptor = descriptor; this.startTime = startTime; this.endTime = endTime; this.isOpenCampaign = isOpenCampaign; this.assignToEids = assignToEids; this.templateItem = templateItem; }
Example #16
Source File: CommonsFileUploadPart.java From tomee with Apache License 2.0 | 5 votes |
@Override public Collection<String> getHeaderNames() { if (fileItem instanceof DiskFileItem) { final Set<String> headerNames = new LinkedHashSet<>(); final Iterator<String> iter = fileItem.getHeaders().getHeaderNames(); while (iter.hasNext()) { headerNames.add(iter.next()); } return headerNames; } return Collections.emptyList(); }
Example #17
Source File: ImportWizardControllerTest.java From molgenis with GNU Lesser General Public License v3.0 | 5 votes |
private MultipartFile createMultipartFile(String filename) throws IOException { File file = new File("/src/test/resources/" + filename); DiskFileItem fileItem = new DiskFileItem( "file", "text/plain", false, file.getName(), (int) file.length(), file.getParentFile()); fileItem.getOutputStream(); return new CommonsMultipartFile(fileItem); }
Example #18
Source File: TestProcessCreateRequest.java From metalcon with GNU General Public License v3.0 | 5 votes |
@Test public void testFullFormWithImageTooWide() throws Exception { // FIXME imageFileItem does not get any data File image = new File("testImage_tooWide.jpg"); if (image.length() > 0) { FileItem imageFileItem = new DiskFileItem("image", "image/JPEG", true, "file", 50000, null); // imageFileItem = image.toFileItem(); ProcessCreateResponse testResponse = this .processTestRequest( ProtocolTestConstants.VALID_SUGGESTION_KEY, ProtocolTestConstants.VALID_SUGGESTION_STRING, ProtocolTestConstants.VALID_SUGGESTION_WEIGHT, ProtocolTestConstants.VALID_SUGGESTION_INDEX, imageFileItem); // TODO: Insert Assertion System.out.println(testResponse.getContainer().getComponents() .getImageBase64()); } else { fail("no image to test with provided!"); } }
Example #19
Source File: TestProcessCreateRequest.java From metalcon with GNU General Public License v3.0 | 5 votes |
@Test public void testFullFormWithImageTooHigh() throws Exception { // FIXME imageFileItem does not get any data File image = new File("testImage_tooHigh.jpg"); if (image.length() > 0) { FileItem imageFileItem = new DiskFileItem("image", "image/JPEG", true, "file", 50000, null); // imageFileItem = image.toFileItem(); ProcessCreateResponse testResponse = this .processTestRequest( ProtocolTestConstants.VALID_SUGGESTION_KEY, ProtocolTestConstants.VALID_SUGGESTION_STRING, ProtocolTestConstants.VALID_SUGGESTION_WEIGHT, ProtocolTestConstants.VALID_SUGGESTION_INDEX, imageFileItem); // TODO: Insert Assertion System.out.println(testResponse.getContainer().getComponents() .getImageBase64()); } else { fail("no image to test with provided!"); } }
Example #20
Source File: TestProcessCreateRequest.java From metalcon with GNU General Public License v3.0 | 5 votes |
@Test public void testFullFormWithImageWrongType() throws Exception { // FIXME imageFileItem does not get any data File image = new File("testImage_wrongType.png"); if (image.length() > 0) { FileItem imageFileItem = new DiskFileItem("image", "image/JPEG", true, "file", 50000, null); // imageFileItem = image.toFileItem(); ProcessCreateResponse testResponse = this .processTestRequest( ProtocolTestConstants.VALID_SUGGESTION_KEY, ProtocolTestConstants.VALID_SUGGESTION_STRING, ProtocolTestConstants.VALID_SUGGESTION_WEIGHT, ProtocolTestConstants.VALID_SUGGESTION_INDEX, imageFileItem); // TODO: Insert Assertion System.out.println(testResponse.getContainer().getComponents() .getImageBase64()); } else { fail("no image to test with provided!"); } }
Example #21
Source File: CommonsMultipartFile.java From spring-analysis-note with MIT License | 5 votes |
/** * Return a description for the storage location of the multipart content. * Tries to be as specific as possible: mentions the file location in case * of a temporary file. */ public String getStorageDescription() { if (this.fileItem.isInMemory()) { return "in memory"; } else if (this.fileItem instanceof DiskFileItem) { return "at [" + ((DiskFileItem) this.fileItem).getStoreLocation().getAbsolutePath() + "]"; } else { return "on disk"; } }
Example #22
Source File: CommonsMultipartFile.java From java-technology-stack with MIT License | 5 votes |
/** * Determine whether the multipart content is still available. * If a temporary file has been moved, the content is no longer available. */ protected boolean isAvailable() { // If in memory, it's available. if (this.fileItem.isInMemory()) { return true; } // Check actual existence of temporary file. if (this.fileItem instanceof DiskFileItem) { return ((DiskFileItem) this.fileItem).getStoreLocation().exists(); } // Check whether current file size is different than original one. return (this.fileItem.getSize() == this.size); }
Example #23
Source File: SecurityUIUtil.java From carbon-identity-framework with Apache License 2.0 | 5 votes |
public static String getTextParameter(DiskFileItem diskFileItem, String characterEncoding) throws Exception { String encoding = diskFileItem.getCharSet(); if (encoding == null) { encoding = characterEncoding; } String textValue; if (encoding == null) { textValue = new String(diskFileItem.get(), StandardCharsets.UTF_8); } else { textValue = new String(diskFileItem.get(), encoding); } return textValue; }
Example #24
Source File: StandardMultipartFile.java From AndServer with Apache License 2.0 | 5 votes |
/** * Determine whether the multipart content is still available. If a temporary file has been moved, the content is no * longer available. */ protected boolean isAvailable() { // If in memory, it's available. if (fileItem.isInMemory()) { return true; } // Check actual existence of temporary file. if (fileItem instanceof DiskFileItem) { return ((DiskFileItem) fileItem).getStoreLocation().exists(); } // Check whether current file size is different than original one. return (fileItem.getSize() == size); }
Example #25
Source File: CommonsMultipartFile.java From validator-web with Apache License 2.0 | 5 votes |
/** * Return a description for the storage location of the multipart content. * Tries to be as specific as possible: mentions the file location in case * of a temporary file. */ public String getStorageDescription() { if (this.fileItem.isInMemory()) { return "in memory"; } else if (this.fileItem instanceof DiskFileItem) { return "at [" + ((DiskFileItem) this.fileItem).getStoreLocation().getAbsolutePath() + "]"; } else { return "on disk"; } }
Example #26
Source File: CommonsMultipartFile.java From java-technology-stack with MIT License | 5 votes |
/** * Return a description for the storage location of the multipart content. * Tries to be as specific as possible: mentions the file location in case * of a temporary file. */ public String getStorageDescription() { if (this.fileItem.isInMemory()) { return "in memory"; } else if (this.fileItem instanceof DiskFileItem) { return "at [" + ((DiskFileItem) this.fileItem).getStoreLocation().getAbsolutePath() + "]"; } else { return "on disk"; } }
Example #27
Source File: ApacheMultiPartTest.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test delete method. * * @throws Exception when a serious error occurs. */ @Test public void testDelete() throws Exception { File file = new File("delete.me"); file.createNewFile(); assertTrue(file.exists()); FileItem item = new DiskFileItem("fieldName", "text/html", false, "delete.me", 0, file); ApacheMultiPart part = new ApacheMultiPart(item); part.delete(); file.delete(); }
Example #28
Source File: ApacheMultiPartTest.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Test getContentType method. * * @throws Exception when a serious error occurs. */ @Test public void testGetContentType() throws Exception { File file = new File("delete.me"); file.createNewFile(); assertTrue(file.exists()); FileItem item = new DiskFileItem("fieldName", "text/html", false, "delete.me", 0, file); ApacheMultiPart part = new ApacheMultiPart(item); assertEquals(part.getContentType(), "text/html"); file.delete(); }
Example #29
Source File: CommonsMultipartFile.java From validator-web with Apache License 2.0 | 5 votes |
/** * Determine whether the multipart content is still available. * If a temporary file has been moved, the content is no longer available. */ protected boolean isAvailable() { // If in memory, it's available. if (this.fileItem.isInMemory()) { return true; } // Check actual existence of temporary file. if (this.fileItem instanceof DiskFileItem) { return ((DiskFileItem) this.fileItem).getStoreLocation().exists(); } // Check whether current file size is different than original one. return (this.fileItem.getSize() == this.size); }
Example #30
Source File: FileUpload1.java From ysoserial-modified with MIT License | 5 votes |
private static DiskFileItem makePayload ( int thresh, String repoPath, String filePath, byte[] data ) throws IOException, Exception { // if thresh < written length, delete outputFile after copying to repository temp file // otherwise write the contents to repository temp file File repository = new File(repoPath); DiskFileItem diskFileItem = new DiskFileItem("test", "application/octet-stream", false, "test", 100000, repository); File outputFile = new File(filePath); DeferredFileOutputStream dfos = new DeferredFileOutputStream(thresh, outputFile); OutputStream os = (OutputStream) Reflections.getFieldValue(dfos, "memoryOutputStream"); os.write(data); Reflections.getField(ThresholdingOutputStream.class, "written").set(dfos, data.length); Reflections.setFieldValue(diskFileItem, "dfos", dfos); Reflections.setFieldValue(diskFileItem, "sizeThreshold", 0); return diskFileItem; }