Ejemplo n.º 1
0
  /**
   * Convenience method for getting the "{@code content-type}" header.
   *
   * @return type from the header or "{@code application/octet-stream}" if there was no {@code
   *     content-type} header.
   */
  public MimeMediaType getContentTypeHeader() {
    Iterator<Header> it = getHeader(CONTENT_TYPE);

    if (!it.hasNext()) {
      // return the generic type. Better than returning "null".
      return MimeMediaType.AOS;
    }
    Header header = it.next();

    return MimeMediaType.valueOf(header.getValueString());
  }
Ejemplo n.º 2
0
    static String getExtensionForMime(
        StructuredDocumentFactory.Instantiator.ExtensionMapping[] mappings,
        MimeMediaType mimeType) {
      MimeMediaType cleanMime = new MimeMediaType(mimeType.getMimeMediaType());
      String result = "???";

      for (int eachMapping = 0; eachMapping < mappings.length; eachMapping++) {
        // assign the extension as the result if this is the default
        if (null == mappings[eachMapping].getMimeMediaType())
          result = mappings[eachMapping].getExtension();

        if (mappings[eachMapping].getMimeMediaType().equals(cleanMime)) {
          result = mappings[eachMapping].getExtension();
          break;
        }
      }

      return result;
    }
Ejemplo n.º 3
0
 /**
  * Convenience method for setting the "{@code content-type}" header.
  *
  * @param type type of the message.
  */
 public void setContentTypeHeader(MimeMediaType type) {
   replaceHeader(CONTENT_TYPE, type.toString());
 }