Class MimeTypeContent

java.lang.Object
com.helger.commons.mime.MimeTypeContent

@Immutable @MustImplementEqualsAndHashcode public class MimeTypeContent extends Object
Represent a single mapping from content bytes to an IMimeType.
Author:
Philip Helger
  • Field Details

  • Constructor Details

    • MimeTypeContent

      public MimeTypeContent(@Nonnull @Nonempty byte[] aContentBytes, @Nonnull IMimeType aMimeType)
      Constructor
      Parameters:
      aContentBytes - The beginning bytes. May neither be null nor empty.
      aMimeType - The corresponding mime type. May not be null.
    • MimeTypeContent

      public MimeTypeContent(@Nonnull @Nonempty byte[] aContentBytes, boolean bCopyBytes, @Nonnull IMimeType aMimeType)
      Constructor
      Parameters:
      aContentBytes - The beginning bytes. May neither be null nor empty.
      bCopyBytes - true to copy the bytes, false to reuse the provided instance.
      aMimeType - The corresponding mime type. May not be null.
  • Method Details

    • getAllContentBytes

      @Nonnull @Nonempty @ReturnsMutableCopy public byte[] getAllContentBytes()
      Returns:
      A copy of the content bytes to use. Neither null nor empty.
    • getContentByteCount

      @Nonnegative public int getContentByteCount()
      Returns:
      The number of content bytes available. Always > 0.
    • writeContentBytes

      public void writeContentBytes(@Nonnull @WillNotClose OutputStream aOS) throws IOException
      Write the content bytes to the specified output stream.
      Parameters:
      aOS - The output stream to write to. The stream is NOT closed. May not be null.
      Throws:
      IOException - In case of a write error
    • getMimeType

      @Nonnull public IMimeType getMimeType()
      Returns:
      The matching mime type. Never null.
    • matchesBeginning

      public boolean matchesBeginning(@Nonnull byte[] aCmpBytes)
      Check if the passed byte array starts with the bytes of this object.
      Parameters:
      aCmpBytes - The bytes to compare to. May not be null.
      Returns:
      true if the passed bytes start with the bytes in this object.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object