本文整理汇总了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;
}
}
示例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);
}
示例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;
}
示例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);
}