protected byte[] consumeLiteralAsBytes(ImapRequestLineReader request) throws ProtocolException { // The 1st character must be '{' consumeChar(request, '{'); StringBuilder digits = new StringBuilder(); char next = request.nextChar(); while (next != '}' && next != '+') { digits.append(next); request.consume(); next = request.nextChar(); } // If the number is *not* suffixed with a '+', we *are* using a synchronized literal, // and we need to send command continuation request before reading data. boolean synchronizedLiteral = true; // '+' indicates a non-synchronized literal (no command continuation request) if (next == '+') { synchronizedLiteral = false; consumeChar(request, '+'); } // Consume the '}' and the newline consumeChar(request, '}'); consumeCRLF(request); if (synchronizedLiteral) { request.commandContinuationRequest(); } int size = Integer.parseInt(digits.toString()); byte[] buffer = new byte[size]; request.read(buffer); return buffer; }