Here you can find the source of getString(ByteBuffer bb)
Parameter | Description |
---|---|
bb | the input byte buffer |
Parameter | Description |
---|---|
IOException | if an I/O error occurs |
public static String getString(ByteBuffer bb) throws IOException
//package com.java2s; /**/*from w w w . j a v a 2s .com*/ * Copyright 2001 Sun Microsystems, Inc. * * See the file "license.terms" for information on usage and * redistribution of this file, and for a DISCLAIMER OF ALL * WARRANTIES. */ import java.io.DataInputStream; import java.nio.ByteBuffer; import java.io.IOException; public class Main { /** Inputs a string from a DataInputStream. * @param dis the stream * @return the string * @throws IOException if an I/O error occurs */ public static String getString(DataInputStream dis) throws IOException { int size = dis.readShort(); char[] charBuffer = new char[size]; for (int i = 0; i < size; i++) { charBuffer[i] = dis.readChar(); } return new String(charBuffer, 0, size); } /** Inputs a string from a ByteBuffer. * @param bb the input byte buffer * @return the string * @throws IOException if an I/O error occurs */ public static String getString(ByteBuffer bb) throws IOException { int size = bb.getShort(); char[] charBuffer = new char[size]; for (int i = 0; i < size; i++) { charBuffer[i] = bb.getChar(); } return new String(charBuffer, 0, size); } }