Quellcode durchsuchen

Call addLine with a \n delimited string.

Issue 1242


git-svn-id: http://svn.dmdirc.com/trunk@4078 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Shane Mc Cormack vor 16 Jahren
Ursprung
Commit
e92ab141ce

+ 1
- 4
src/com/dmdirc/addons/logging/HistoryWindow.java Datei anzeigen

@@ -71,10 +71,7 @@ public class HistoryWindow extends FrameContainer {
71 71
                 "plugin-Logging", "history.lines", 50000);
72 72
         final int frameBufferSize = IdentityManager.getGlobalConfig().getOptionInt(
73 73
                 "ui", "frameBufferSize", 10000);
74
-        final Stack<String> lines = reader.getLines(Math.min(frameBufferSize, historyLineCount));
75
-        while (lines.size() > 0) {
76
-            window.addLine(lines.pop(), false);
77
-        }
74
+        window.addLine(reader.getLinesAsString(Math.min(frameBufferSize, historyLineCount)), false);
78 75
     }
79 76
     
80 77
     /** {@inheritDoc} */

+ 24
- 1
src/com/dmdirc/addons/logging/ReverseFileReader.java Datei anzeigen

@@ -218,7 +218,7 @@ public class ReverseFileReader {
218 218
 	 * If the file is closed, an empty stack will be returned.
219 219
 	 *
220 220
 	 * @param numLines Number of lines to try and get.
221
-     * @return The requested lines
221
+	 * @return The requested lines
222 222
 	 */
223 223
 	public Stack<String> getLines(final int numLines) {
224 224
 		final Stack<String> result = new Stack<String>();
@@ -231,4 +231,27 @@ public class ReverseFileReader {
231 231
 		}
232 232
 		return result;
233 233
 	}
234
+	
235
+	/**
236
+	 * Try and get x number of lines and return a \n delimited String.
237
+	 * If the file is closed, an empty string will be returned.
238
+	 *
239
+	 * @param numLines Number of lines to try and get.
240
+	 * @return The requested lines
241
+	 */
242
+	public String getLinesAsString(final int numLines) {
243
+		final StringBuilder result = new StringBuilder();
244
+		for (int i = 0; i < numLines; ++i) {
245
+			try {
246
+				result.insert(0, "\n");
247
+				result.insert(0, getNextLine());
248
+			} catch (IOException e) {
249
+				break;
250
+			}
251
+		}
252
+		if (result.charAt(0) == '\n') {
253
+			result.deleteCharAt(0);
254
+		}
255
+		return result.toString();
256
+	}
234 257
 }

Laden…
Abbrechen
Speichern