Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static String stringFromStandardInput(Charset cs) throws IOException {
- int BUFFER_SIZE = 10;
- ReadableByteChannel in = Channels.newChannel(System.in);
- ByteBuffer bb = ByteBuffer.allocate(10);
- StringBuilder sb = new StringBuilder();
- while(bb.hasRemaining()) {
- if(in.read(bb) > bb.remaining()){
- BUFFER_SIZE *= 2;
- ByteBuffer bb_ = ByteBuffer.allocate(BUFFER_SIZE);
- bb_.put(bb);
- bb = bb_;
- }
- }
- bb.flip();
- sb.append(cs.decode(bb));
- bb.clear();
- return sb.toString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement