commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Jakarta-commons Wiki] Update of "Net/FrequentlyAskedQuestions" by dgsoft
Date Mon, 08 Jan 2007 16:32:29 GMT
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


Mime
View raw message