@Override public byte[] getContents() { return fileItem.get(); }
assertEquals("field1", item0.getFieldName()); assertNull(item0.getName()); assertEquals("Joe Blow", new String(item0.get())); FileItem item1 = fileItems.get(1); assertEquals("pics", item1.getFieldName()); assertEquals("file1.txt", item1.getName()); assertEquals("... contents of file1.txt ...", new String(item1.get())); FileItem item2 = fileItems.get(2); assertEquals("pics", item2.getFieldName()); assertEquals("file2.gif", item2.getName()); assertEquals("...contents of file2.gif...", new String(item2.get()));
byte[] bytes = item.get(); assertEquals(i, bytes.length); for (int j = 0; j < i; j++) {
for (FileItem item : items) { String fileName = FilenameUtils.getName(item.getName()); AwsProxyRequestPart newPart = new AwsProxyRequestPart(item.get()); newPart.setName(fileName); newPart.setSubmittedFileName(item.getFieldName());
/** * 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); }
/** * 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(); }
assertTrue(Arrays.equals(item.get(), testFieldValueBytes)); assertEquals(item.getString(), textFieldValue);
/** * Tests a file upload with varying file sizes. */ public void testFileUpload() throws IOException, FileUploadException { byte[] request = newRequest(); List<FileItem> fileItems = parseUpload(request); Iterator<FileItem> fileIter = fileItems.iterator(); int add = 16; int num = 0; for (int i = 0; i < 16384; i += add) { if (++add == 32) { add = 16; } FileItem item = fileIter.next(); assertEquals("field" + (num++), item.getFieldName()); byte[] bytes = item.get(); assertEquals(i, bytes.length); for (int j = 0; j < i; j++) { assertEquals((byte) j, bytes[j]); } } assertTrue(!fileIter.hasNext()); }
/** * 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(); }
@Override public byte[] getBytes() { if (!isAvailable()) { throw new IllegalStateException("File has been moved - cannot be read again"); } byte[] bytes = this.fileItem.get(); return (bytes != null ? bytes : new byte[0]); }
FileItem item = fileIter.next(); assertEquals("field", item.getFieldName()); byte[] bytes = item.get(); assertEquals(3, bytes.length); assertEquals((byte)'1', bytes[0]);
@Override public byte[] getBytes() { if (!isAvailable()) { throw new IllegalStateException("File has been moved - cannot be read again"); } byte[] bytes = this.fileItem.get(); return (bytes != null ? bytes : new byte[0]); }
@Override public byte[] getBytes() { if (!isAvailable()) { throw new IllegalStateException("File has been moved - cannot be read again."); } byte[] bytes = this.fileItem.get(); return (bytes != null ? bytes : new byte[0]); }
/** * @return Uploaded file as an array of bytes */ public byte[] getBytes() { return item.get(); }
/** * @return Uploaded file as an array of bytes */ public byte[] getBytes() { return item.get(); }
/** * @see org.opencms.ugc.I_CmsFormDataItem#getData() */ @Override public byte[] getData() { return m_fileItem.get(); }
/** * @return a byte array containing the binary content of the attachment. * @deprecated use {@link #getContentInputStream()} instead */ @Deprecated public byte[] getContent() { return this.file.get(); }
public byte[] getBytes() { if (!isAvailable()) { throw new IllegalStateException("File has been moved - cannot be read again"); } byte[] bytes = this.fileItem.get(); return (bytes != null ? bytes : new byte[0]); }