Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2007-05-24 17:18:58 +0000
committerrelves2007-05-24 17:18:58 +0000
commitb495ddb08dbfbe6c8a2f881fcd3735aaa34c7ec9 (patch)
tree0f30430a57eed472880447cbd3704fca9eff28f4 /org.eclipse.mylyn.bugzilla.core
parentdc84f15ee2e9c154796126943f6fa040c35cf9a9 (diff)
downloadorg.eclipse.mylyn.tasks-b495ddb08dbfbe6c8a2f881fcd3735aaa34c7ec9.tar.gz
org.eclipse.mylyn.tasks-b495ddb08dbfbe6c8a2f881fcd3735aaa34c7ec9.tar.xz
org.eclipse.mylyn.tasks-b495ddb08dbfbe6c8a2f881fcd3735aaa34c7ec9.zip
NEW - bug 187630: Refactor AbstractReportFactory to use stream filter
https://bugs.eclipse.org/bugs/show_bug.cgi?id=187630
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.core')
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/AbstractReportFactory.java71
1 files changed, 20 insertions, 51 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/AbstractReportFactory.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/AbstractReportFactory.java
index d00141082..1d38274b3 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/AbstractReportFactory.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/AbstractReportFactory.java
@@ -12,12 +12,11 @@
package org.eclipse.mylar.internal.bugzilla.core;
import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.io.StringReader;
import java.security.GeneralSecurityException;
@@ -57,18 +56,26 @@ public class AbstractReportFactory {
return;
}
- ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
-
- copyAndCleanByteStream(inStream, byteStream);
-
- BufferedReader in;
+ final BufferedInputStream is = new BufferedInputStream(inStream, 1024);
+
+ // Remove control characters other than \\n and \\r
+ InputStream iis = new InputStream() {
+ public int read() throws IOException {
+ int c;
+ while ((c = is.read()) != -1) {
+ if (!Character.isISOControl(c) || c == '\n' || c == '\r') {
+ return c;
+ }
+ }
+ return -1;
+ }
+ };
+
+ Reader in;
if (characterEncoding != null) {
- // in = new BufferedReader(new InputStreamReader(inStream,
- // characterEncoding));
- in = new BufferedReader(new StringReader(byteStream.toString(characterEncoding)));
+ in = new InputStreamReader(iis, characterEncoding);
} else {
- // in = new BufferedReader(new InputStreamReader(inStream));
- in = new BufferedReader(new StringReader(byteStream.toString()));
+ in = new InputStreamReader(iis);
}
if (in != null && clean) {
@@ -122,42 +129,4 @@ public class AbstractReportFactory {
}
}
- // Copy and remove control characters other than \n and \r
- private void copyAndCleanByteStream(InputStream in, OutputStream out) throws IOException {
- try {
- if (in != null && out != null) {
- BufferedInputStream inBuffered = new BufferedInputStream(in);
-
- int bufferSize = 1000;
- byte[] buffer = new byte[bufferSize];
-
- int readCount;
-
- BufferedOutputStream outStream = new BufferedOutputStream(out);
-
- while ((readCount = inBuffered.read(buffer)) != -1) {
- for (int x = 0; x < readCount; x++) {
-
- if (!Character.isISOControl(buffer[x])) {
- outStream.write(buffer[x]);
- } else if (buffer[x] == '\n' || buffer[x] == '\r') {
- outStream.write(buffer[x]);
- }
- }
- // if (readCount < bufferSize) {
- // outStream.write(buffer, 0, readCount);
- // } else {
- // outStream.write(buffer);
- // }
- }
- outStream.flush();
- outStream.close();
-
- }
- } finally {
- in.close();
- }
-
- }
-
}

Back to the top