Package eu.medsea.mimeutil

Examples of eu.medsea.mimeutil.MimeType


    static {
        MimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector");
    }

    public static String getContentType(File file) {
        Collection types = MimeUtil.getMimeTypes(file, new MimeType(MediaType.APPLICATION_OCTET_STREAM));
        return MimeUtil.getMostSpecificMimeType(types).toString();
    }
View Full Code Here


    } else
      content = ""; // prevent NullPointerException happening later in
              // readBuffer(...)

    if (tokens.length > 3) {
      mimeType = new MimeType(tokens[3].trim());
    }
    if (tokens.length > 4) {
      mimeEnc = tokens[4].trim();
    }
View Full Code Here

    buf.position(0);
    boolean matches = match(buf);
    if (matches) {
      int subLen = subEntries.size();
      MimeType mimeType = getMimeType();
      if (subLen > 0) {
        for (int k = 0; k < subLen; k++) {
          MagicMimeEntry me = (MagicMimeEntry) subEntries.get(k);
          MagicMimeEntry matchingEntry = me.getMatch(content);
          if (matchingEntry != null) {
View Full Code Here

    if (buf == null) {
      return null;
    }
    boolean matches = match(buf);
    if (matches) {
      MimeType mimeType = getMimeType();
      if (subEntries.size() > 0) {
        for (int i = 0; i < subEntries.size(); i++) {
          MagicMimeEntry me = (MagicMimeEntry) subEntries.get(i);
          MagicMimeEntry matchingEntry = me.getMatch(raf);
          if (matchingEntry != null) {
View Full Code Here

  }

  private boolean isMimeTypeSubclass(String mimeType, String subClass) {
    String umimeType = unaliasMimeType(mimeType);
    String usubClass = unaliasMimeType(subClass);
    MimeType _mimeType = new MimeType(umimeType);
    MimeType _subClass = new MimeType(usubClass);

    if (umimeType.compareTo(usubClass) == 0) {
      return true;
    }

    if (isSuperType(usubClass)
        && (_mimeType.getMediaType().equals(_subClass.getMediaType()))) {
      return true;
    }

    // Handle special cases text/plain and application/octet-stream
    if (usubClass.equals("text/plain")
View Full Code Here

      return mimeTypes;
    }

    String contentType = getContentType(MimeUtil.getExtension(url.getPath()));
    if(contentType != null && contentType.length() > 0) {
      mimeTypes.add(new MimeType(contentType));
    }
    return mimeTypes;
  }
View Full Code Here

      // First try case sensitive
      types = (String) extMimeTypes.get(fileExtension);
      if (types != null) {
        String [] mimeTypeArray = types.split(",");
        for(int i = 0; i < mimeTypeArray.length; i++) {
          mimeTypes.add(new MimeType(mimeTypeArray[i]));
        }
        return mimeTypes;
      }
      if(mimeTypes.isEmpty()) {
        // Failed to find case insensitive extension so lets try again with
        // lowercase
        types = (String) extMimeTypes.get(fileExtension.toLowerCase());
        if (types != null) {
          String [] mimeTypeArray = types.split(",");
          for(int i = 0; i < mimeTypeArray.length; i++) {
            mimeTypes.add(new MimeType(mimeTypeArray[i]));
          }
          return mimeTypes;
        }
      }
      fileExtension = MimeUtil.getExtension(fileExtension);
View Full Code Here

    return specificity;
  }

  public MimeType getMimeType()
  {
    return new MimeType(magicMimeEntry.getMimeType());
  }
View Full Code Here

      Collection mimeTypes = mimeUtil.getMimeTypes("src/test/resources/plaintext.txt");
      assertTrue(mimeTypes.contains("text/plain"));
      Collection retain = new HashSet();
      retain.add("text/plain");
      mimeTypes.retainAll(retain);
      MimeType mimeType = (MimeType)mimeTypes.iterator().next();
      assertTrue(mimeType instanceof TextMimeType);
      assertTrue(((TextMimeType)mimeType).getSpecificity() == 2);

    }finally{
      // We want this to unregister no matter what
View Full Code Here

  class XMLHandler implements TextMimeHandler {

    public boolean handle(TextMimeType mimeType, String content) {
      if(content.startsWith("<?xml")) {
        mimeType.setMimeType(new MimeType("text/xml"));

        // Now lets find the encoding if possible
        int index = content.indexOf("encoding=\"");
        if(index != -1) {
          int endindex = content.indexOf("\"", index+10);
View Full Code Here

TOP

Related Classes of eu.medsea.mimeutil.MimeType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.