Java Code Examples for sun.misc.IOUtils#readNBytes()
The following examples show how to use
sun.misc.IOUtils#readNBytes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ICC_Profile.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
static byte[] getProfileDataFromStream(InputStream s) throws IOException { BufferedInputStream bis = new BufferedInputStream(s); bis.mark(128); byte[] header = IOUtils.readNBytes(bis, 128); if (header[36] != 0x61 || header[37] != 0x63 || header[38] != 0x73 || header[39] != 0x70) { return null; /* not a valid profile */ } int profileSize = ((header[0] & 0xff) << 24) | ((header[1] & 0xff) << 16) | ((header[2] & 0xff) << 8) | (header[3] & 0xff); bis.reset(); try { return IOUtils.readNBytes(bis, profileSize); } catch (OutOfMemoryError e) { throw new IOException("Color profile is too big"); } }
Example 2
Source File: ICC_Profile.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
static byte[] getProfileDataFromStream(InputStream s) throws IOException { BufferedInputStream bis = new BufferedInputStream(s); bis.mark(128); byte[] header = IOUtils.readNBytes(bis, 128); if (header[36] != 0x61 || header[37] != 0x63 || header[38] != 0x73 || header[39] != 0x70) { return null; /* not a valid profile */ } int profileSize = ((header[0] & 0xff) << 24) | ((header[1] & 0xff) << 16) | ((header[2] & 0xff) << 8) | (header[3] & 0xff); bis.reset(); try { return IOUtils.readNBytes(bis, profileSize); } catch (OutOfMemoryError e) { throw new IOException("Color profile is too big"); } }
Example 3
Source File: ICC_Profile.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
static byte[] getProfileDataFromStream(InputStream s) throws IOException { BufferedInputStream bis = new BufferedInputStream(s); bis.mark(128); byte[] header = IOUtils.readNBytes(bis, 128); if (header[36] != 0x61 || header[37] != 0x63 || header[38] != 0x73 || header[39] != 0x70) { return null; /* not a valid profile */ } int profileSize = ((header[0] & 0xff) << 24) | ((header[1] & 0xff) << 16) | ((header[2] & 0xff) << 8) | (header[3] & 0xff); bis.reset(); try { return IOUtils.readNBytes(bis, profileSize); } catch (OutOfMemoryError e) { throw new IOException("Color profile is too big"); } }
Example 4
Source File: ICC_Profile.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
static byte[] getProfileDataFromStream(InputStream s) throws IOException { BufferedInputStream bis = new BufferedInputStream(s); bis.mark(128); byte[] header = IOUtils.readNBytes(bis, 128); if (header[36] != 0x61 || header[37] != 0x63 || header[38] != 0x73 || header[39] != 0x70) { return null; /* not a valid profile */ } int profileSize = ((header[0] & 0xff) << 24) | ((header[1] & 0xff) << 16) | ((header[2] & 0xff) << 8) | (header[3] & 0xff); bis.reset(); try { return IOUtils.readNBytes(bis, profileSize); } catch (OutOfMemoryError e) { throw new IOException("Color profile is too big"); } }
Example 5
Source File: CertificateRevokedException.java From jdk1.8-source-analysis with Apache License 2.0 | 5 votes |
/** * Deserialize the {@code CertificateRevokedException} instance. */ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { // Read in the non-transient fields // (revocationDate, reason, authority) ois.defaultReadObject(); // Defensively copy the revocation date revocationDate = new Date(revocationDate.getTime()); // Read in the size (number of mappings) of the extensions map // and create the extensions map int size = ois.readInt(); if (size == 0) { extensions = Collections.emptyMap(); } else if (size < 0) { throw new IOException("size cannot be negative"); } else { extensions = new HashMap<>(size > 20 ? 20 : size); } // Read in the extensions and put the mappings in the extensions map for (int i = 0; i < size; i++) { String oid = (String) ois.readObject(); boolean critical = ois.readBoolean(); byte[] extVal = IOUtils.readNBytes(ois, ois.readInt()); Extension ext = sun.security.x509.Extension.newExtension (new ObjectIdentifier(oid), critical, extVal); extensions.put(oid, ext); } }
Example 6
Source File: ReadNBytes.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
static void test(byte[] inputBytes) throws IOException { int length = inputBytes.length; WrapperInputStream in = new WrapperInputStream(new ByteArrayInputStream(inputBytes)); byte[] readBytes = new byte[(length / 2) + 1]; int nread = IOUtils.readNBytes(in, readBytes, 0, readBytes.length); int x; byte[] tmp; check(nread == readBytes.length, "Expected number of bytes read: " + readBytes.length + ", got: " + nread); check(Arrays.equals((tmp = Arrays.copyOf(inputBytes, nread)), readBytes), "Expected[" + tmp + "], got:[" + readBytes + "]"); check(!in.isClosed(), "Stream unexpectedly closed"); // Read again nread = IOUtils.readNBytes(in, readBytes, 0, readBytes.length); check(nread == length - readBytes.length, "Expected number of bytes read: " + (length - readBytes.length) + ", got: " + nread); check(Arrays.equals((tmp = Arrays.copyOfRange(inputBytes, readBytes.length, length)), Arrays.copyOf(readBytes, nread)), "Expected[" + tmp + "], got:[" + readBytes + "]"); // Expect end of stream check((x = in.read()) == -1, "Expected end of stream from read(), got " + x); check((x = in.read(tmp)) == -1, "Expected end of stream from read(byte[]), got " + x); check((x = in.read(tmp, 0, tmp.length)) == -1, "Expected end of stream from read(byte[], int, int), got " + x); check((x = IOUtils.readNBytes(in, tmp, 0, tmp.length)) == 0, "Expected end of stream, 0, from readNBytes(byte[], int, int), got " + x); check(!in.isClosed(), "Stream unexpectedly closed"); }
Example 7
Source File: ReadNBytes.java From TencentKona-8 with GNU General Public License v2.0 | 5 votes |
static void test(byte[] inputBytes) throws IOException { int length = inputBytes.length; WrapperInputStream in = new WrapperInputStream(new ByteArrayInputStream(inputBytes)); byte[] readBytes = new byte[(length / 2) + 1]; int nread = IOUtils.readNBytes(in, readBytes, 0, readBytes.length); int x; byte[] tmp; check(nread == readBytes.length, "Expected number of bytes read: " + readBytes.length + ", got: " + nread); check(Arrays.equals((tmp = Arrays.copyOf(inputBytes, nread)), readBytes), "Expected[" + tmp + "], got:[" + readBytes + "]"); check(!in.isClosed(), "Stream unexpectedly closed"); // Read again nread = IOUtils.readNBytes(in, readBytes, 0, readBytes.length); check(nread == length - readBytes.length, "Expected number of bytes read: " + (length - readBytes.length) + ", got: " + nread); check(Arrays.equals((tmp = Arrays.copyOfRange(inputBytes, readBytes.length, length)), Arrays.copyOf(readBytes, nread)), "Expected[" + tmp + "], got:[" + readBytes + "]"); // Expect end of stream check((x = in.read()) == -1, "Expected end of stream from read(), got " + x); check((x = in.read(tmp)) == -1, "Expected end of stream from read(byte[]), got " + x); check((x = in.read(tmp, 0, tmp.length)) == -1, "Expected end of stream from read(byte[], int, int), got " + x); check((x = IOUtils.readNBytes(in, tmp, 0, tmp.length)) == 0, "Expected end of stream, 0, from readNBytes(byte[], int, int), got " + x); check(!in.isClosed(), "Stream unexpectedly closed"); }
Example 8
Source File: CertificateRevokedException.java From JDKSourceCode1.8 with MIT License | 5 votes |
/** * Deserialize the {@code CertificateRevokedException} instance. */ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { // Read in the non-transient fields // (revocationDate, reason, authority) ois.defaultReadObject(); // Defensively copy the revocation date revocationDate = new Date(revocationDate.getTime()); // Read in the size (number of mappings) of the extensions map // and create the extensions map int size = ois.readInt(); if (size == 0) { extensions = Collections.emptyMap(); } else if (size < 0) { throw new IOException("size cannot be negative"); } else { extensions = new HashMap<>(size > 20 ? 20 : size); } // Read in the extensions and put the mappings in the extensions map for (int i = 0; i < size; i++) { String oid = (String) ois.readObject(); boolean critical = ois.readBoolean(); byte[] extVal = IOUtils.readNBytes(ois, ois.readInt()); Extension ext = sun.security.x509.Extension.newExtension (new ObjectIdentifier(oid), critical, extVal); extensions.put(oid, ext); } }
Example 9
Source File: ReadNBytes.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
static void test(byte[] inputBytes) throws IOException { int length = inputBytes.length; WrapperInputStream in = new WrapperInputStream(new ByteArrayInputStream(inputBytes)); byte[] readBytes = new byte[(length / 2) + 1]; int nread = IOUtils.readNBytes(in, readBytes, 0, readBytes.length); int x; byte[] tmp; check(nread == readBytes.length, "Expected number of bytes read: " + readBytes.length + ", got: " + nread); check(Arrays.equals((tmp = Arrays.copyOf(inputBytes, nread)), readBytes), "Expected[" + tmp + "], got:[" + readBytes + "]"); check(!in.isClosed(), "Stream unexpectedly closed"); // Read again nread = IOUtils.readNBytes(in, readBytes, 0, readBytes.length); check(nread == length - readBytes.length, "Expected number of bytes read: " + (length - readBytes.length) + ", got: " + nread); check(Arrays.equals((tmp = Arrays.copyOfRange(inputBytes, readBytes.length, length)), Arrays.copyOf(readBytes, nread)), "Expected[" + tmp + "], got:[" + readBytes + "]"); // Expect end of stream check((x = in.read()) == -1, "Expected end of stream from read(), got " + x); check((x = in.read(tmp)) == -1, "Expected end of stream from read(byte[]), got " + x); check((x = in.read(tmp, 0, tmp.length)) == -1, "Expected end of stream from read(byte[], int, int), got " + x); check((x = IOUtils.readNBytes(in, tmp, 0, tmp.length)) == 0, "Expected end of stream, 0, from readNBytes(byte[], int, int), got " + x); check(!in.isClosed(), "Stream unexpectedly closed"); }
Example 10
Source File: CertificateRevokedException.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
/** * Deserialize the {@code CertificateRevokedException} instance. */ private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException { // Read in the non-transient fields // (revocationDate, reason, authority) ois.defaultReadObject(); // Defensively copy the revocation date revocationDate = new Date(revocationDate.getTime()); // Read in the size (number of mappings) of the extensions map // and create the extensions map int size = ois.readInt(); if (size == 0) { extensions = Collections.emptyMap(); } else if (size < 0) { throw new IOException("size cannot be negative"); } else { extensions = new HashMap<>(size > 20 ? 20 : size); } // Read in the extensions and put the mappings in the extensions map for (int i = 0; i < size; i++) { String oid = (String) ois.readObject(); boolean critical = ois.readBoolean(); byte[] extVal = IOUtils.readNBytes(ois, ois.readInt()); Extension ext = sun.security.x509.Extension.newExtension (new ObjectIdentifier(oid), critical, extVal); extensions.put(oid, ext); } }
Example 11
Source File: ReadNBytes.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
static void test(byte[] inputBytes) throws IOException { int length = inputBytes.length; WrapperInputStream in = new WrapperInputStream(new ByteArrayInputStream(inputBytes)); byte[] readBytes = new byte[(length / 2) + 1]; int nread = IOUtils.readNBytes(in, readBytes, 0, readBytes.length); int x; byte[] tmp; check(nread == readBytes.length, "Expected number of bytes read: " + readBytes.length + ", got: " + nread); check(Arrays.equals((tmp = Arrays.copyOf(inputBytes, nread)), readBytes), "Expected[" + tmp + "], got:[" + readBytes + "]"); check(!in.isClosed(), "Stream unexpectedly closed"); // Read again nread = IOUtils.readNBytes(in, readBytes, 0, readBytes.length); check(nread == length - readBytes.length, "Expected number of bytes read: " + (length - readBytes.length) + ", got: " + nread); check(Arrays.equals((tmp = Arrays.copyOfRange(inputBytes, readBytes.length, length)), Arrays.copyOf(readBytes, nread)), "Expected[" + tmp + "], got:[" + readBytes + "]"); // Expect end of stream check((x = in.read()) == -1, "Expected end of stream from read(), got " + x); check((x = in.read(tmp)) == -1, "Expected end of stream from read(byte[]), got " + x); check((x = in.read(tmp, 0, tmp.length)) == -1, "Expected end of stream from read(byte[], int, int), got " + x); check((x = IOUtils.readNBytes(in, tmp, 0, tmp.length)) == 0, "Expected end of stream, 0, from readNBytes(byte[], int, int), got " + x); check(!in.isClosed(), "Stream unexpectedly closed"); }
Example 12
Source File: ReadNBytes.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
static void test(int max) throws IOException { byte[] subset1, subset2; byte[] inputBytes = max <= 0 ? new byte[0] : createRandomBytes(max); WrapperInputStream in = new WrapperInputStream(new ByteArrayInputStream(inputBytes)); if (max < 0) { try { IOUtils.readNBytes(in, max); check(false, "Expected IllegalArgumentException not thrown"); } catch (IllegalArgumentException iae) { return; } } else if (max == 0) { int x; check((x = IOUtils.readNBytes(in, max).length) == 0, "Expected zero bytes, got " + x); return; } int off = Math.toIntExact(in.skip(generator.nextInt(max/2))); int len = generator.nextInt(max - 1 - off); byte[] readBytes = IOUtils.readNBytes(in, len); check(readBytes.length == len, "Expected " + len + " bytes, got " + readBytes.length); subset1 = Arrays.copyOfRange(inputBytes, off, off + len); subset2 = Arrays.copyOfRange(readBytes, 0, len); check(Arrays.equals(subset1, subset2), "Expected[" + subset1 + "], got:[" + readBytes + "]"); int remaining = max - (off + len); readBytes = IOUtils.readNBytes(in, remaining); check(readBytes.length == remaining, "Expected " + remaining + "bytes, got " + readBytes.length); subset1 = Arrays.copyOfRange(inputBytes, off + len, max); subset2 = Arrays.copyOfRange(readBytes, 0, remaining); check(Arrays.equals(subset1, subset2), "Expected[" + subset1 + "], got:[" + readBytes + "]"); check(!in.isClosed(), "Stream unexpectedly closed"); }
Example 13
Source File: ReadNBytes.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
static void test(int max) throws IOException { byte[] subset1, subset2; byte[] inputBytes = max <= 0 ? new byte[0] : createRandomBytes(max); WrapperInputStream in = new WrapperInputStream(new ByteArrayInputStream(inputBytes)); if (max < 0) { try { IOUtils.readNBytes(in, max); check(false, "Expected IllegalArgumentException not thrown"); } catch (IllegalArgumentException iae) { return; } } else if (max == 0) { int x; check((x = IOUtils.readNBytes(in, max).length) == 0, "Expected zero bytes, got " + x); return; } int off = Math.toIntExact(in.skip(generator.nextInt(max/2))); int len = generator.nextInt(max - 1 - off); byte[] readBytes = IOUtils.readNBytes(in, len); check(readBytes.length == len, "Expected " + len + " bytes, got " + readBytes.length); subset1 = Arrays.copyOfRange(inputBytes, off, off + len); subset2 = Arrays.copyOfRange(readBytes, 0, len); check(Arrays.equals(subset1, subset2), "Expected[" + subset1 + "], got:[" + readBytes + "]"); int remaining = max - (off + len); readBytes = IOUtils.readNBytes(in, remaining); check(readBytes.length == remaining, "Expected " + remaining + "bytes, got " + readBytes.length); subset1 = Arrays.copyOfRange(inputBytes, off + len, max); subset2 = Arrays.copyOfRange(readBytes, 0, remaining); check(Arrays.equals(subset1, subset2), "Expected[" + subset1 + "], got:[" + readBytes + "]"); check(!in.isClosed(), "Stream unexpectedly closed"); }
Example 14
Source File: ReadNBytes.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
static void test(int max) throws IOException { byte[] subset1, subset2; byte[] inputBytes = max <= 0 ? new byte[0] : createRandomBytes(max); WrapperInputStream in = new WrapperInputStream(new ByteArrayInputStream(inputBytes)); if (max < 0) { try { IOUtils.readNBytes(in, max); check(false, "Expected IllegalArgumentException not thrown"); } catch (IllegalArgumentException iae) { return; } } else if (max == 0) { int x; check((x = IOUtils.readNBytes(in, max).length) == 0, "Expected zero bytes, got " + x); return; } int off = Math.toIntExact(in.skip(generator.nextInt(max/2))); int len = generator.nextInt(max - 1 - off); byte[] readBytes = IOUtils.readNBytes(in, len); check(readBytes.length == len, "Expected " + len + " bytes, got " + readBytes.length); subset1 = Arrays.copyOfRange(inputBytes, off, off + len); subset2 = Arrays.copyOfRange(readBytes, 0, len); check(Arrays.equals(subset1, subset2), "Expected[" + subset1 + "], got:[" + readBytes + "]"); int remaining = max - (off + len); readBytes = IOUtils.readNBytes(in, remaining); check(readBytes.length == remaining, "Expected " + remaining + "bytes, got " + readBytes.length); subset1 = Arrays.copyOfRange(inputBytes, off + len, max); subset2 = Arrays.copyOfRange(readBytes, 0, remaining); check(Arrays.equals(subset1, subset2), "Expected[" + subset1 + "], got:[" + readBytes + "]"); check(!in.isClosed(), "Stream unexpectedly closed"); }
Example 15
Source File: ReadNBytes.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
static void test(int max) throws IOException { byte[] subset1, subset2; byte[] inputBytes = max <= 0 ? new byte[0] : createRandomBytes(max); WrapperInputStream in = new WrapperInputStream(new ByteArrayInputStream(inputBytes)); if (max < 0) { try { IOUtils.readNBytes(in, max); check(false, "Expected IllegalArgumentException not thrown"); } catch (IllegalArgumentException iae) { return; } } else if (max == 0) { int x; check((x = IOUtils.readNBytes(in, max).length) == 0, "Expected zero bytes, got " + x); return; } int off = Math.toIntExact(in.skip(generator.nextInt(max/2))); int len = generator.nextInt(max - 1 - off); byte[] readBytes = IOUtils.readNBytes(in, len); check(readBytes.length == len, "Expected " + len + " bytes, got " + readBytes.length); subset1 = Arrays.copyOfRange(inputBytes, off, off + len); subset2 = Arrays.copyOfRange(readBytes, 0, len); check(Arrays.equals(subset1, subset2), "Expected[" + subset1 + "], got:[" + readBytes + "]"); int remaining = max - (off + len); readBytes = IOUtils.readNBytes(in, remaining); check(readBytes.length == remaining, "Expected " + remaining + "bytes, got " + readBytes.length); subset1 = Arrays.copyOfRange(inputBytes, off + len, max); subset2 = Arrays.copyOfRange(readBytes, 0, remaining); check(Arrays.equals(subset1, subset2), "Expected[" + subset1 + "], got:[" + readBytes + "]"); check(!in.isClosed(), "Stream unexpectedly closed"); }