sun.misc.IOUtils Java Examples
The following examples show how to use
sun.misc.IOUtils.
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: AppletClassLoader.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
private static byte[] getBytes(URL url) throws IOException { URLConnection uc = url.openConnection(); if (uc instanceof java.net.HttpURLConnection) { java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc; int code = huc.getResponseCode(); if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) { throw new IOException("open HTTP connection failed."); } } int len = uc.getContentLength(); // Fixed #4507227: Slow performance to load // class and resources. [stanleyh] // // Use buffered input stream [stanleyh] InputStream in = new BufferedInputStream(uc.getInputStream()); byte[] b; try { b = IOUtils.readFully(in, len, true); } finally { in.close(); } return b; }
Example #2
Source File: MethodUtil.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static byte[] getBytes(URL url) throws IOException { URLConnection uc = url.openConnection(); if (uc instanceof java.net.HttpURLConnection) { java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc; int code = huc.getResponseCode(); if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) { throw new IOException("open HTTP connection failed."); } } int len = uc.getContentLength(); InputStream in = new BufferedInputStream(uc.getInputStream()); byte[] b; try { b = IOUtils.readFully(in, len, true); } finally { in.close(); } return b; }
Example #3
Source File: TimestampCheck.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
static void checkTimestamp(String file, String policyId, String digestAlg) throws Exception { try (JarFile jf = new JarFile(file)) { JarEntry je = jf.getJarEntry("META-INF/SIGNER.RSA"); try (InputStream is = jf.getInputStream(je)) { byte[] content = IOUtils.readAllBytes(is); PKCS7 p7 = new PKCS7(content); SignerInfo[] si = p7.getSignerInfos(); if (si == null || si.length == 0) { throw new Exception("Not signed"); } PKCS9Attribute p9 = si[0].getUnauthenticatedAttributes() .getAttribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID); PKCS7 tsToken = new PKCS7((byte[]) p9.getValue()); TimestampToken tt = new TimestampToken(tsToken.getContentInfo().getData()); if (!tt.getHashAlgorithm().toString().equals(digestAlg)) { throw new Exception("Digest alg different"); } if (!tt.getPolicyID().equals(policyId)) { throw new Exception("policyId different"); } } } }
Example #4
Source File: TimestampCheck.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
static void checkTimestamp(String file, String policyId, String digestAlg) throws Exception { try (JarFile jf = new JarFile(file)) { JarEntry je = jf.getJarEntry("META-INF/OLD.RSA"); try (InputStream is = jf.getInputStream(je)) { byte[] content = IOUtils.readFully(is, -1, true); PKCS7 p7 = new PKCS7(content); SignerInfo[] si = p7.getSignerInfos(); if (si == null || si.length == 0) { throw new Exception("Not signed"); } PKCS9Attribute p9 = si[0].getUnauthenticatedAttributes() .getAttribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID); PKCS7 tsToken = new PKCS7((byte[]) p9.getValue()); TimestampToken tt = new TimestampToken(tsToken.getContentInfo().getData()); if (!tt.getHashAlgorithm().toString().equals(digestAlg)) { throw new Exception("Digest alg different"); } if (!tt.getPolicyID().equals(policyId)) { throw new Exception("policyId different"); } } } }
Example #5
Source File: MethodUtil.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
private static byte[] getBytes(URL url) throws IOException { URLConnection uc = url.openConnection(); if (uc instanceof java.net.HttpURLConnection) { java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc; int code = huc.getResponseCode(); if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) { throw new IOException("open HTTP connection failed."); } } int len = uc.getContentLength(); InputStream in = new BufferedInputStream(uc.getInputStream()); byte[] b; try { b = IOUtils.readFully(in, len, true); } finally { in.close(); } return b; }
Example #6
Source File: CCacheInputStream.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
AuthorizationDataEntry[] readAuth() throws IOException { int num, adtype, adlength; num = readLength4(); if (num > 0) { List<AuthorizationDataEntry> auData = new ArrayList<>(); byte[] data = null; for (int i = 0; i < num; i++) { adtype = read(2); adlength = readLength4(); data = IOUtils.readFully(this, adlength, true); auData.add(new AuthorizationDataEntry(adtype, data)); } return auData.toArray(new AuthorizationDataEntry[auData.size()]); } else return null; }
Example #7
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 #8
Source File: CCacheInputStream.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
AuthorizationDataEntry[] readAuth() throws IOException { int num, adtype, adlength; num = readLength4(); if (num > 0) { List<AuthorizationDataEntry> auData = new ArrayList<>(); byte[] data = null; for (int i = 0; i < num; i++) { adtype = read(2); adlength = readLength4(); data = IOUtils.readFully(this, adlength, true); auData.add(new AuthorizationDataEntry(adtype, data)); } return auData.toArray(new AuthorizationDataEntry[auData.size()]); } else return null; }
Example #9
Source File: MethodUtil.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private static byte[] getBytes(URL url) throws IOException { URLConnection uc = url.openConnection(); if (uc instanceof java.net.HttpURLConnection) { java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc; int code = huc.getResponseCode(); if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) { throw new IOException("open HTTP connection failed."); } } int len = uc.getContentLength(); InputStream in = new BufferedInputStream(uc.getInputStream()); byte[] b; try { b = IOUtils.readFully(in, len, true); } finally { in.close(); } return b; }
Example #10
Source File: MethodUtil.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static byte[] getBytes(URL url) throws IOException { URLConnection uc = url.openConnection(); if (uc instanceof java.net.HttpURLConnection) { java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc; int code = huc.getResponseCode(); if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) { throw new IOException("open HTTP connection failed."); } } int len = uc.getContentLength(); InputStream in = new BufferedInputStream(uc.getInputStream()); byte[] b; try { b = IOUtils.readFully(in, len, true); } finally { in.close(); } return b; }
Example #11
Source File: TimestampCheck.java From hottub with GNU General Public License v2.0 | 6 votes |
static void checkTimestamp(String file, String policyId, String digestAlg) throws Exception { try (JarFile jf = new JarFile(file)) { JarEntry je = jf.getJarEntry("META-INF/OLD.RSA"); try (InputStream is = jf.getInputStream(je)) { byte[] content = IOUtils.readFully(is, -1, true); PKCS7 p7 = new PKCS7(content); SignerInfo[] si = p7.getSignerInfos(); if (si == null || si.length == 0) { throw new Exception("Not signed"); } PKCS9Attribute p9 = si[0].getUnauthenticatedAttributes() .getAttribute(PKCS9Attribute.SIGNATURE_TIMESTAMP_TOKEN_OID); PKCS7 tsToken = new PKCS7((byte[]) p9.getValue()); TimestampToken tt = new TimestampToken(tsToken.getContentInfo().getData()); if (!tt.getHashAlgorithm().toString().equals(digestAlg)) { throw new Exception("Digest alg different"); } if (!tt.getPolicyID().equals(policyId)) { throw new Exception("policyId different"); } } } }
Example #12
Source File: MethodUtil.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static byte[] getBytes(URL url) throws IOException { URLConnection uc = url.openConnection(); if (uc instanceof java.net.HttpURLConnection) { java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc; int code = huc.getResponseCode(); if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) { throw new IOException("open HTTP connection failed."); } } int len = uc.getContentLength(); try (InputStream in = new BufferedInputStream(uc.getInputStream())) { byte[] b = IOUtils.readAllBytes(in); if (len != -1 && b.length != len) throw new EOFException("Expected:" + len + ", read:" + b.length); return b; } }
Example #13
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 #14
Source File: MethodUtil.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private static byte[] getBytes(URL url) throws IOException { URLConnection uc = url.openConnection(); if (uc instanceof java.net.HttpURLConnection) { java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc; int code = huc.getResponseCode(); if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) { throw new IOException("open HTTP connection failed."); } } int len = uc.getContentLength(); try (InputStream in = new BufferedInputStream(uc.getInputStream())) { byte[] b = IOUtils.readAllBytes(in); if (len != -1 && b.length != len) throw new EOFException("Expected:" + len + ", read:" + b.length); return b; } }
Example #15
Source File: MethodUtil.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static byte[] getBytes(URL url) throws IOException { URLConnection uc = url.openConnection(); if (uc instanceof java.net.HttpURLConnection) { java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc; int code = huc.getResponseCode(); if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) { throw new IOException("open HTTP connection failed."); } } int len = uc.getContentLength(); try (InputStream in = new BufferedInputStream(uc.getInputStream())) { byte[] b = IOUtils.readAllBytes(in); if (len != -1 && b.length != len) throw new EOFException("Expected:" + len + ", read:" + b.length); return b; } }
Example #16
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 #17
Source File: ReadAllBytes.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
static void test(byte[] expectedBytes) throws IOException { int expectedLength = expectedBytes.length; WrapperInputStream in = new WrapperInputStream(new ByteArrayInputStream(expectedBytes)); byte[] readBytes = IOUtils.readAllBytes(in); int x; byte[] tmp = new byte[10]; 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(IOUtils.readAllBytes(in).length == 0, "Expected readAllBytes to return empty byte array"); check(expectedLength == readBytes.length, "Expected length " + expectedLength + ", got " + readBytes.length); check(Arrays.equals(expectedBytes, readBytes), "Expected[" + expectedBytes + "], got:[" + readBytes + "]"); check(!in.isClosed(), "Stream unexpectedly closed"); }
Example #18
Source File: MethodUtil.java From java-n-IDE-for-Android with Apache License 2.0 | 6 votes |
private static byte[] getBytes(URL url) throws IOException { URLConnection uc = url.openConnection(); if (uc instanceof java.net.HttpURLConnection) { java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc; int code = huc.getResponseCode(); if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) { throw new IOException("open HTTP connection failed."); } } int len = uc.getContentLength(); InputStream in = new BufferedInputStream(uc.getInputStream()); byte[] b; try { b = IOUtils.readFully(in, len, true); } finally { in.close(); } return b; }
Example #19
Source File: AppletClassLoader.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private static byte[] getBytes(URL url) throws IOException { URLConnection uc = url.openConnection(); if (uc instanceof java.net.HttpURLConnection) { java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc; int code = huc.getResponseCode(); if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) { throw new IOException("open HTTP connection failed."); } } int len = uc.getContentLength(); // Fixed #4507227: Slow performance to load // class and resources. [stanleyh] // // Use buffered input stream [stanleyh] InputStream in = new BufferedInputStream(uc.getInputStream()); byte[] b; try { b = IOUtils.readFully(in, len, true); } finally { in.close(); } return b; }
Example #20
Source File: ReadAllBytes.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
static void test(byte[] expectedBytes) throws IOException { int expectedLength = expectedBytes.length; WrapperInputStream in = new WrapperInputStream(new ByteArrayInputStream(expectedBytes)); byte[] readBytes = IOUtils.readAllBytes(in); int x; byte[] tmp = new byte[10]; 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(IOUtils.readAllBytes(in).length == 0, "Expected readAllBytes to return empty byte array"); check(expectedLength == readBytes.length, "Expected length " + expectedLength + ", got " + readBytes.length); check(Arrays.equals(expectedBytes, readBytes), "Expected[" + expectedBytes + "], got:[" + readBytes + "]"); check(!in.isClosed(), "Stream unexpectedly closed"); }
Example #21
Source File: MethodUtil.java From javaide with GNU General Public License v3.0 | 6 votes |
private static byte[] getBytes(URL url) throws IOException { URLConnection uc = url.openConnection(); if (uc instanceof java.net.HttpURLConnection) { java.net.HttpURLConnection huc = (java.net.HttpURLConnection) uc; int code = huc.getResponseCode(); if (code >= java.net.HttpURLConnection.HTTP_BAD_REQUEST) { throw new IOException("open HTTP connection failed."); } } int len = uc.getContentLength(); InputStream in = new BufferedInputStream(uc.getInputStream()); byte[] b; try { b = IOUtils.readFully(in, len, true); } finally { in.close(); } return b; }
Example #22
Source File: NetClient.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
@Override public byte[] receive() throws IOException { byte[] lenField = new byte[4]; int count = readFully(lenField, 4); if (count != 4) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient could not read length field"); } return null; } int len = networkByteOrderToInt(lenField, 0, 4); if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient reading " + len + " bytes"); } if (len <= 0) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient zero or negative length field: "+len); } return null; } try { return IOUtils.readExactlyNBytes(in, len); } catch (IOException ioe) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient could not read complete packet (" + len + "/" + count + ")"); } return null; } }
Example #23
Source File: CCacheInputStream.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
EncryptionKey readKey(int version) throws IOException { int keyType, keyLen; keyType = read(2); if (version == KRB5_FCC_FVNO_3) read(2); /* keytype recorded twice in fvno 3 */ keyLen = readLength4(); byte[] bytes = IOUtils.readExactlyNBytes(this, keyLen); return new EncryptionKey(bytes, keyType, new Integer(version)); }
Example #24
Source File: NetClient.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
@Override public byte[] receive() throws IOException { byte[] lenField = new byte[4]; int count = readFully(lenField, 4); if (count != 4) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient could not read length field"); } return null; } int len = networkByteOrderToInt(lenField, 0, 4); if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient reading " + len + " bytes"); } if (len <= 0) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient zero or negative length field: "+len); } return null; } try { return IOUtils.readFully(in, len, true); } catch (IOException ioe) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient could not read complete packet (" + len + "/" + count + ")"); } return null; } }
Example #25
Source File: CCacheInputStream.java From hottub with GNU General Public License v2.0 | 5 votes |
EncryptionKey readKey(int version) throws IOException { int keyType, keyLen; keyType = read(2); if (version == KRB5_FCC_FVNO_3) read(2); /* keytype recorded twice in fvno 3 */ keyLen = readLength4(); byte[] bytes = IOUtils.readFully(this, keyLen, true); return new EncryptionKey(bytes, keyType, new Integer(version)); }
Example #26
Source File: NetClient.java From openjdk-8-source with GNU General Public License v2.0 | 5 votes |
@Override public byte[] receive() throws IOException { byte[] lenField = new byte[4]; int count = readFully(lenField, 4); if (count != 4) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient could not read length field"); } return null; } int len = networkByteOrderToInt(lenField, 0, 4); if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient reading " + len + " bytes"); } if (len <= 0) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient zero or negative length field: "+len); } return null; } try { return IOUtils.readFully(in, len, true); } catch (IOException ioe) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient could not read complete packet (" + len + "/" + count + ")"); } return null; } }
Example #27
Source File: CertificateRevokedException.java From openjdk-jdk8u 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.readExactlyNBytes(ois, ois.readInt()); Extension ext = sun.security.x509.Extension.newExtension (new ObjectIdentifier(oid), critical, extVal); extensions.put(oid, ext); } }
Example #28
Source File: NetClient.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
@Override public byte[] receive() throws IOException { byte[] lenField = new byte[4]; int count = readFully(lenField, 4); if (count != 4) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient could not read length field"); } return null; } int len = networkByteOrderToInt(lenField, 0, 4); if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient reading " + len + " bytes"); } if (len <= 0) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient zero or negative length field: "+len); } return null; } try { return IOUtils.readFully(in, len, true); } catch (IOException ioe) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient could not read complete packet (" + len + "/" + count + ")"); } return null; } }
Example #29
Source File: NetClient.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
@Override public byte[] receive() throws IOException { byte[] lenField = new byte[4]; int count = readFully(lenField, 4); if (count != 4) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient could not read length field"); } return null; } int len = networkByteOrderToInt(lenField, 0, 4); if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient reading " + len + " bytes"); } if (len <= 0) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient zero or negative length field: "+len); } return null; } try { return IOUtils.readFully(in, len, true); } catch (IOException ioe) { if (Krb5.DEBUG) { System.out.println( ">>>DEBUG: TCPClient could not read complete packet (" + len + "/" + count + ")"); } return null; } }
Example #30
Source File: AnonymousClassLoader.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
public static byte[] readClassFile(Class<?> templateClass) throws IOException { String templateName = templateClass.getName(); int lastDot = templateName.lastIndexOf('.'); java.net.URL url = templateClass.getResource(templateName.substring(lastDot+1)+".class"); java.net.URLConnection connection = url.openConnection(); int contentLength = connection.getContentLength(); if (contentLength < 0) throw new IOException("invalid content length "+contentLength); return IOUtils.readFully(connection.getInputStream(), contentLength, true); }