/** * Create a FileItem with the specfied content bytes and repository. */ private FileItem createFileItem(byte[] contentBytes, File repository) { FileItemFactory factory = new DiskFileItemFactory(threshold, repository); String textFieldName = "textField"; FileItem item = factory.createItem( textFieldName, textContentType, true, "My File Name" ); try { OutputStream os = item.getOutputStream(); os.write(contentBytes); os.close(); } catch(IOException e) { fail("Unexpected IOException" + e); } return item; }
items.add(fileItem); try { Streams.copy(item.openStream(), fileItem.getOutputStream(), true); } catch (FileUploadIOException e) { throw (FileUploadException) e.getCause();
true, null); OutputStream outstream = item.getOutputStream(); for (int element : SWISS_GERMAN_STUFF_ISO8859_1) { outstream.write(element); true, null); outstream = item.getOutputStream(); for (int element : SWISS_GERMAN_STUFF_UTF8) { outstream.write(element); true, null); outstream = item.getOutputStream(); for (int element : RUSSIAN_STUFF_KOI8R) { outstream.write(element); true, null); outstream = item.getOutputStream(); for (int element : RUSSIAN_STUFF_WIN1251) { outstream.write(element); true, null); outstream = item.getOutputStream(); for (int element : RUSSIAN_STUFF_UTF8) { outstream.write(element);
/** * 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); }
OutputStream os = item.getOutputStream(); os.write(testFieldValueBytes); os.close();
/** * {@inheritDoc} */ @Override public OutputStream getOutputStream( ) throws IOException { return _item.getOutputStream( ); }
@Override public OutputStream getOutputStream() throws IOException { return item.getOutputStream(); }
@Override public OutputStream getOutputStream() throws IOException { if (this.__isFileObj) { return new FileOutputStream(__fileObj); } return __fileItemObj.getOutputStream(); }
public OutputStream getOutputStream() { try { return wrapped.getOutputStream(); } catch (IOException ex) { throw new RuntimeException(ex); } }
@Override public OutputStream getOutputStream() { try { return file.getOutputStream(); } catch(final IOException ex) { throw new RuntimeException(ex); } }
public OutputStream getOutputStream() { try { return wrapped.getOutputStream(); } catch (IOException ex) { throw new RuntimeException(ex); } }
/** * @return 获取文件输出流对象 * @throws IOException */ public OutputStream getOutputStream() throws IOException { if (this.__isFileObj) { if (this.__fileObj == null) { throw new IOException("Cannot get output stream, file object was null!"); } return new FileOutputStream(this.__fileObj); } return __fileItemObj.getOutputStream(); }
/** * Right now, using the same approach present in upload attachments to create the attachment */ private static FileItem createPreferencesFileItem(InputStream is, String filename, String contentType) throws IOException { FileItemFactory f = new DiskFileItemFactory(); FileItem item = f.createItem(filename, contentType, false, filename); UploadServlet.copyFromInputStreamToOutputStream(is, item.getOutputStream()); return item; }
OutputStream outputStream = fileItem.getOutputStream(); // Last step is to get FileItem's output stream, and write your inputStream in it. This is the way to write to your FileItem.
/** * Set the content of the attachment from an InputStream. * * @param is the input stream that will be read * @throws IOException when an error occurs during streaming operation * @since 2.6M1 */ public void setContent(InputStream is) throws IOException { this.newFileItem(); IOUtils.copy(is, this.file.getOutputStream()); this.setContentDirty(true); this.attachment.setFilesize(this.getSize()); }
try { try { Streams.copy(item.openStream(), fileItem.getOutputStream(), true); } catch (FileUploadIOException e) { throw (FileUploadException) e.getCause();
items.add(fileItem); try { Streams.copy(item.openStream(), fileItem.getOutputStream(), true); } catch (FileUploadIOException e) { throw (FileUploadException) e.getCause();
item.getName()); try { Streams.copy(item.openStream(), fileItem.getOutputStream(), true); } catch (FileUploadIOException e) {
items.add(fileItem); try { Streams.copy(item.openStream(), fileItem.getOutputStream(), true); } catch (FileUploadIOException e) { throw (FileUploadException) e.getCause();
.getOutputStream(), true); .getOutputStream(), true);