Java 类sun.misc.IOUtils 实例源码

项目:influx-jmh-reporter    文件:CommandLineArgs.java   
private static String getHostName()
{
    String hostname = System.getenv().get("HOSTNAME");
    if (hostname == null)
    {
        try
        {
            final Process hostnameProcess = Runtime.getRuntime().exec("hostname");
            final String processOutput = new String(IOUtils.readFully(hostnameProcess.getInputStream(), Integer.MAX_VALUE, false), StandardCharsets.US_ASCII);
            hostname = processOutput.replace("\n", "").replace("\r", "").trim();
        }
        catch (final IOException ignored)
        {
            //ignored
        }
    }
    return hostname;
}
项目:GraphiteMappings    文件:MappingsBase.java   
private List<ClassNode> indexJar() {
    ArrayList<ClassNode> classNodes = new ArrayList<ClassNode>();
    Enumeration<JarEntry> enumeration = jarFile.entries();
    while (enumeration.hasMoreElements()) {
        JarEntry jarEntry = enumeration.nextElement();
        if (jarEntry != null) {
            if (jarEntry.getName().endsWith(".class")) {
                try {
                    byte[] classBytes = IOUtils.readFully(jarFile.getInputStream(jarEntry), -1,
                            false);
                    ClassReader classReader = new ClassReader(classBytes);
                    ClassNode classNode = new ClassNode();
                    classReader.accept(classNode, 0);
                    classNodes.add(classNode);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return classNodes;
}
项目:Passion    文件:AsmMethodTest.java   
@Test
public void asmTest() throws Exception {
    JvmClass jvmClass = new JvmClass(IOUtils.readFully(getClass().getClassLoader()
            .getResourceAsStream("passion/test/AsmMethodTest$ExampleClass.class"), -1,
            false));
    jvmClass.getMethods().forEach((bytecodeMethod -> {
        if (bytecodeMethod.asm().name.equals("meow") && bytecodeMethod.getDescriptor()
                .getArguments().length == 0) {
            System.out.println("Found meow");
            bytecodeMethod.getInvocations().forEach((invocation -> System.out.println("Invoke: " + invocation.getOwner().jvm() + ": " +
                    invocation.getName() + ": " + invocation.getDescriptor()
                    .getReturnType().jvm())));
            Invocation invoke = Invocation.invokeStatic(bytecodeMethod, OtherClass.class
                    .getName(), "ok", "()V");
            bytecodeMethod.injectAllEndpoints(invoke, false);
        }
    }));
    File output = new File("output.class");
    System.out.println("output = " + output.getAbsolutePath());
    jvmClass.toFile(output);
}
项目:javaide    文件:MethodUtil.java   
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;
}
项目:OpenJSharp    文件:CCacheInputStream.java   
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;
}
项目:OpenJSharp    文件:MethodUtil.java   
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;
}
项目:OpenJSharp    文件:AppletClassLoader.java   
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;
}
项目:jdk8u-jdk    文件:CCacheInputStream.java   
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;
}
项目:jdk8u-jdk    文件:MethodUtil.java   
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;
}
项目:jdk8u-jdk    文件:AppletClassLoader.java   
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;
}
项目:jdk8u-jdk    文件:TimestampCheck.java   
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");
            }
        }
    }
}
项目:jdk8u_jdk    文件:CCacheInputStream.java   
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;
}
项目:jdk8u_jdk    文件:MethodUtil.java   
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;
}
项目:jdk8u_jdk    文件:AppletClassLoader.java   
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;
}
项目:jdk8u_jdk    文件:TimestampCheck.java   
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");
            }
        }
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:CCacheInputStream.java   
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;
}
项目:lookaside_java-1.8.0-openjdk    文件:MethodUtil.java   
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;
}
项目:lookaside_java-1.8.0-openjdk    文件:AppletClassLoader.java   
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;
}
项目:lookaside_java-1.8.0-openjdk    文件:TimestampCheck.java   
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");
            }
        }
    }
}
项目:infobip-open-jdk-8    文件:CCacheInputStream.java   
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;
}
项目:infobip-open-jdk-8    文件:MethodUtil.java   
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;
}
项目:infobip-open-jdk-8    文件:AppletClassLoader.java   
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;
}
项目:jdk8u-dev-jdk    文件:CCacheInputStream.java   
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;
}
项目:jdk8u-dev-jdk    文件:MethodUtil.java   
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;
}
项目:jdk8u-dev-jdk    文件:AppletClassLoader.java   
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;
}
项目:jdk7-jdk    文件:MethodUtil.java   
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;
}
项目:jdk7-jdk    文件:AppletClassLoader.java   
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;
}
项目:openjdk-source-code-learn    文件:MethodUtil.java   
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;
}
项目:openjdk-source-code-learn    文件:AppletClassLoader.java   
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;
}
项目:OLD-OpenJDK8    文件:MethodUtil.java   
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;
}
项目:OLD-OpenJDK8    文件:AppletClassLoader.java   
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;
}
项目:openjdk-jdk7u-jdk    文件:MethodUtil.java   
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;
}
项目:openjdk-jdk7u-jdk    文件:AppletClassLoader.java   
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;
}
项目:robovm-jfx78-compat    文件:MethodUtil.java   
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;
}
项目:openjdk-icedtea7    文件:MethodUtil.java   
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;
}
项目:openjdk-icedtea7    文件:AppletClassLoader.java   
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;
}
项目:Invasion    文件:Client.java   
/**
 * Method which is called at the beginning of the client's communication
 *
 * Communicates with Server.ClientChecker
 *
 * Reads initData; mapsize, this client's id, and current state of the sections
 * @throws IOException if communication fails
 */
private static void initGame() throws IOException {
    DataInputStream in = new DataInputStream(CLIENT.getInputStream());
    PrintStream out = new PrintStream(CLIENT.getOutputStream());

    // write requestType
    out.println(Server.CONST_PLAY);
    System.out.println("DBG:Play");

    // write requested map
    out.println(_MAP);
    System.out.println("DBG:Map");

    // read gameData

    // mapsize
    mapsize = in.readInt();
    System.out.println("DBG:Size "+mapsize);

    // clientId
    clientId = in.readInt();
    System.out.println("DBG:id "+clientId);
    // amount of bytes that will be read, state
    int stateCount = in.readInt();
    System.out.println("DBG:stateLength "+stateCount);

    // read stateData
    byte[] stateData = IOUtils.readFully(in, stateCount, true);
    System.out.println("DBG:StateData\n"+Arrays.toString(stateData));


    // init CLIENT_GUI
    CLIENT_GUI = new ClientGUI(mapsize, stateData);
    CLIENT_GUI.setTitle(ManagementFactory.getRuntimeMXBean().getName()+"  Map: "+_MAP+"  ID:"+clientId);

    // tells server that client is ready
    out.write(1);
    System.out.println("DBG:Confirmed");
}
项目:backup    文件:ContentProviderBackupComponent.java   
@Override
public int sendBackupData(int numBytes) {

    if (backupState == null) {
        Log.e(TAG, "Attempted sendBackupData() before performFullBackup()");
        return TRANSPORT_ERROR;
    }

    long bytesTransferred = backupState.getBytesTransferred() + numBytes;

    if (bytesTransferred > configuration.getBackupSizeQuota()) {
        return TRANSPORT_QUOTA_EXCEEDED;
    }

    InputStream inputStream = backupState.getInputStream();
    ZipOutputStream outputStream = backupState.getOutputStream();

    try {
        outputStream.write(IOUtils.readFully(inputStream, numBytes, true));
        backupState.setBytesTransferred(bytesTransferred);

    } catch (IOException ex) {
        Log.e(TAG, "Error handling backup data for " + backupState.getPackageName() + ": ", ex);
        return TRANSPORT_ERROR;
    }
    return TRANSPORT_OK;
}
项目:OpenJSharp    文件:CCacheInputStream.java   
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));
}
项目:OpenJSharp    文件:CCacheInputStream.java   
byte[] readData() throws IOException {
    int length;
    length = readLength4();
    if (length == 0) {
        return null;
    } else {
        return IOUtils.readFully(this, length, true);
    }
}