Possible duplicate:
How to make a deep copy of InputStream in Java?
I have an InputStream object and I want to make a copy of it. What is the best way to do this?
The data does not come from the file, but as the payload of the http form sent from the web page, I use the Apache Commons FileUpload library, my code that InputStream gives me looks like this: ...
InputStream imageStream = null; boolean isMultipart = ServletFileUpload.isMultipartContent(request); FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List items = new ArrayList(); items = upload.parseRequest(request); Iterator iter = items.iterator(); while (iter.hasNext()) { FileItem item = (FileItem) iter.next(); if (item.isFormField()) { // this is subject Id if (item.getFieldName().equals("subId")) { subId = Integer.parseInt(item.getString()); System.out.println("SubId: " + subId); } } else { imageStream = item.getInputStream(); } }
What is the best way to get duplicate / copy of imageStream?
java inputstream copy
Ankur
source share