@Override public long skip(long n) throws IOException { if (n <= 0) return 0; byte[] buf = new byte[4096]; for (long remaining = n;;) { int count = this.read(buf, 0, (int) Math.min(buf.length, remaining)); if (count == -1) return n - remaining; remaining -= count; if (remaining == 0L) return n; } }
private static String percentDecode(byte[] bytes, int off, int len) throws IOException { PercentEncodingInputStream is = new PercentEncodingInputStream(new ByteArrayInputStream(bytes, off, len)); try { // According to https://tools.ietf.org/html/rfc3986#section-2.5, "... the data should first be encoded as // octets according to the UTF-8 character encoding". return IoUtil.readAll(new InputStreamReader(is, CHARSET_UTF_8)); } catch (MalformedInputException mie) { // Bytes could not be UTF-8-decoded, so fall back to ISO 8859-1. return IoUtil.readAll(new InputStreamReader(is, CHARSET_ISO_8859_1)); } }
private static String percentDecode(byte[] bytes, int off, int len) throws IOException { PercentEncodingInputStream is = new PercentEncodingInputStream(new ByteArrayInputStream(bytes, off, len)); try { // According to https://tools.ietf.org/html/rfc3986#section-2.5, "... the data should first be encoded as // octets according to the UTF-8 character encoding". return Readers.readAll(new InputStreamReader(is, CHARSET_UTF_8)); } catch (MalformedInputException mie) { // Bytes could not be UTF-8-decoded, so fall back to ISO 8859-1. return Readers.readAll(new InputStreamReader(is, CHARSET_ISO_8859_1)); } }
@Override public long skip(long n) throws IOException { if (n <= 0) return 0; byte[] buf = new byte[4096]; for (long remaining = n;;) { int count = this.read(buf, 0, (int) Math.min(buf.length, remaining)); if (count == -1) return n - remaining; remaining -= count; if (remaining == 0L) return n; } }
@Override public int read(byte[] buf, int off, int len) throws IOException { if (off < 0 || off > buf.length) throw new IndexOutOfBoundsException("off"); if (len < 0 || len > buf.length - off) throw new IndexOutOfBoundsException("len"); if (len == 0) return 0; int b = this.read(); if (b == -1) return -1; buf[off] = (byte) b; for (int i = 1; i < len; i++) { try { b = this.read(); } catch (IOException ioe) { return i; } if (b == -1) return i; buf[off + i] = (byte) b; } return len; }
@Override public int read(byte[] buf, int off, int len) throws IOException { if (off < 0 || off > buf.length) throw new IndexOutOfBoundsException("off"); if (len < 0 || len > buf.length - off) throw new IndexOutOfBoundsException("len"); if (len == 0) return 0; int b = this.read(); if (b == -1) return -1; buf[off] = (byte) b; for (int i = 1; i < len; i++) { try { b = this.read(); } catch (IOException ioe) { return i; } if (b == -1) return i; buf[off + i] = (byte) b; } return len; }