@Override public int read(byte[] buffer) throws IOException { return read(buffer, 0, buffer.length); }
private void expect(char expected) throws IOException { int readByte = inputStream.read(); if (readByte != expected) { throw new IOException(String.format("Expected %04x (%c) but got %04x (%c)", (int) expected, expected, readByte, (char) readByte)); } }
private String readStringUntil(char end) throws IOException { StringBuilder sb = new StringBuilder(); int ch; while ((ch = inputStream.read()) != -1) { if (ch == end) { return sb.toString(); } else { sb.append((char) ch); } } throw new IOException("readStringUntil(): end of stream reached. " + "Read: \"" + sb.toString() + "\" while waiting for " + formatChar(end)); }
private String parseBareString(boolean allowBrackets) throws IOException { StringBuilder sb = new StringBuilder(); int ch; while (true) { ch = inputStream.peek(); if (ch == -1) { throw new IOException("parseBareString(): end of stream reached"); } if (ch == '(' || ch == ')' || (allowBrackets && (ch == '[' || ch == ']')) || ch == '{' || ch == ' ' || ch == '"' || (ch >= 0x00 && ch <= 0x1f) || ch == 0x7f) { if (sb.length() == 0) { throw new IOException(String.format("parseBareString(): (%04x %c)", ch, ch)); } return sb.toString(); } else { sb.append((char) inputStream.read()); } } }
private String parseQuoted() throws IOException { expect('"'); StringBuilder sb = new StringBuilder(); int ch; boolean escape = false; while ((ch = inputStream.read()) != -1) { if (!escape && ch == '\\') { // Found the escape character escape = true; } else if (!escape && ch == '"') { return sb.toString(); } else { sb.append((char) ch); escape = false; } } throw new IOException("parseQuoted(): end of stream reached"); }
private String readLine() throws IOException { StringBuilder sb = new StringBuilder(); int d; while ((d = inputStream.read()) != -1) { char c = (char) d; if (c == '\n') { break; } else if (c != '\r') { sb.append(c); } } String ret = sb.toString(); if (K9MailLib.isDebug() && DEBUG_PROTOCOL_SMTP) Timber.d("SMTP <<< %s", ret); return ret; }
int read = 0; while (read != size) { int count = inputStream.read(data, read, size - read); if (count == -1) { throw new IOException("parseLiteral(): end of stream reached");