You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by as...@apache.org on 2009/05/24 19:53:26 UTC

svn commit: r778199 - /httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java

Author: asankha
Date: Sun May 24 17:53:26 2009
New Revision: 778199

URL: http://svn.apache.org/viewvc?rev=778199&view=rev
Log:
fix the sample to adhere to the way it seems to illustrate how to save an enclosed entity to a file for a PUT, POST method etc, and how to serve a file for a GET etc

Modified:
    httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java

Modified: httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java
URL: http://svn.apache.org/viewvc/httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java?rev=778199&r1=778198&r2=778199&view=diff
==============================================================================
--- httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java (original)
+++ httpcomponents/httpcore/trunk/httpcore-nio/src/examples/org/apache/http/examples/nio/NHttpFileServer.java Sun May 24 17:53:26 2009
@@ -30,10 +30,7 @@
  */
 package org.apache.http.examples.nio;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InterruptedIOException;
+import java.io.*;
 import java.net.InetSocketAddress;
 import java.net.URLDecoder;
 import java.nio.channels.FileChannel;
@@ -200,15 +197,15 @@
 
     static class FileWriteListener implements ContentListener {
         private final File file;
-        private final FileInputStream inputFile;
+        private final FileOutputStream outputFile;
         private final FileChannel fileChannel;
         private final boolean useFileChannels;
         private long idx = 0;
 
         public FileWriteListener(boolean useFileChannels) throws IOException {
             this.file = File.createTempFile("tmp", ".tmp", null);
-            this.inputFile = new FileInputStream(file);
-            this.fileChannel = inputFile.getChannel();
+            this.outputFile = new FileOutputStream(file, true);
+            this.fileChannel = outputFile.getChannel();
             this.useFileChannels = useFileChannels;
         }
 
@@ -229,7 +226,7 @@
 
         public void finished() {
             try {
-                inputFile.close();
+                outputFile.close();
             } catch(IOException ignored) {}
             try {
                 fileChannel.close();