本文整理汇总了Java中org.apache.axiom.attachments.utils.IOUtils.getStreamAsByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.getStreamAsByteArray方法的具体用法?Java IOUtils.getStreamAsByteArray怎么用?Java IOUtils.getStreamAsByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.axiom.attachments.utils.IOUtils
的用法示例。
在下文中一共展示了IOUtils.getStreamAsByteArray方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBytes
import org.apache.axiom.attachments.utils.IOUtils; //导入方法依赖的package包/类
/**
* Get a specific entry's content as a byte array
*
* @param in
* @param resource
* @return
* @throws Exception
*/
private byte[] getBytes(InputStream in, String resource) throws Exception {
ZipInputStream zin = new ZipInputStream(in);
ZipEntry entry;
String entryName;
while ((entry = zin.getNextEntry()) != null) {
entryName = entry.getName();
if (entryName != null &&
entryName.endsWith(resource)) {
byte[] raw = IOUtils.getStreamAsByteArray(zin);
zin.close();
return raw;
}
}
return null;
}
示例2: testretByteArray
import org.apache.axiom.attachments.utils.IOUtils; //导入方法依赖的package包/类
/**
* Auto generated test method
*/
public void testretByteArray() throws java.lang.Exception {
byte[] input = new byte[]{(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF};
ComplexDataTypesDocLitBareStub.RetByteArray req = new ComplexDataTypesDocLitBareStub.RetByteArray();
req.setInByteArray(new DataHandler(new ByteArrayDataSource(input)));
DataHandler ret = stub.retByteArray(req).get_return();
byte[] bytes = IOUtils.getStreamAsByteArray(ret.getInputStream());
assertTrue(Arrays.equals(bytes, input));
}
示例3: testretByteArray
import org.apache.axiom.attachments.utils.IOUtils; //导入方法依赖的package包/类
/**
* Auto generated test method
*/
public void testretByteArray() throws java.lang.Exception {
byte[] input = new byte[]{(byte) 0xDE, (byte) 0xAD, (byte) 0xBE, (byte) 0xEF};
DataHandler ret = stub.retByteArray(new DataHandler(new ByteArrayDataSource(input)));
byte[] bytes = IOUtils.getStreamAsByteArray(ret.getInputStream());
assertTrue(Arrays.equals(bytes, input));
}
示例4: getStringFromDatahandler
import org.apache.axiom.attachments.utils.IOUtils; //导入方法依赖的package包/类
/**
* Converts the given .datahandler to a string
*
* @return string
*/
public static String getStringFromDatahandler(DataHandler dataHandler) {
try {
InputStream inStream;
if (dataHandler == null) {
return "";
}
inStream = dataHandler.getDataSource().getInputStream();
byte[] data = IOUtils.getStreamAsByteArray(inStream);
return Base64.encode(data);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例5: findResource
import org.apache.axiom.attachments.utils.IOUtils; //导入方法依赖的package包/类
/**
* Finds the resource with the specified name on the URL search path.
*
* @param resource the name of the resource
* @return a <code>URL</code> for the resource, or <code>null</code>
* if the resource could not be found.
*/
public URL findResource(String resource) {
URL url = super.findResource(resource);
if (url == null) {
for (int i = 0; embedded_jars != null && i < embedded_jars.size(); i++) {
String libjar_name = (String) embedded_jars.get(i);
try {
InputStream in = getJarAsStream(libjar_name);
ZipInputStream zin = new ZipInputStream(in);
ZipEntry entry;
String entryName;
while ((entry = zin.getNextEntry()) != null) {
entryName = entry.getName();
if (entryName != null &&
entryName.endsWith(resource)) {
byte[] raw = IOUtils.getStreamAsByteArray(zin);
return new URL("jar", "", -1, urls[0] + "!/" + libjar_name + "!/" + entryName,
new ByteUrlStreamHandler(raw));
}
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}
return url;
}
示例6: findResources
import org.apache.axiom.attachments.utils.IOUtils; //导入方法依赖的package包/类
/**
* Returns an Enumeration of URLs representing all of the resources
* on the URL search path having the specified name.
*
* @param resource the resource name
* @exception IOException if an I/O exception occurs
* @return an <code>Enumeration</code> of <code>URL</code>s
*/
public Enumeration findResources(String resource) throws IOException {
ArrayList resources = new ArrayList();
Enumeration e = super.findResources(resource);
while (e.hasMoreElements()) {
resources.add(e.nextElement());
}
for (int i = 0; embedded_jars != null && i < embedded_jars.size(); i++) {
String libjar_name = (String) embedded_jars.get(i);
try {
InputStream in = getJarAsStream(libjar_name);
ZipInputStream zin = new ZipInputStream(in);
ZipEntry entry;
String entryName;
while ((entry = zin.getNextEntry()) != null) {
entryName = entry.getName();
if (entryName != null &&
entryName.endsWith(resource)) {
byte[] raw = IOUtils.getStreamAsByteArray(zin);
resources.add(new URL("jar", "", -1, urls[0] + "!/" + libjar_name + "!/" + entryName,
new ByteUrlStreamHandler(raw)));
}
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
return Collections.enumeration(resources);
}
示例7: testSetBase64Content
import org.apache.axiom.attachments.utils.IOUtils; //导入方法依赖的package包/类
@Validated @Test
public void testSetBase64Content() {
try {
MessageFactory factory = MessageFactory.newInstance();
SOAPMessage msg = factory.createMessage();
AttachmentPart ap = msg.createAttachmentPart();
String urlString = "http://ws.apache.org/images/project-logo.jpg";
if (isNetworkedResourceAvailable(urlString)) {
URL url = new URL(urlString);
DataHandler dh = new DataHandler(url);
//Create InputStream from DataHandler's InputStream
InputStream is = dh.getInputStream();
byte buf[] = IOUtils.getStreamAsByteArray(is);
//Setting Content via InputStream for image/jpeg mime type
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Base64.encode(buf, 0, buf.length, bos);
buf = bos.toByteArray();
InputStream stream = new ByteArrayInputStream(buf);
ap.setBase64Content(stream, "image/jpeg");
//Getting Content.. should return InputStream object
InputStream r = ap.getBase64Content();
if (r != null) {
if (r instanceof InputStream) {
//InputStream object was returned (ok)
} else {
fail("Unexpected object was returned");
}
}
}
} catch (Exception e) {
fail("Exception: " + e);
}
}