Java ByteBuffer Get getMultiString(ByteBuffer bb, boolean wideChar)

Here you can find the source of getMultiString(ByteBuffer bb, boolean wideChar)

Description

get Multi String

License

Open Source License

Declaration

public static String[] getMultiString(ByteBuffer bb, boolean wideChar) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * This program and the accompanying materials
 * are made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at 
 * http://www.eclipse.org/legal/cpl-v10.html
 * //w w w  .j a v a 2 s  .  co  m
 * Contributors:
 *     Peter Smith
 *******************************************************************************/

import java.nio.ByteBuffer;

import java.util.ArrayList;

public class Main {
    public static String[] getMultiString(ByteBuffer bb, boolean wideChar) {
        ArrayList strs = new ArrayList();
        StringBuilder sb = new StringBuilder();
        while (bb.hasRemaining()) {
            char c = wideChar ? bb.getChar() : (char) bb.get();
            if (c == 0) {
                if (sb.length() == 0) {
                    break;
                } else {
                    strs.add(sb.toString());
                    sb.setLength(0);
                }
            } else {
                sb.append(c);
            }
        }
        return (String[]) strs.toArray(new String[strs.size()]);
    }
}

Related

  1. getLTriad(ByteBuffer bb)
  2. getMean(ByteBuffer simulationResults)
  3. getMedium(ByteBuffer buffer)
  4. getMediumInt(ByteBuffer buffer)
  5. getModularShort(ByteBuffer bb)
  6. getNaluStartLength(ByteBuffer buffer)
  7. getNextTagNum(ByteBuffer message)
  8. getNTString(ByteBuffer buffer)
  9. getNullTerminatedByte(ByteBuffer buffer)