public static String readString ( DataInputStream is , byte [ ] _buff ) throws IOException { int l = is . readInt ( ) ; byte [ ] buff = _buff ; switch ( l ) { case - 1 : return null ; case 0 : return "" ; default : // Cover case where there is a large string, without always allocating a large buffer. if ( l > buff . length ) { buff = new byte [ l ] ; } is . read ( buff , 0 , l ) ; return new String ( buff , 0 , l ) ; } }
We use bytes here to set a Maximum