Package eu.medsea.mimeutil

Examples of eu.medsea.mimeutil.MimeException


   * @param mimeType
   * @throws MimeException
   */
  public MimeType(final String mimeType) throws MimeException {
    if(mimeType == null || mimeType.trim().length() == 0){
      throw new MimeException("Invalid MimeType [" + mimeType + "]");
    }
    String [] parts = mimeSplitter.split(mimeType.trim());

    if(parts.length > 0) {
      // Treat as the mediaType
View Full Code Here


      timer = new Timer();
      // repeat the check every 10 seconds
      timer.schedule(task, new Date(), 10000);

    } catch (Exception e) {
      throw new MimeException(e);
    } finally {
      if (rCh != null) {
        try {
          rCh.close();
        } catch (Exception e) {
View Full Code Here

        offset += bytesRead;
        restBytesToRead -= bytesRead;
      }
    } catch (IOException ioe) {
      throw new MimeException(ioe);
    } finally {
      try {
        // Reset the input stream to where it was marked.
        in.reset();
      } catch (Exception e) {
        throw new MimeException(e);
      }
    }
    return lookupMagicData(data);
  }
View Full Code Here

  private InputStream getInputStream(URL url) {
    try {
      return MimeUtil.getInputStreamForURL(url);
    } catch (Exception e) {
      throw new MimeException("Error getting InputStream for URL ["
          + url.getPath() + "]", e);
    }
  }
View Full Code Here

            return _mimeTypes;
          }
        }
      }
    } catch (Exception e) {
      throw new MimeException(e);
    } finally {
      closeStream(in);
    }
    return mimeTypes;
View Full Code Here

  public Collection getMimeTypesFile(File file)
      throws UnsupportedOperationException {
    try {
      return getMimeTypesURL(file.toURI().toURL());
    }catch(Exception e) {
      throw new MimeException(e);
    }
  }
View Full Code Here

   */
  public static String getMimeType(InputStream in)
  throws MimeException
  {
    if (!in.markSupported())
      throw new MimeException("InputStream does not support mark and reset!");

    String mimeType = null;
    try {
      List matchingEntries = getMimeTypes(in);

View Full Code Here

   * @param canProvide is a comma separated list of mime types that can be provided such as that returned from a call to getExtensionMimeTypes(...)
   * @return the best matching mime type possible.
   */
  public static String getPreferedMimeType(String accept, String canProvide) {
    if(canProvide == null || canProvide.trim().length() == 0) {
      throw new MimeException("Must specify at least one mime type that can be provided.");
    }
    if(accept == null || accept.trim().length() == 0) {
      accept = "*/*";
    }

 
View Full Code Here

   * @return the quality value of the mime type either calculated from the rules above or the actual value defined.
   * @throws MimeException this is thrown if the mime type pattern is invalid.
   */
  public static double getMimeQuality(String mimeType) throws MimeException{
    if(mimeType == null) {
      throw new MimeException("Invalid MimeType [" + mimeType + "].");
    }
    String [] parts = mimeSplitter.split(mimeType);
    if(parts.length < 2) {
      throw new MimeException("Invalid MimeType [" + mimeType + "].");
    }
    if(parts.length > 2) {
      for(int i = 2; i < parts.length; i++) {
        if(parts[i].trim().startsWith("q=")) {
          // Get the number part
          try {
            // Get the quality factor
            double d = Double.parseDouble(parts[i].split("=")[1].trim());
            return d > 1.0 ? 1.0 : d;
          }catch(NumberFormatException e) {
            throw new MimeException("Invalid Mime quality indicator [" + parts[i].trim() + "]. Must be a valid double between 0 and 1");
          }catch(Exception e) {
            throw new MimeException("Error parsing Mime quality indicator.", e);
          }
        }
      }
    }
    // No quality indicator so always assume its 1 unless a wild card is used
View Full Code Here

      MatchingMagicMimeEntry mostSpecificMatchingEntry = getMostSpecificMatchingEntry(matchingEntries);
      if (mostSpecificMatchingEntry != null)
        return mostSpecificMatchingEntry.getMimeType();
    } catch(Exception e) {
      throw new MimeException("Error parsing file [" + file.getAbsolutePath() + "]", e);
    }finally {
      if(raf != null) {
        try {
          raf.close();
        }catch(Exception e) {
View Full Code Here

TOP

Related Classes of eu.medsea.mimeutil.MimeException

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.