Java Vector Create parseLinesFromLast(byte[] bytearray, int lineCount, Vector lastNlines)

Here you can find the source of parseLinesFromLast(byte[] bytearray, int lineCount, Vector lastNlines)

Description

Given a byte array this method: a.

License

Open Source License

Parameter

Parameter Description
bytearray a parameter
lineCount a parameter
lastNlines a parameter

Declaration

private static boolean parseLinesFromLast(byte[] bytearray, int lineCount, Vector lastNlines) 

Method Source Code


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

Related

  1. createVector(Object[] array)
  2. makeVector(String[] O)
  3. tokenVector(String s, String delimiters)
  4. ToVector(byte[] in)
  5. toVector(Enumeration pEnumeration_)
  6. toVector(Object[] array)