Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsminto2009-08-17 16:59:07 +0000
committersminto2009-08-17 16:59:07 +0000
commitdb5a415abce55906ebc282a1825951a953b9ee92 (patch)
treec3ad5b38b44a1029d89ef90149f0006064d1a910 /org.eclipse.mylyn.monitor.usage
parent0f15f0060bb047d86cd673449632a795c48f744c (diff)
downloadorg.eclipse.mylyn.incubator-db5a415abce55906ebc282a1825951a953b9ee92.tar.gz
org.eclipse.mylyn.incubator-db5a415abce55906ebc282a1825951a953b9ee92.tar.xz
org.eclipse.mylyn.incubator-db5a415abce55906ebc282a1825951a953b9ee92.zip
RESOLVED - bug 286691: [usage]IProgressMonitor when reading interaction history from file
https://bugs.eclipse.org/bugs/show_bug.cgi?id=286691
Diffstat (limited to 'org.eclipse.mylyn.monitor.usage')
-rw-r--r--org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/InteractionEventLogger.java50
-rw-r--r--org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/Messages.java2
-rw-r--r--org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/messages.properties1
3 files changed, 47 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/InteractionEventLogger.java b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/InteractionEventLogger.java
index 88116cd9..f70c1d25 100644
--- a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/InteractionEventLogger.java
+++ b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/InteractionEventLogger.java
@@ -19,6 +19,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.StringReader;
+import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@@ -29,7 +30,9 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.commons.net.HtmlStreamTokenizer;
@@ -51,7 +54,7 @@ public class InteractionEventLogger extends AbstractMonitorLog implements IInter
private final InteractionEventObfuscator handleObfuscator = new InteractionEventObfuscator();
- private final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z", Locale.ENGLISH); //$NON-NLS-1$
+ private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z", Locale.ENGLISH); //$NON-NLS-1$
public InteractionEventLogger(File outputFile) {
this.outputFile = outputFile;
@@ -125,35 +128,64 @@ public class InteractionEventLogger extends AbstractMonitorLog implements IInter
}
public List<InteractionEvent> getHistoryFromFile(File file) {
+ return getHistoryFromFile(file, new NullProgressMonitor());
+ }
+
+ public List<InteractionEvent> getHistoryFromFile(File file, IProgressMonitor monitor) {
+
List<InteractionEvent> events = new ArrayList<InteractionEvent>();
+ InputStream inputStream = null;
+ long fileLength = 0;
+
try {
// The file may be a zip file...
if (file.getName().endsWith(".zip")) { //$NON-NLS-1$
ZipFile zip = new ZipFile(file);
if (zip.entries().hasMoreElements()) {
ZipEntry entry = zip.entries().nextElement();
- getHistoryFromStream(zip.getInputStream(entry), events);
+ inputStream = zip.getInputStream(entry);
+ fileLength = entry.getSize();
}
} else {
- InputStream reader = new FileInputStream(file);
- getHistoryFromStream(reader, events);
- reader.close();
+ inputStream = new FileInputStream(file);
+ fileLength = file.length();
}
+ //450: the approximate size of an event in XML
+ int numberOfEventsEstimate = (int) (fileLength / 450);
+
+ monitor.beginTask(Messages.InteractionEventLogger_Reading_History_From_File, numberOfEventsEstimate);
+
+ getHistoryFromStream(inputStream, events, monitor);
+
} catch (Exception e) {
StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN,
"Could not read interaction history", e)); //$NON-NLS-1$
+ } finally {
+ if (inputStream != null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN,
+ "unable to close input stream", e)); //$NON-NLS-1$
+ }
+ }
}
+
+ monitor.done();
+
return events;
}
/**
* @param events
+ * @param monitor
* @param tag
* @param endl
* @param buf
*/
- private void getHistoryFromStream(InputStream reader, List<InteractionEvent> events) throws IOException {
+ private void getHistoryFromStream(InputStream reader, List<InteractionEvent> events, IProgressMonitor monitor)
+ throws IOException {
String xml;
int index;
String buf = ""; //$NON-NLS-1$
@@ -176,6 +208,8 @@ public class InteractionEventLogger extends AbstractMonitorLog implements IInter
} else {
buf = buf.substring(index + endl.length(), buf.length());
}
+
+ monitor.worked(1);
}
buffer = new byte[1000];
}
@@ -359,4 +393,8 @@ public class InteractionEventLogger extends AbstractMonitorLog implements IInter
}
return org.eclipse.mylyn.internal.commons.core.XmlStringConverter.convertXmlToString(content.toString()).trim();
}
+
+ public static DateFormat dateFormat() {
+ return (DateFormat) dateFormat.clone();
+ }
}
diff --git a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/Messages.java b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/Messages.java
index da9185a4..bca61a1b 100644
--- a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/Messages.java
+++ b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/Messages.java
@@ -16,6 +16,8 @@ import org.eclipse.osgi.util.NLS;
public class Messages extends NLS {
private static final String BUNDLE_NAME = "org.eclipse.mylyn.internal.monitor.usage.messages"; //$NON-NLS-1$
+ public static String InteractionEventLogger_Reading_History_From_File;
+
public static String MonitorFileRolloverJob_Mylyn_Monitor_Log_Rollover;
public static String ReportGenerator_Generate_Statistics_Job;
diff --git a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/messages.properties b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/messages.properties
index f91e6e4e..d71f3411 100644
--- a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/messages.properties
+++ b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/messages.properties
@@ -1,3 +1,4 @@
+InteractionEventLogger_Reading_History_From_File=Reading Interaction History from File
MonitorFileRolloverJob_Mylyn_Monitor_Log_Rollover=Mylyn Monitor Log Rollover
ReportGenerator_Generate_Statistics_Job=Generate statistics job
ReportGenerator_Mylyn_Usage_Summary_Generation=Mylyn Usage Summary Generation

Back to the top