public static String readStringSafely ( DataInput in , int maxLength ) throws IOException , IllegalArgumentException { int length = readVInt ( in ) ; if ( length < 0 || length > maxLength ) { throw new IllegalArgumentException ( "Encoded byte size for String was " + length + ", which is outside of 0.." + maxLength + " range." ) ; } byte [ ] bytes = new byte [ length ] ; in . readFully ( bytes , 0 , length ) ; return Text . decode ( bytes ) ; }
Read a string but check it for sanity . The format consists of a vint followed by the given number of bytes .