You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by eh...@apache.org on 2007/03/19 04:06:09 UTC
svn commit: r519809 -
/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/upload/FileUpload.java
Author: ehillenius
Date: Sun Mar 18 20:06:08 2007
New Revision: 519809
URL: http://svn.apache.org/viewvc?view=rev&rev=519809
Log:
made item private and removed deprecated method that's been there forever
Modified:
incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/upload/FileUpload.java
Modified: incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/upload/FileUpload.java
URL: http://svn.apache.org/viewvc/incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/upload/FileUpload.java?view=diff&rev=519809&r1=519808&r2=519809
==============================================================================
--- incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/upload/FileUpload.java (original)
+++ incubator/wicket/branches/wicket-1.x/jdk-1.4/wicket/src/main/java/wicket/markup/html/form/upload/FileUpload.java Sun Mar 18 20:06:08 2007
@@ -37,9 +37,9 @@
{
private static final long serialVersionUID = 1L;
- final FileItem item;
-
- private List/*<InputStream>*/ inputStreams;
+ private final FileItem item;
+
+ private List/* <InputStream> */inputStreams;
/**
* Constructor
@@ -53,37 +53,52 @@
}
/**
- * Deletes temp file from disk
+ * Close the streams which has been opened when getting the InputStream
+ * using {@link #getInputStream()}. All the input streams are closed at the
+ * end of the request. This is done when the FileUploadField, which is
+ * associated with this FileUpload is detached.
+ * <p>
+ * If an exception is thrown when closing the input streams, we ignore it,
+ * because the stream might have been closed already.
*/
- public void delete()
+ public final void closeStreams()
{
- item.delete();
- }
+ if (inputStreams != null)
+ {
+ for (Iterator inputStreamsIterator = inputStreams.iterator(); inputStreamsIterator
+ .hasNext();)
+ {
+ InputStream inputStream = (InputStream)inputStreamsIterator.next();
- /**
- * @return Uploaded file as an array of bytes
- */
- public byte[] getBytes()
- {
- return item.get();
+ try
+ {
+ inputStream.close();
+ }
+ catch (IOException e)
+ {
+ // We don't care aobut the exceptions thrown here.
+ }
+ }
+
+ // Reset the list
+ inputStreams = null;
+ }
}
/**
- * @return Content type for upload
+ * Deletes temp file from disk
*/
- public String getContentType()
+ public void delete()
{
- return item.getContentType();
+ item.delete();
}
/**
- * @return File object for client-side file that was uploaded.
- * @deprecated - this method was very counterintuitive. its been replaced by
- * getClientFileName(). see bug 1372481.
+ * @return Uploaded file as an array of bytes
*/
- public File getFile()
+ public byte[] getBytes()
{
- return new File(item.getName());
+ return item.get();
}
/**
@@ -95,6 +110,13 @@
return item.getName();
}
+ /**
+ * @return Content type for upload
+ */
+ public String getContentType()
+ {
+ return item.getContentType();
+ }
/**
* Get an input stream for the file uploaded. Use this input stream if you
@@ -103,21 +125,23 @@
* persist it elsewhere, i.e. a database or external filesystem.
* <p>
* <b>PLEASE NOTE!</b><br>
- * The InputStream return will be closed be Wicket at the end of the request.
- * If you need it across a request you need to hold on to this FileUpload
- * instead.
+ * The InputStream return will be closed be Wicket at the end of the
+ * request. If you need it across a request you need to hold on to this
+ * FileUpload instead.
+ *
* @return Input stream with file contents.
* @throws IOException
*/
public InputStream getInputStream() throws IOException
{
- if (inputStreams == null) {
- inputStreams = new ArrayList/*<InputStream>*/();
+ if (inputStreams == null)
+ {
+ inputStreams = new ArrayList/* <InputStream> */();
}
-
+
InputStream is = item.getInputStream();
inputStreams.add(is);
-
+
return is;
}
@@ -166,37 +190,5 @@
File temp = File.createTempFile(Session.get().getId(), item.getFieldName());
writeTo(temp);
return temp;
- }
-
- /**
- * Close the streams which has been opened when getting the InputStream
- * using {@link #getInputStream()}. All the input streams are closed at the
- * end of the request. This is done when the FileUploadField, which is
- * associated with this FileUpload is detached.
- * <p>
- * If an exception is thrown when closing the input streams, we ignore it,
- * because the stream might have been closed already.
- */
- public final void closeStreams()
- {
- if (inputStreams != null)
- {
- for (Iterator inputStreamsIterator = inputStreams.iterator(); inputStreamsIterator.hasNext();)
- {
- InputStream inputStream = (InputStream)inputStreamsIterator.next();
-
- try
- {
- inputStream.close();
- }
- catch (IOException e)
- {
- // We don't care aobut the exceptions thrown here.
- }
- }
-
- // Reset the list
- inputStreams = null;
- }
}
}