Here you can find the source of parseLinesFromLast(byte[] bytearray, int lineCount, Vector lastNlines)
Parameter | Description |
---|---|
bytearray | a parameter |
lineCount | a parameter |
lastNlines | a parameter |
private static boolean parseLinesFromLast(byte[] bytearray, int lineCount, Vector lastNlines)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { /**/*from w w w . j a va2 s . com*/ * Given a byte array this method: * a. creates a String out of it * b. reverses the string * c. extracts the lines * d. characters in extracted line will be in reverse order, * so it reverses the line just before storing in Vector. * * On extracting required numer of lines, this method returns TRUE, * Else it returns FALSE. * * @param bytearray * @param lineCount * @param lastNlines * @return */ private static boolean parseLinesFromLast(byte[] bytearray, int lineCount, Vector lastNlines) { String lastNChars = new String(bytearray); StringBuffer sb = new StringBuffer(lastNChars); lastNChars = sb.reverse().toString(); StringTokenizer tokens = new StringTokenizer(lastNChars, "\n"); while (tokens.hasMoreTokens()) { StringBuffer sbLine = new StringBuffer((String) tokens.nextToken()); lastNlines.add(sbLine.reverse().toString()); if (lastNlines.size() == lineCount) { return true;//indicates we got 'lineCount' lines } } return false; //indicates didn't read 'lineCount' lines } }