/** * 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"; } }
/** * 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); }
/** * 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"; } }
/** * 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); }
LogFormatUtils.traceDebug(logger, traceOn -> { String action = "transferred"; if (!this.fileItem.isInMemory()) { action = (isAvailable() ? "copied" : "moved");
LogFormatUtils.traceDebug(logger, traceOn -> { String action = "transferred"; if (!this.fileItem.isInMemory()) { action = (isAvailable() ? "copied" : "moved");
/** * 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); }
fail("Unexpected IOException"); assertFalse(item.isInMemory()); assertEquals(item.getSize(), testFieldValueBytes.length); assertTrue(Arrays.equals(item.get(), testFieldValueBytes));
/** * 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); } }
/** * @since 3.0 */ public boolean isInMemory() { return _fileItem.isInMemory(); }
@Override public boolean isInMemory() { return fileItem.isInMemory(); } }
/** * @since 3.0 */ public boolean isInMemory() { return _fileItem.isInMemory(); }
@Override public boolean isInMemory() { return item.isInMemory(); }
/** * {@inheritDoc} */ @Override public boolean isInMemory( ) { return _item.isInMemory( ); }
@Override public boolean isInMemory() { return item.isInMemory(); }
@Override public boolean isInMemory() { return fileItem.isInMemory(); }
public File getStoreLocation() { if (fileItem.isInMemory()) { return null; } return ((DiskFileItem) fileItem).getStoreLocation(); }
@Test public void inMemoryIsFileItemInMemory() throws Exception { FileItem item = newMock(FileItem.class); UploadedFileItem uploadedFile = new UploadedFileItem(item); expect(item.isInMemory()).andReturn(true); replay(); assertTrue(uploadedFile.isInMemory()); verify(); }