You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Apache Wiki <wi...@apache.org> on 2007/01/08 17:32:29 UTC

[Jakarta-commons Wiki] Update of "Net/FrequentlyAskedQuestions" by dgsoft

Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Jakarta-commons Wiki" for change notification.

The following page has been changed by dgsoft:
http://wiki.apache.org/jakarta-commons/Net/FrequentlyAskedQuestions

The comment on the change is:
old code always transfers the whole buffer even if less bytes are read

------------------------------------------------------------------------------
  		InputStream fis = new FileInputStream("c:\\temp\\B.pdf");
  		OutputStream os = client.storeFileStream("B.pdf");
  		
- 		byte buf[] = new byte[8192];
+                 byte buf[] = new byte[8192];
- 		while (fis.read(buf) != -1) {
- 			os.write(buf);
- 		}
+                 int bytesRead = fis.read(buf);
+                 while (bytesRead != -1) {
+                     os.write(buf, 0, bytesRead);
+                     bytesRead = fis.read(buf);
+                 }
  		fis.close();
  		os.close();
  		client.completePendingCommand();

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org