diff options
author | relves | 2007-05-24 17:18:58 +0000 |
---|---|---|
committer | relves | 2007-05-24 17:18:58 +0000 |
commit | b495ddb08dbfbe6c8a2f881fcd3735aaa34c7ec9 (patch) | |
tree | 0f30430a57eed472880447cbd3704fca9eff28f4 | |
parent | dc84f15ee2e9c154796126943f6fa040c35cf9a9 (diff) | |
download | org.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
3 files changed, 52 insertions, 55 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(); - } - - } - } diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java index a818e0eae..8790e367e 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java @@ -49,7 +49,7 @@ import org.eclipse.mylar.tasks.ui.search.SearchHitCollector; * @author Nathan Hapke */ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest { - + public void testCreateTaskFromExistingId() throws Exception { init222(); try { @@ -631,6 +631,36 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest { private boolean validateAttachmentAttributes(RepositoryAttachment att, boolean isPatch, boolean isObsolete) { return (att.isPatch() == isPatch) && (att.isObsolete() == isObsolete); } + + +// public void testSimpleLoad() throws Exception { +// repository = new TaskRepository(DEFAULT_KIND, IBugzillaConstants.ECLIPSE_BUGZILLA_URL); +// //Credentials credentials = MylarTestUtils.readCredentials(); +// //repository.setAuthenticationCredentials(credentials.username, credentials.password); +// +// //repository.setTimeZoneId("Canada/Eastern"); +// assertNotNull(manager); +// manager.addRepository(repository, TasksUiPlugin.getDefault().getRepositoriesFilePath()); +// +// taskList = TasksUiPlugin.getTaskListManager().getTaskList(); +// +// AbstractRepositoryConnector abstractRepositoryConnector = manager.getRepositoryConnector(DEFAULT_KIND); +// +// assertEquals(abstractRepositoryConnector.getRepositoryType(), DEFAULT_KIND); +// +// connector = (BugzillaRepositoryConnector) abstractRepositoryConnector; +// +// long start = System.currentTimeMillis(); +// BugzillaTask task = null; +// for(int x = 1; x < 5; x++) { +// if(task != null) +// taskList.deleteTask(task); +// +// task = this.generateLocalTaskAndDownload("154100"); +// assertNotNull(task); +// } +// System.err.println("Total: "+((System.currentTimeMillis() - start)/1000)); +// } // class MockBugzillaReportSubmitForm extends BugzillaReportSubmitForm { // diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java index b4310ff5d..8259c858c 100644 --- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java +++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java @@ -239,9 +239,7 @@ public class DelegatingTaskExternalizer implements ITaskListExternalizer { StringBuilder builder = new StringBuilder(text.length()); for (int x = 0; x < text.length(); x++) { char temp = text.charAt(x); - if (!Character.isISOControl(temp)) { - builder.append(temp); - } else if (temp == '\n' || temp == '\r') { + if (!Character.isISOControl(temp) || temp == '\n' || temp == '\r') { builder.append(temp); } } |