use of org.apache.cxf.helpers.LoadingByteArrayOutputStream in project cxf by apache.
the class CachedOutputStream method getInputStream.
public InputStream getInputStream() throws IOException {
flush();
if (inmem) {
if (currentStream instanceof LoadingByteArrayOutputStream) {
return ((LoadingByteArrayOutputStream) currentStream).createInputStream();
} else if (currentStream instanceof ByteArrayOutputStream) {
return new ByteArrayInputStream(((ByteArrayOutputStream) currentStream).toByteArray());
} else {
return null;
}
}
try {
InputStream fileInputStream = new TransferableFileInputStream(tempFile);
streamList.add(fileInputStream);
if (cipherTransformation != null) {
fileInputStream = new CipherInputStream(fileInputStream, ciphers.getDecryptor()) {
boolean closed;
public void close() throws IOException {
if (!closed) {
super.close();
closed = true;
}
}
};
}
return fileInputStream;
} catch (FileNotFoundException e) {
throw new IOException("Cached file was deleted, " + e.toString());
}
}
use of org.apache.cxf.helpers.LoadingByteArrayOutputStream in project cxf by apache.
the class CachedOutputStream method maybeDeleteTempFile.
private boolean maybeDeleteTempFile(Object stream) {
boolean postClosedInvoked = false;
streamList.remove(stream);
if (!inmem && tempFile != null && streamList.isEmpty() && allowDeleteOfFile) {
if (currentStream != null) {
try {
currentStream.close();
postClose();
} catch (Exception e) {
// ignore
}
postClosedInvoked = true;
}
deleteTempFile();
currentStream = new LoadingByteArrayOutputStream(1024);
inmem = true;
}
return postClosedInvoked;
}
use of org.apache.cxf.helpers.LoadingByteArrayOutputStream in project cxf by apache.
the class TransportURIResolver method resolve.
public InputSource resolve(String curUri, String baseUri) {
// Spaces must be encoded or URI.resolve() will choke
curUri = curUri.replace(" ", "%20");
InputSource is = null;
URI base;
try {
if (baseUri == null) {
base = new URI(curUri);
} else {
base = new URI(baseUri);
base = base.resolve(curUri);
}
} catch (URISyntaxException use) {
// ignore
base = null;
LOG.log(Level.FINEST, "Could not resolve curUri " + curUri, use);
}
try {
if (base == null || DEFAULT_URI_RESOLVER_HANDLES.contains(base.getScheme())) {
is = super.resolve(curUri, baseUri);
}
} catch (Exception ex) {
// nothing
LOG.log(Level.FINEST, "Default URI handlers could not resolve " + baseUri + " " + curUri, ex);
}
if (is == null && base != null && base.getScheme() != null && !DEFAULT_URI_RESOLVER_HANDLES.contains(base.getScheme())) {
try {
ConduitInitiatorManager mgr = bus.getExtension(ConduitInitiatorManager.class);
ConduitInitiator ci = null;
if ("http".equals(base.getScheme()) || "https".equals(base.getScheme())) {
// common case, don't "search"
ci = mgr.getConduitInitiator("http://cxf.apache.org/transports/http");
}
if (ci == null) {
ci = mgr.getConduitInitiatorForUri(base.toString());
}
if (ci != null) {
EndpointInfo info = new EndpointInfo();
// set the endpointInfo name which could be used for configuration
info.setName(new QName("http://cxf.apache.org", "TransportURIResolver"));
info.setAddress(base.toString());
final Conduit c = ci.getConduit(info, bus);
Message message = new MessageImpl();
Exchange exch = new ExchangeImpl();
message.setExchange(exch);
message.put(Message.HTTP_REQUEST_METHOD, "GET");
c.setMessageObserver(new MessageObserver() {
public void onMessage(Message message) {
LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream();
try {
IOUtils.copy(message.getContent(InputStream.class), bout);
message.getExchange().put(InputStream.class, bout.createInputStream());
c.close(message);
} catch (IOException e) {
// ignore
}
}
});
c.prepare(message);
c.close(message);
InputStream ins = exch.get(InputStream.class);
resourceOpened.addElement(ins);
InputSource src = new InputSource(ins);
String u = (String) message.get("transport.retransmit.url");
if (u == null) {
u = base.toString();
}
src.setPublicId(u);
src.setSystemId(u);
lastestImportUri = u;
currentResolver.unresolve();
return src;
}
} catch (Exception e) {
// ignore
LOG.log(Level.FINEST, "Conduit initiator could not resolve " + baseUri + " " + curUri, e);
}
}
if (is == null && (base == null || base.getScheme() == null || !DEFAULT_URI_RESOLVER_HANDLES.contains(base.getScheme()))) {
is = super.resolve(curUri, baseUri);
}
return is;
}
Aggregations