You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2012/06/22 10:22:27 UTC
svn commit: r1352797 -
/chemistry/site/trunk/content/java/developing/guide.mdtext
Author: fmui
Date: Fri Jun 22 08:22:26 2012
New Revision: 1352797
URL: http://svn.apache.org/viewvc?rev=1352797&view=rev
Log:
Fixed sample code
Modified:
chemistry/site/trunk/content/java/developing/guide.mdtext
Modified: chemistry/site/trunk/content/java/developing/guide.mdtext
URL: http://svn.apache.org/viewvc/chemistry/site/trunk/content/java/developing/guide.mdtext?rev=1352797&r1=1352796&r2=1352797&view=diff
==============================================================================
--- chemistry/site/trunk/content/java/developing/guide.mdtext (original)
+++ chemistry/site/trunk/content/java/developing/guide.mdtext Fri Jun 22 08:22:26 2012
@@ -377,18 +377,25 @@ The following code snippet retrieves the
* @throws IOException
*/
private static String getContentAsString(ContentStream stream) throws IOException {
- InputStream in2 = stream.getStream();
- StringBuffer sbuf = null;
- sbuf = new StringBuffer(in2.available());
- int count;
- byte[] buf2 = new byte[100];
- while ((count = in2.read(buf2)) != -1) {
- for (int i = 0; i < count; i++) {
- sbuf.append((char) buf2[i]);
+ StringBuilder sb = new StringBuilder();
+ Reader reader = new InputStreamReader(stream.getStream(), "UTF-8");
+
+ try {
+ final char[] buffer = new char[4 * 1024];
+ int b;
+ while (true) {
+ b = reader.read(buffer, 0, buffer.length);
+ if (b > 0) {
+ sb.append(buffer, 0, b);
+ } else if (b == -1) {
+ break;
+ }
}
+ } finally {
+ reader.close();
}
- in2.close();
- return sbuf.toString();
+
+ return sb.toString();
}
The following code snippet retrieves the newly created object using a path:-