本文整理汇总了Java中com.sun.xml.internal.messaging.saaj.util.ByteOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java ByteOutputStream类的具体用法?Java ByteOutputStream怎么用?Java ByteOutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByteOutputStream类属于com.sun.xml.internal.messaging.saaj.util包,在下文中一共展示了ByteOutputStream类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: MimeBodyPart
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
/**
* Constructs a MimeBodyPart by reading and parsing the data from
* the specified input stream. The parser consumes data till the end
* of the given input stream. The input stream must start at the
* beginning of a valid MIME body part and must terminate at the end
* of that body part. <p>
*
* Note that the "boundary" string that delimits body parts must
* <strong>not</strong> be included in the input stream. The intention
* is that the MimeMultipart parser will extract each body part's bytes
* from a multipart stream and feed them into this constructor, without
* the delimiter strings.
*
* @param is the body part Input Stream
*/
public MimeBodyPart(InputStream is) throws MessagingException {
if (!(is instanceof ByteArrayInputStream) &&
!(is instanceof BufferedInputStream) &&
!(is instanceof SharedInputStream))
is = new BufferedInputStream(is);
headers = new InternetHeaders(is);
if (is instanceof SharedInputStream) {
SharedInputStream sis = (SharedInputStream) is;
contentStream = sis.newStream(sis.getPosition(), -1);
} else {
try {
ByteOutputStream bos = new ByteOutputStream();
bos.write(is);
content = bos.getBytes();
contentLength = bos.getCount();
} catch (IOException ioex) {
throw new MessagingException("Error reading input stream", ioex);
}
}
}
示例2: compressString
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
/**
* Compress the string with ZIP method.
* @param content
* @return
*/
public static byte[] compressString(String entryName, String content) {
try {
ByteOutputStream bos = new ByteOutputStream(10000);
ZipOutputStream zos = new ZipOutputStream(bos);
ZipEntry entry = new ZipEntry(entryName);
zos.putNextEntry(entry);
zos.write(content.getBytes("utf8"));
zos.flush();
zos.close();
byte[] fileBytes = new byte[bos.size()];
System.arraycopy(bos.getBytes(), 0, fileBytes, 0, fileBytes.length);
return fileBytes;
} catch (IOException e) {
logger.warn("Failed to zip string.", e);
}
return null;
}
示例3: toXML
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
/**
* 转为xml串
* @param obj
* @return
*/
public String toXML(Object obj){
String result = null;
try {
JAXBContext context = JAXBContext.newInstance(obj.getClass());
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.setProperty(Marshaller.JAXB_FRAGMENT, true);// 去掉报文头
OutputStream os = new ByteOutputStream();
StringWriter writer = new StringWriter();
XMLSerializer serializer = getXMLSerializer(os);
m.marshal(obj, serializer.asContentHandler());
result = os.toString();
} catch (Exception e) {
e.printStackTrace();
}
logger.info("response text:" + result);
return result;
}
示例4: setBase64Content
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
public void setBase64Content(InputStream content, String contentType)
throws SOAPException {
if (mimePart != null) {
mimePart.close();
mimePart = null;
}
dataHandler = null;
InputStream decoded = null;
try {
decoded = MimeUtility.decode(content, "base64");
InternetHeaders hdrs = new InternetHeaders();
hdrs.setHeader("Content-Type", contentType);
//TODO: reading the entire attachment here is ineffcient. Somehow the MimeBodyPart
// Ctor with inputStream causes problems based on the InputStream
// has markSupported()==true
ByteOutputStream bos = new ByteOutputStream();
bos.write(decoded);
rawContent = new MimeBodyPart(hdrs, bos.getBytes(), bos.getCount());
setMimeHeader("Content-Type", contentType);
} catch (Exception e) {
log.log(Level.SEVERE, "SAAJ0578.soap.attachment.setbase64content.exception", e);
throw new SOAPExceptionImpl(e.getLocalizedMessage());
} finally {
try {
decoded.close();
} catch (IOException ex) {
throw new SOAPException(ex);
}
}
}
示例5: setRawContent
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
public void setRawContent(InputStream content, String contentType)
throws SOAPException {
if (mimePart != null) {
mimePart.close();
mimePart = null;
}
dataHandler = null;
try {
InternetHeaders hdrs = new InternetHeaders();
hdrs.setHeader("Content-Type", contentType);
//TODO: reading the entire attachment here is ineffcient. Somehow the MimeBodyPart
// Ctor with inputStream causes problems based on whether the InputStream has
// markSupported()==true or false
ByteOutputStream bos = new ByteOutputStream();
bos.write(content);
rawContent = new MimeBodyPart(hdrs, bos.getBytes(), bos.getCount());
setMimeHeader("Content-Type", contentType);
} catch (Exception e) {
log.log(Level.SEVERE, "SAAJ0576.soap.attachment.setrawcontent.exception", e);
throw new SOAPExceptionImpl(e.getLocalizedMessage());
} finally {
try {
content.close();
} catch (IOException ex) {
throw new SOAPException(ex);
}
}
}
示例6: readBody
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
private int readBody(
InputStream is, byte[] pattern, long[] posVector,
ByteOutputStream baos, SharedInputStream sin)
throws Exception {
if (!find(is, pattern, posVector, baos, sin)) {
throw new Exception(
"Missing boundary delimitier while reading Body Part");
}
return b;
}
示例7: writeTo
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
public void writeTo(OutputStream os)
throws IOException, MessagingException {
// inputStream was not null
if (in != null) {
contentType.setParameter("boundary", this.boundary);
}
String bnd = "--" + contentType.getParameter("boundary");
for (int i = 0; i < parts.size(); i++) {
OutputUtil.writeln(bnd, os); // put out boundary
((MimeBodyPart)parts.get(i)).writeTo(os);
OutputUtil.writeln(os); // put out empty line
}
if (in != null) {
OutputUtil.writeln(bnd, os); // put out boundary
if ((os instanceof ByteOutputStream) && lazyAttachments) {
((ByteOutputStream)os).write(in);
} else {
ByteOutputStream baos = new ByteOutputStream(in.available());
baos.write(in);
baos.writeTo(os);
// reset the inputstream so that we can support a
//getAttachment later
in = baos.newInputStream();
}
// this will endup writing the end boundary
} else {
// put out last boundary
OutputUtil.writeAsAscii(bnd, os);
OutputUtil.writeAsAscii("--", os);
}
}
示例8: getBytes
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
/**
*
* @deprecated
* this is an expensive operation that require an additional
* buffer reallocation just to get the array of an exact size.
* Unless you absolutely need the exact size array, don't use this.
* Use {@link ByteOutputStream} and {@link ByteOutputStream#write(InputStream)}.
*/
public static byte[] getBytes(InputStream is) throws IOException {
ByteOutputStream bos = new ByteOutputStream();
try {
bos.write(is);
} finally {
is.close();
}
return bos.toByteArray();
}
示例9: readBody
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
private int readBody(
InputStream is, byte[] pattern, long[] posVector,
ByteOutputStream baos, SharedInputStream sin)
throws Exception {
if (!find(is, pattern, posVector, baos, sin)) {
throw new Exception(
"Missing boundary delimitier while reading Body Part");
}
return b;
}
示例10: writeXmlDocumentToVirtualFile
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
private void writeXmlDocumentToVirtualFile(VirtualFile pom, Document pomDocument) throws TransformerConfigurationException, TransformerException, IOException {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
DOMSource source = new DOMSource(pomDocument);
ByteOutputStream bytes = new ByteOutputStream();
StreamResult result = new StreamResult(bytes);
transformer.transform(source, result);
VfsUtil.saveText(pom, bytes.toString());
}
示例11: compressStringZlib
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
public static byte[] compressStringZlib(String content) {
try {
ByteOutputStream bos = new ByteOutputStream(10000);
DeflaterOutputStream zos = new DeflaterOutputStream(bos);
zos.write(content.getBytes("utf8"));
zos.flush();
zos.close();
byte[] fileBytes = new byte[bos.size()];
System.arraycopy(bos.getBytes(), 0, fileBytes, 0, fileBytes.length);
return fileBytes;
} catch (IOException e) {
logger.warn("Failed to zip string.", e);
}
return null;
}
示例12: setBase64Content
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
public void setBase64Content(InputStream content, String contentType)
throws SOAPException {
if (mimePart != null) {
mimePart.close();
mimePart = null;
}
dataHandler = null;
InputStream decoded = null;
try {
decoded = MimeUtility.decode(content, "base64");
InternetHeaders hdrs = new InternetHeaders();
hdrs.setHeader("Content-Type", contentType);
//TODO: reading the entire attachment here is ineffcient. Somehow the MimeBodyPart
// Ctor with inputStream causes problems based on the InputStream
// has markSupported()==true
ByteOutputStream bos = new ByteOutputStream();
bos.write(decoded);
rawContent = new MimeBodyPart(hdrs, bos.getBytes(), bos.getCount());
setMimeHeader("Content-Type", contentType);
} catch (Exception e) {
log.log(Level.SEVERE, "SAAJ0578.soap.attachment.setbase64content.exception", e);
throw new SOAPExceptionImpl(e.getLocalizedMessage());
} finally {
try {
decoded.close();
} catch (IOException ex) {
throw new SOAPException(ex);
}
}
}
示例13: writeXmlDocumentToVirtualFile
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
public void writeXmlDocumentToVirtualFile(VirtualFile pom, Document pomDocument) {
RunnableHelper.runWriteCommand(projectHandle, new Runnable() {
@Override
public void run() {
try {
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
DOMSource source = new DOMSource(pomDocument);
ByteOutputStream bytes = new ByteOutputStream();
StreamResult result = new StreamResult(bytes);
transformer.transform(source, result);
VfsUtil.saveText(pom, bytes.toString());
} catch (TransformerException tfe) {
tfe.printStackTrace();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
}
示例14: getContentAsStream
import com.sun.xml.internal.messaging.saaj.util.ByteOutputStream; //导入依赖的package包/类
public InputStream getContentAsStream() throws IOException {
if (source != null) {
InputStream is = null;
// Allow message to be transcode if so requested
if (source instanceof StreamSource && !isFastInfoset()) {
is = ((StreamSource) source).getInputStream();
}
else if (FastInfosetReflection.isFastInfosetSource(source) &&
isFastInfoset())
{
try {
// InputStream is = source.getInputStream()
is = FastInfosetReflection.FastInfosetSource_getInputStream(source);
}
catch (Exception e) {
throw new IOException(e.toString());
}
}
if (is != null) {
if (lazyContentLength) {
return is;
}
if (!(is instanceof ByteInputStream)) {
log.severe("SAAJ0546.soap.stream.incorrect.type");
throw new IOException("Internal error: stream not of the right type");
}
return (ByteInputStream) is;
}
// need to do something here for reader...
// for now we'll see if we can fallback...
}
ByteOutputStream b = new ByteOutputStream();
Envelope env = null;
try {
env = (Envelope) getEnvelope();
env.output(b, isFastInfoset());
}
catch (SOAPException soapException) {
log.severe("SAAJ0547.soap.cannot.externalize");
throw new SOAPIOException(
"SOAP exception while trying to externalize: ",
soapException);
}
return b.newInputStream();
}