本文整理了Java中org.apache.cxf.helpers.IOUtils
类的一些代码示例,展示了IOUtils
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils
类的具体详情如下:
包路径:org.apache.cxf.helpers.IOUtils
类名称:IOUtils
暂无
代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-jaxws
try {
if (src.getInputStream() != null) {
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(2048)) {
IOUtils.copy(src.getInputStream(), bos, 1024);
ds = new ByteDataSource(bos.toByteArray(), ct);
ds = new ByteDataSource(IOUtils.toString(src.getReader()).getBytes(StandardCharsets.UTF_8),
ct);
throw new Fault(e);
ByteArrayOutputStream bwriter = new ByteArrayOutputStream();
XMLStreamWriter writer = null;
try {
ds = new ByteDataSource(bwriter.toByteArray(), ct);
} catch (XMLStreamException e1) {
throw new Fault(e1);
} finally {
StaxUtils.close(writer);
代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-jaxws
if (a.getId().startsWith(start)) {
DataHandler dh = a.getDataHandler();
String ct = dh.getContentType();
Object o = null;
Class<?> typeClass = mpi.getTypeClass();
try {
o = dh.getContent();
} catch (IOException e) {
throw new Fault(e);
o = IOUtils.readBytesFromStream(dh.getInputStream());
} catch (IOException e) {
throw new Fault(e);
o = ImageIO.read(dh.getInputStream());
} catch (IOException e) {
throw new Fault(e);
代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http
protected void serveStaticContent(HttpServletRequest request,
HttpServletResponse response,
String pathInfo) throws ServletException {
InputStream is = getResourceAsStream(pathInfo);
if (is == null) {
throw new ServletException("Static resource " + pathInfo + " is not available");
}
try {
int ind = pathInfo.lastIndexOf(".");
if (ind != -1 && ind < pathInfo.length()) {
String type = getStaticResourceContentType(pathInfo.substring(ind + 1));
if (type != null) {
response.setContentType(type);
}
}
String cacheControl = getServletConfig().getInitParameter(STATIC_CACHE_CONTROL);
if (cacheControl != null) {
response.setHeader("Cache-Control", cacheControl.trim());
}
ServletOutputStream os = response.getOutputStream();
IOUtils.copyAndCloseInput(is, os);
os.flush();
} catch (IOException ex) {
throw new ServletException("Static resource " + pathInfo
+ " can not be written to the output stream");
}
}
代码示例来源:origin: apache/cxf
public static byte[] readBytesFromStream(InputStream in) throws IOException {
int i = in.available();
if (i < DEFAULT_BUFFER_SIZE) {
i = DEFAULT_BUFFER_SIZE;
}
try (ByteArrayOutputStream bos = new ByteArrayOutputStream(i)) {
copy(in, bos);
return bos.toByteArray();
} finally {
in.close();
}
}
}
代码示例来源:origin: apache/cxf
@Override
public byte[] getAttachmentAsByteArray(String contentId) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
InputStream is = AttachmentUtil.getAttachmentDataSource(contentId, attachments)
.getInputStream();
IOUtils.copy(is, bos);
is.close();
bos.close();
} catch (IOException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("ATTACHMENT_READ_ERROR", LOG), e);
}
return bos.toByteArray();
}
代码示例来源:origin: org.apache.cxf/cxf-rt-core
public byte[] invokeBytes(String address, String transport, String message) throws Exception {
EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
ei.setAddress(address);
ConduitInitiatorManager conduitMgr = getBus().getExtension(ConduitInitiatorManager.class);
ConduitInitiator conduitInit = conduitMgr.getConduitInitiator(transport);
Conduit conduit = conduitInit.getConduit(ei);
TestMessageObserver obs = new TestMessageObserver();
conduit.setMessageObserver(obs);
Message m = new MessageImpl();
conduit.prepare(m);
OutputStream os = m.getContent(OutputStream.class);
InputStream is = getResourceAsStream(message);
if (is == null) {
throw new RuntimeException("Could not find resource " + message);
}
IOUtils.copy(is, os);
// TODO: shouldn't have to do this. IO caching needs cleaning
// up or possibly removal...
os.flush();
is.close();
os.close();
byte[] bs = obs.getResponseStream().toByteArray();
return bs;
}
public byte[] invokeBytes(String address, String transport, byte[] message) throws Exception {
代码示例来源:origin: apache/cxf
@Override
protected byte[] getBytes(Object object) {
DataSource dataSource = (DataSource) object;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
IOUtils.copyAndCloseInput(dataSource.getInputStream(), baos);
} catch (IOException e) {
throw new RuntimeException(e);
}
return baos.toByteArray();
}
}
代码示例来源:origin: apache/cxf
/**
* Read the entire original input stream and cache it. Useful
* if switching threads or doing something where the original
* stream may not be valid by the time the next read() occurs
*/
public void cacheInput() {
if (!cached) {
CachedOutputStream cache = new CachedOutputStream();
try {
InputStream origIn = in;
IOUtils.copy(in, cache);
if (cache.size() > 0) {
in = cache.getInputStream();
} else {
in = new ByteArrayInputStream(new byte[0]);
}
cache.close();
origIn.close();
} catch (IOException e) {
//ignore
}
cached = true;
}
}
代码示例来源:origin: org.apache.cxf/cxf-testutils
public void onMessage(Message message) {
try {
contentType = (String)message.get(Message.CONTENT_TYPE);
InputStream is = message.getContent(InputStream.class);
try {
IOUtils.copy(is, response);
is.close();
response.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
} finally {
synchronized (this) {
written = true;
notifyAll();
}
}
}
}
代码示例来源:origin: apache/cxf
public static String readBody(InputStream is, String encoding) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
IOUtils.copy(is, bos, 1024);
return new String(bos.toByteArray(), encoding);
} catch (Exception ex) {
throw ExceptionUtils.toInternalServerErrorException(ex, null);
}
}
代码示例来源:origin: apache/cxf
/**
* Copied from LoggingInInterceptor
*
* @param soapMessage
*/
private void getSoapRequest(Message soapMessage, ExchangeData exchange) {
InputStream is = soapMessage.getContent(InputStream.class);
if (is != null) {
CachedOutputStream bos = new CachedOutputStream();
try {
IOUtils.copy(is, bos);
bos.flush();
is.close();
soapMessage.setContent(InputStream.class, bos.getInputStream());
StringBuilder builder = new StringBuilder();
bos.writeCacheTo(builder, bos.size());
bos.close();
exchange.setRequest(builder.toString());
exchange.setRequestSize((int)bos.size());
} catch (IOException e) {
throw new Fault(e);
}
}
}
代码示例来源:origin: apache/cxf
public void echoData(Holder<String> text, Holder<DataHandler> data) {
try {
InputStream bis = null;
bis = data.value.getDataSource().getInputStream();
byte[] b = new byte[6];
bis.read(b, 0, 6);
String string = IOUtils.newStringFromBytes(b);
ByteArrayDataSource source =
new ByteArrayDataSource(("test" + string).getBytes(), "application/octet-stream");
data.value = new DataHandler(source);
} catch (IOException e) {
e.printStackTrace();
}
}
代码示例来源:origin: org.apache.cxf/cxf-rt-frontend-jaxws
public void handleMessage(Message message) throws Fault {
BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();
if (bop != null && !bindingName.equals(bop.getBinding().getName())) {
return;
} else if (DataSource.class.isAssignableFrom(type)) {
deser.initializeAttachments();
} catch (IOException ex) {
throw new Fault(ex);
try {
InputStream in = ds.getInputStream();
IOUtils.copy(in, out);
in.close();
out.flush();
out.close();
} catch (IOException e) {
throw new Fault(e);
out = new CachedOutputStream();
ds = new DOMSource(StaxUtils.read(ds));
} catch (XMLStreamException e) {
throw new Fault(e);
代码示例来源:origin: apache/cxf
public static int copyAndCloseInput(final InputStream input,
final OutputStream output) throws IOException {
try {
return copy(input, output);
} finally {
input.close();
}
}
代码示例来源:origin: apache/cxf
public byte[] getBytes() throws IOException {
flush();
if (inmem) {
if (currentStream instanceof ByteArrayOutputStream) {
return ((ByteArrayOutputStream)currentStream).toByteArray();
}
throw new IOException("Unknown format of currentStream");
}
// read the file
try (InputStream fin = createInputStream(tempFile)) {
return IOUtils.readBytesFromStream(fin);
}
}
代码示例来源:origin: org.apache.camel/camel-cxf
public static String getStringFromInputStream(InputStream in) throws Exception {
CachedOutputStream bos = new CachedOutputStream();
IOUtils.copy(in, bos);
in.close();
bos.close();
return bos.getOut().toString();
}
代码示例来源:origin: apache/cxf
public void onMessage(Message message) {
try {
// HTTP seems to need this right now...
ExchangeImpl ex = new ExchangeImpl();
ex.setInMessage(message);
Conduit backChannel = message.getDestination().getBackChannel(message);
MessageImpl res = new MessageImpl();
ex.setOutMessage(res);
res.put(Message.CONTENT_TYPE, "text/xml");
backChannel.prepare(res);
OutputStream out = res.getContent(OutputStream.class);
InputStream is = resource.openStream();
IOUtils.copy(is, out, 2048);
out.flush();
out.close();
is.close();
backChannel.close(res);
} catch (Exception e) {
e.printStackTrace();
}
}
代码示例来源:origin: org.apache.cxf/cxf-core
public static String toString(final InputStream input, int bufferSize, String charset)
throws IOException {
int avail = input.available();
if (avail > bufferSize) {
bufferSize = avail;
}
Reader reader = charset == null ? new InputStreamReader(input, UTF8_CHARSET)
: new InputStreamReader(input, charset);
return toString(reader, bufferSize);
}
代码示例来源:origin: org.apache.cxf/cxf-rt-transports-http
inMessage.setExchange(new ExchangeImpl());
inMessage.getExchange().put(Bus.class, bus);
inMessage.put(Message.DECOUPLED_CHANNEL_MESSAGE, Boolean.TRUE);
InputStream in = inMessage.getContent(InputStream.class);
if (in != null) {
CachedOutputStream cos = new CachedOutputStream();
IOUtils.copy(in, cos);
inMessage.setContent(InputStream.class, cos.getInputStream());
代码示例来源:origin: org.apache.cxf/cxf-api
public void writeCacheTo(OutputStream out) throws IOException {
flush();
if (inmem) {
if (currentStream instanceof ByteArrayOutputStream) {
((ByteArrayOutputStream)currentStream).writeTo(out);
} else {
throw new IOException("Unknown format of currentStream");
}
} else {
// read the file
InputStream fin = createInputStream(tempFile);
IOUtils.copyAndCloseInput(fin, out);
}
}
内容来源于网络,如有侵权,请联系作者删除!