⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 multipartrelatedinputstream.java

📁 Java有关XML编程需要用到axis 的源代码 把里面bin下的包导入相应的Java工程 进行使用
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    Messages.getMessage("readError", e.getMessage()));        } catch (javax.mail.MessagingException e) {            throw new org.apache.axis.AxisFault(                    Messages.getMessage("readError", e.getMessage()));        }    }    //when searching for a MIME boundary it MUST be terminated with CR LF. LF alone is NOT sufficient.    private final byte[] readLine(java.io.InputStream is) throws IOException {        java.io.ByteArrayOutputStream input = new java.io.ByteArrayOutputStream(1024);        int c = 0;        input.write('\r');        input.write('\n');        int next = -1;        for (;c != -1;) {            c = -1 != next ? next :  is.read();            next = -1;            switch (c) {                case -1:                break;                case '\r':                    next = is.read();                    if(next == '\n')  //found a line.                        return input.toByteArray();                    if(next == -1)  return null;                    //fall through                default:                    input.write((byte)c);                break;            }        }        //even if there is stuff in buffer if EOF then this can't be a boundary.        return null;    }    public Part getAttachmentByReference(final String[] id)            throws org.apache.axis.AxisFault {        // First see if we have read it in yet.        Part ret = null;        for (int i = id.length - 1; (ret == null) && (i > -1); --i) {            ret = (AttachmentPart) parts.get(id[i]);        }        if (null == ret) {            ret = readTillFound(id);        }        log.debug(Messages.getMessage("return02",                "getAttachmentByReference(\"" + id                + "\"", ((ret == null)                ? "null"                : ret.toString())));        return ret;    }    /**     * Add an <code>AttachmentPart</code> together with its content and location     * IDs.     *     * @param contentId     the content ID     * @param locationId    the location ID     * @param ap            the <code>AttachmentPart</code>     */    protected void addPart(String contentId, String locationId,                           AttachmentPart ap) {        if ((contentId != null) && (contentId.trim().length() != 0)) {            parts.put(contentId, ap);        }        if ((locationId != null) && (locationId.trim().length() != 0)) {            parts.put(locationId, ap);        }        orderedParts.add(ap);    }    /** Field READ_ALL           */    protected static final String[] READ_ALL = {        " * \0 ".intern()};    // Shouldn't never match    /**     * Read all data.     *     * @throws org.apache.axis.AxisFault if there was a problem reading all the     *              data     */    protected void readAll() throws org.apache.axis.AxisFault {        readTillFound(READ_ALL);    }    public java.util.Collection getAttachments()            throws org.apache.axis.AxisFault {        readAll();        return orderedParts;    }    /**     * This will read streams in till the one that is needed is found.     *     * @param id id is the stream being sought.     *     * @return the part for the id     *     * @throws org.apache.axis.AxisFault     */    protected Part readTillFound(final String[] id)            throws org.apache.axis.AxisFault {        if (boundaryDelimitedStream == null) {            return null;    // The whole stream has been consumed already        }        Part ret = null;        try {            if (soapStreamBDS                    == boundaryDelimitedStream) {    // Still on the SOAP stream.                if (!eos) {    // The SOAP packet has not been fully read yet. Need to store it away.                    java.io.ByteArrayOutputStream soapdata =                            new java.io.ByteArrayOutputStream(1024 * 8);                    byte[] buf =                            new byte[1024 * 16];                    int byteread = 0;                    do {                        byteread = soapStream.read(buf);                        if (byteread > 0) {                            soapdata.write(buf, 0, byteread);                        }                    } while (byteread > -1);                    soapdata.close();                    soapStream = new java.io.ByteArrayInputStream(                            soapdata.toByteArray());                }                boundaryDelimitedStream =                        boundaryDelimitedStream.getNextStream();            }            // Now start searching for the data.            if (null != boundaryDelimitedStream) {                do {                    String contentType = null;                    String contentId = null;                    String contentTransferEncoding = null;                    String contentLocation = null;                    // Read this attachments headers from the stream.                    javax.mail.internet.InternetHeaders headers =                            new javax.mail.internet.InternetHeaders(                                    boundaryDelimitedStream);                    contentId = headers.getHeader("Content-Id", null);                    if (contentId != null) {                        contentId = contentId.trim();                        if (contentId.startsWith("<")) {                            contentId = contentId.substring(1);                        }                        if (contentId.endsWith(">")) {                            contentId =                                    contentId.substring(0, contentId.length() - 1);                        }                     //   if (!contentId.startsWith("cid:")) {                     //       contentId = "cid:" + contentId;                     //   }                        contentId = contentId.trim();                    }                    contentType =                            headers.getHeader(HTTPConstants.HEADER_CONTENT_TYPE,                                    null);                    if (contentType != null) {                        contentType = contentType.trim();                    }                    contentLocation =                            headers.getHeader(HTTPConstants.HEADER_CONTENT_LOCATION,                                    null);                    if (contentLocation != null) {                        contentLocation = contentLocation.trim();                    }                    contentTransferEncoding = headers.getHeader(                            HTTPConstants.HEADER_CONTENT_TRANSFER_ENCODING, null);                    if (contentTransferEncoding != null) {                        contentTransferEncoding =                                contentTransferEncoding.trim();                    }                    java.io.InputStream decodedStream = boundaryDelimitedStream;                    if ((contentTransferEncoding != null)                            && (0 != contentTransferEncoding.length())) {                        decodedStream =                                MimeUtility.decode(decodedStream,                                        contentTransferEncoding);                    }                    ManagedMemoryDataSource source = new ManagedMemoryDataSource(                                                        decodedStream, ManagedMemoryDataSource.MAX_MEMORY_DISK_CACHED, contentType, true);                    DataHandler dh = new DataHandler(source);                    AttachmentPart ap = new AttachmentPart(dh);                    if (contentId != null) {                        ap.setMimeHeader(HTTPConstants.HEADER_CONTENT_ID,                                contentId);                    }                    if (contentLocation != null) {                        ap.setMimeHeader(HTTPConstants.HEADER_CONTENT_LOCATION,                                contentLocation);                    }                    for (java.util.Enumeration en =                            headers.getNonMatchingHeaders(new String[]{                                HTTPConstants.HEADER_CONTENT_ID,                                HTTPConstants.HEADER_CONTENT_LOCATION,                                HTTPConstants.HEADER_CONTENT_TYPE}); en.hasMoreElements();) {                        javax.mail.Header header =                                (javax.mail.Header) en.nextElement();                        String name = header.getName();                        String value = header.getValue();                        if ((name != null) && (value != null)) {                            name = name.trim();                            if (name.length() != 0) {                                ap.addMimeHeader(name, value);                            }                        }                    }                    addPart(contentId, contentLocation, ap);                    for (int i = id.length - 1; (ret == null) && (i > -1);                         --i) {                        if ((contentId != null) && id[i].equals(                                contentId)) {    // This is the part being sought                            ret = ap;                        } else if ((contentLocation != null)                                && id[i].equals(contentLocation)) {                            ret = ap;                        }                    }                    boundaryDelimitedStream =                            boundaryDelimitedStream.getNextStream();                } while ((null == ret) && (null != boundaryDelimitedStream));            }        } catch (Exception e) {            throw org.apache.axis.AxisFault.makeFault(e);        }        return ret;    }    public String getContentLocation() {        return contentLocation;    }    public String getContentId() {        return contentId;    }    public int read(byte[] b, int off, int len) throws java.io.IOException {        if (closed) {            throw new java.io.IOException(Messages.getMessage("streamClosed"));        }        if (eos) {            return -1;        }        int read = soapStream.read(b, off, len);        if (read < 0) {            eos = true;        }        return read;    }    public int read(byte[] b) throws java.io.IOException {        return read(b, 0, b.length);    }    public int read() throws java.io.IOException {        if (closed) {            throw new java.io.IOException(Messages.getMessage("streamClosed"));        }        if (eos) {            return -1;        }        int ret = soapStream.read();        if (ret < 0) {            eos = true;        }        return ret;    }    public void close() throws java.io.IOException {        closed = true;        soapStream.close();    }    public int available() throws java.io.IOException {        return (closed || eos) ? 0 : soapStream.available();    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -