当前位置: 首页>>代码示例>>Java>>正文


Java InputStream.readAllBytes方法代码示例

本文整理汇总了Java中java.io.InputStream.readAllBytes方法的典型用法代码示例。如果您正苦于以下问题:Java InputStream.readAllBytes方法的具体用法?Java InputStream.readAllBytes怎么用?Java InputStream.readAllBytes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.InputStream的用法示例。


在下文中一共展示了InputStream.readAllBytes方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handle

import java.io.InputStream; //导入方法依赖的package包/类
@Override
public void handle(HttpExchange he) throws IOException {
    String method = he.getRequestMethod();
    InputStream is = he.getRequestBody();
    if (method.equalsIgnoreCase("POST")) {
        String requestBody = new String(is.readAllBytes(), US_ASCII);
        if (!requestBody.equals(POST_BODY)) {
            he.sendResponseHeaders(500, -1);
            ok = false;
        } else {
            he.sendResponseHeaders(200, -1);
            ok = true;
        }
    } else { // GET
        he.sendResponseHeaders(200, RESPONSE.length());
        OutputStream os = he.getResponseBody();
        os.write(RESPONSE.getBytes(US_ASCII));
        os.close();
        ok = true;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:22,代码来源:BasicAuthTest.java

示例2: getASLResource

import java.io.InputStream; //导入方法依赖的package包/类
private ASL getASLResource(String resourceName) throws IOException {
    InputStream definition = getClass().getClassLoader().getResourceAsStream(resourceName);
    if(definition == null) {
        throw new RuntimeException("machine.json not found");
    }

    byte[] jsonData = definition.readAllBytes();
    return objectMapper.readValue(jsonData, ASL.class);
}
 
开发者ID:fnproject,项目名称:flow-stages,代码行数:10,代码来源:Stages.java

示例3: getBytes

import java.io.InputStream; //导入方法依赖的package包/类
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 = in.readAllBytes();
        if (len != -1 && b.length != len)
            throw new EOFException("Expected:" + len + ", read:" + b.length);
    } finally {
        in.close();
    }
    return b;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:28,代码来源:AppletClassLoader.java

示例4: premain

import java.io.InputStream; //导入方法依赖的package包/类
public static void premain(String agentArgs, final Instrumentation inst) throws Exception {
    String s = agentArgs.substring(0, agentArgs.indexOf(".class"));
    clz = Class.forName(s.replace('/', '.'));
    InputStream in;
    Module m = clz.getModule();
    if (m != null) {
        in = m.getResourceAsStream(agentArgs);
    } else {
        ClassLoader loader =
            RedefineClassWithNativeMethodAgent.class.getClassLoader();
        in = loader.getResourceAsStream(agentArgs);
    }
    if (in == null) {
        throw new Exception("Cannot find class: " + agentArgs);
    }
    byte[] buffer = in.readAllBytes();

    new Timer(true).schedule(new TimerTask() {
        public void run() {
            try {
                System.out.println("Instrumenting");
                ClassDefinition cld = new ClassDefinition(clz, buffer);
                inst.redefineClasses(new ClassDefinition[] { cld });
            }
            catch (Exception e) { e.printStackTrace(); }
        }
    }, 500);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:29,代码来源:RedefineClassWithNativeMethodAgent.java


注:本文中的java.io.InputStream.readAllBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。