Package helma.util

Class MimePart

  • All Implemented Interfaces:
    java.io.Serializable

    public class MimePart
    extends java.lang.Object
    implements java.io.Serializable
    This represents a MIME part of a HTTP file upload
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      MimePart​(java.lang.String name, byte[] content, java.lang.String contentType)
      Creates a new MimePart object.
      MimePart​(org.apache.commons.fileupload.FileItem fileItem)
      Creates a new MimePart object from a file upload.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      byte[] getContent()
      Return the content of the mime part as byte array.
      int getContentLength()
      Get the number of bytes in the mime part's content
      java.lang.String getContentType()  
      java.lang.String getETag()
      Get the ETag of the mime part
      java.io.InputStream getInputStream()
      Return an InputStream to read the content of the mime part
      java.util.Date getLastModified()
      Get the last modified date
      java.lang.String getName()
      Get the mime part's name
      static java.lang.String getSubHeader​(java.lang.String header, java.lang.String subHeaderName)
      Get a sub-header from a header, e.g.
      java.lang.String getText()
      Return the content of the mime part as string, if its content type is null, text/* or application/text.
      static java.lang.String normalizeFilename​(java.lang.String filename)
      Normalize a upload file name.
      void setETag​(java.lang.String eTag)
      Set the ETag for the mime part
      void setLastModified​(java.util.Date lastModified)
      Set the last modified date
      java.lang.String writeToFile​(java.lang.String dir)
      Write the mimepart to a directory, using its name as file name.
      java.lang.String writeToFile​(java.lang.String dir, java.lang.String fname)
      Write the mimepart to a file.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MimePart

        public MimePart​(java.lang.String name,
                        byte[] content,
                        java.lang.String contentType)
        Creates a new MimePart object.
        Parameters:
        name - the file name
        content - the mime part content
        contentType - the content type
      • MimePart

        public MimePart​(org.apache.commons.fileupload.FileItem fileItem)
        Creates a new MimePart object from a file upload.
        Parameters:
        fileItem - a commons fileupload file item
    • Method Detail

      • getContentType

        public java.lang.String getContentType()
        Returns:
        the content type
      • getContentLength

        public int getContentLength()
        Get the number of bytes in the mime part's content
        Returns:
        the content length
      • getName

        public java.lang.String getName()
        Get the mime part's name
        Returns:
        the file name
      • getContent

        public byte[] getContent()
        Return the content of the mime part as byte array.
        Returns:
        the mime part content as byte array
      • getInputStream

        public java.io.InputStream getInputStream()
                                           throws java.io.IOException
        Return an InputStream to read the content of the mime part
        Returns:
        an InputStream for the mime part content
        Throws:
        java.io.IOException - an I/O related error occurred
      • getText

        public java.lang.String getText()
        Return the content of the mime part as string, if its content type is null, text/* or application/text. Otherwise, return null.
        Returns:
        the content of the mime part as string
      • getLastModified

        public java.util.Date getLastModified()
        Get the last modified date
        Returns:
        the last modified date
      • setLastModified

        public void setLastModified​(java.util.Date lastModified)
        Set the last modified date
        Parameters:
        lastModified - the last modified date
      • getETag

        public java.lang.String getETag()
        Get the ETag of the mime part
        Returns:
        the ETag
      • setETag

        public void setETag​(java.lang.String eTag)
        Set the ETag for the mime part
        Parameters:
        eTag - the ETag
      • writeToFile

        public java.lang.String writeToFile​(java.lang.String dir)
        Write the mimepart to a directory, using its name as file name.
        Parameters:
        dir - the directory to write the file to
        Returns:
        the absolute path name of the file written, or null if an error occurred
      • writeToFile

        public java.lang.String writeToFile​(java.lang.String dir,
                                            java.lang.String fname)
        Write the mimepart to a file.
        Parameters:
        dir - the directory to write the file to
        Returns:
        the name of the file written, or null if an error occurred
      • getSubHeader

        public static java.lang.String getSubHeader​(java.lang.String header,
                                                    java.lang.String subHeaderName)
        Get a sub-header from a header, e.g. the charset from Content-Type: text/plain; charset="UTF-8"
      • normalizeFilename

        public static java.lang.String normalizeFilename​(java.lang.String filename)
        Normalize a upload file name. Internet Explorer on Windows sends the whole path, so we cut off everything before the actual name.