一段很漂亮的输入流读取代码

抄自QuickServer的源码

private static byte[] toBytes(InputStream _in) throws IOException {

byte[] data = null;

int s = _in.read();

if (s == -1) {

return null;

}

int alength = _in.available();

if (alength > 0) {

data = new byte[alength + 1];

_in.read(data, 1, alength);

} else {

data = new byte[1];

}

data[0] = (byte) s;

return data;

}

Leave a Comment

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.