本文整理汇总了Java中org.jboss.gravia.utils.IOUtils.copyStream方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.copyStream方法的具体用法?Java IOUtils.copyStream怎么用?Java IOUtils.copyStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jboss.gravia.utils.IOUtils
的用法示例。
在下文中一共展示了IOUtils.copyStream方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testURLHandlerService
import org.jboss.gravia.utils.IOUtils; //导入方法依赖的package包/类
@Test
public void testURLHandlerService() throws Exception {
try {
new URL("foo://hi");
Assert.fail("No handler registered. Should throw a MalformedURLException.");
} catch (MalformedURLException mue) {
// expected
}
Runtime runtime = RuntimeLocator.getRequiredRuntime();
ModuleContext syscontext = runtime.getModuleContext();
Dictionary<String, Object> props = new Hashtable<>();
props.put(Constants.URL_HANDLER_PROTOCOL, "foo");
ServiceRegistration<URLStreamHandler> sreg = syscontext.registerService(URLStreamHandler.class, new MyHandler(), props);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copyStream(new URL("foo://somehost").openStream(), baos);
Assert.assertEquals("somehost", new String(baos.toByteArray()));
URL url = new URL("foo:///somepath");
Assert.assertEquals("", url.getHost());
} finally {
sreg.unregister();
}
try {
new URL("foo://hi").openConnection();
Assert.fail("No handler registered any more.");
} catch (IOException ex) {
// expected
}
}
示例2: before
import org.jboss.gravia.utils.IOUtils; //导入方法依赖的package包/类
@Before
public void before() throws Exception {
FileUtils.deleteDirectory(REPO_PATH);
REPO_PATH.toFile().mkdirs();
File configFile = REPO_PATH.resolve("repository-simple-security.xml").toFile();
InputStream input = getClass().getClassLoader().getResourceAsStream("jcr/repository-simple-security.xml");
try (OutputStream output = new FileOutputStream(configFile)) {
IOUtils.copyStream(input, output);
}
repository = new TransientRepository(configFile, REPO_PATH.toFile());
}
示例3: getByteArrayPayload
import org.jboss.gravia.utils.IOUtils; //导入方法依赖的package包/类
public byte[] getByteArrayPayload(String resName) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (InputStream ins = getClass().getClassLoader().getResourceAsStream(resName)) {
IOUtils.copyStream(ins, baos);
}
return baos.toByteArray();
}
示例4: getResourceValue
import org.jboss.gravia.utils.IOUtils; //导入方法依赖的package包/类
public static String getResourceValue (Class<?> clazz, String resname) throws IOException {
try (InputStream in = clazz.getResourceAsStream(resname)) {
IllegalStateAssertion.assertNotNull(in, "Cannot find resource: " + resname);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copyStream(in, out);
return new String(out.toByteArray());
}
}
示例5: testURLHandlerService
import org.jboss.gravia.utils.IOUtils; //导入方法依赖的package包/类
@Test
public void testURLHandlerService() throws Exception {
try {
new URL("foo://hi");
Assert.fail("No handler registered. Should throw a MalformedURLException.");
} catch (MalformedURLException mue) {
// expected
}
Runtime runtime = RuntimeLocator.getRequiredRuntime();
ModuleContext syscontext = runtime.getModuleContext();
Dictionary<String, Object> props = new Hashtable<>();
props.put(Constants.URL_HANDLER_PROTOCOL, "foo");
ServiceRegistration<URLStreamHandler> sreg = syscontext.registerService(URLStreamHandler.class, new MyHandler(), props);
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOUtils.copyStream(new URL("foo://somehost").openStream(), baos);
Assert.assertEquals("somehost", new String(baos.toByteArray()));
} finally {
sreg.unregister();
}
try {
new URL("foo://hi").openConnection();
Assert.fail("No handler registered any more.");
} catch (IOException ex) {
// expected
}
}
示例6: readCustomerXml
import org.jboss.gravia.utils.IOUtils; //导入方法依赖的package包/类
private String readCustomerXml(String xmlpath) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copyStream(getClass().getResourceAsStream(xmlpath), out);
return new String(out.toByteArray());
}