/** * Create an instance wrapping the given FileItem. * @param fileItem the FileItem to wrap */ public CommonsMultipartFile(FileItem fileItem) { this.fileItem = fileItem; this.size = this.fileItem.getSize(); }
/** * Create an instance wrapping the given FileItem. * @param fileItem the FileItem to wrap */ public CommonsMultipartFile(FileItem fileItem) { this.fileItem = fileItem; this.size = this.fileItem.getSize(); }
@Override public long getSize() { return item.getSize(); }
@Override public long getSize() { return fileItem.getSize(); }
/** * 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); }
/** * 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); }
assertEquals("logo.jpg", item.getName()); assertEquals("image/jpeg", item.getContentType()); assertEquals(logo.getFile().length(), item.getSize()); assertEquals("Hall\u00F6le.jpg", item.getName()); assertEquals("image/jpeg", item.getContentType()); assertEquals(logo.getFile().length(), item.getSize());
/** * Create an instance wrapping the given FileItem. * * @param fileItem the FileItem to wrap. */ public StandardMultipartFile(FileItem fileItem) { this.fileItem = fileItem; this.size = fileItem.getSize(); }
@Override public long getSize() { return fileItem.getSize(); } }
public long length() { return item.getSize(); }
/** * Helper method to test creation of a field when a repository is used. */ public void testInMemoryObject(byte[] testFieldValueBytes, File repository) { FileItem item = createFileItem(testFieldValueBytes, repository); // Check state is as expected assertTrue("Initial: in memory", item.isInMemory()); assertEquals("Initial: size", item.getSize(), testFieldValueBytes.length); compareBytes("Initial", item.get(), testFieldValueBytes); item.delete(); }
/** * Test creation of a field for which the amount of data falls below the * configured threshold. */ @Test public void testBelowThreshold() { FileItemFactory factory = createFactory(null); String textFieldName = "textField"; String textFieldValue = "0123456789"; byte[] testFieldValueBytes = textFieldValue.getBytes(); FileItem item = factory.createItem( textFieldName, textContentType, true, null ); assertNotNull(item); try { OutputStream os = item.getOutputStream(); os.write(testFieldValueBytes); os.close(); } catch(IOException e) { fail("Unexpected IOException"); } assertTrue(item.isInMemory()); assertEquals(item.getSize(), testFieldValueBytes.length); assertTrue(Arrays.equals(item.get(), testFieldValueBytes)); assertEquals(item.getString(), textFieldValue); }
assertEquals(item.getSize(), testFieldValueBytes.length); assertTrue(Arrays.equals(item.get(), testFieldValueBytes)); assertEquals(item.getString(), textFieldValue);
/** * Test creation of a field for which the amount of data falls above the * configured threshold. */ @Test public void testAboveThreshold() { // Create the FileItem byte[] testFieldValueBytes = createContentBytes(threshold + 1); FileItem item = createFileItem(testFieldValueBytes); // Check state is as expected assertFalse("Initial: in memory", item.isInMemory()); assertEquals("Initial: size", item.getSize(), testFieldValueBytes.length); compareBytes("Initial", item.get(), testFieldValueBytes); item.delete(); }
/** * 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); } }
/** * 添加<code>FileItem</code>。 * * @param key 参数名 * @param value 参数值 */ public void add(String key, FileItem value) { if (value.isFormField()) { add(key, value.getString()); } else { // 忽略空的上传项。 if (!StringUtil.isEmpty(value.getName()) || value.getSize() > 0) { add(key, (Object) value); } } }
/** * 添加<code>FileItem</code>。 * * @param key 参数名 * @param value 参数值 */ public void add(String key, FileItem value) { if (value.isFormField()) { add(key, value.getString()); } else { // 忽略空的上传项。 if (!StringUtil.isEmpty(value.getName()) || value.getSize() > 0) { add(key, (Object) value); } } }
newPart.setSubmittedFileName(item.getFieldName()); newPart.setContentType(item.getContentType()); newPart.setSize(item.getSize()); item.getHeaders().getHeaderNames().forEachRemaining(h -> { newPart.addHeader(h, item.getHeaders().getHeader(h));