|
@@ -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
|
}
|