private static String readLineBytes(DataInputStream stream) { // readLineBytes() by Christopher Mann, Clemson University, 2005 // // Usage: If your DataInputStream is named dataFromServer, // String line = readLineBytes(dataFromServer); StringBuffer sb = new StringBuffer(); try{ char curr = (char)stream.readByte(); while(curr != '\n'){ if(curr != '\r') sb.append(curr); curr = (char)stream.readByte(); } // This will happen once all data has been read. }catch(Exception e){ /* This allows for this method to completely act as BufferedReader's readLine method, returning null once there is nothing more to read. */ if(sb.toString().equals("")) return null; } return sb.toString(); }