logger.debug("Error calling mime magic", e); } catch (MagicException e) { e.printStackTrace(); logger.debug("Error calling mime magic", e); } finally {
throw new MagicException(e); } catch (UnsupportedTypeException e) { log.error("getMagicMatch(byte[]): " + e); throw new MagicException(e);
/** Get a match from a stream of data. */ public static MagicMatch getMagicMatch(final byte[] data, final boolean onlyMimeMatch) throws MagicParseException, MagicMatchNotFoundException, MagicException { if (!initialized) { initialize(); } final Collection<MagicMatcher> matchers = magicParser.getMatchers(); MagicMatcher matcher = null; MagicMatch match = null; final Iterator<MagicMatcher> i = matchers.iterator(); while (i.hasNext()) { matcher = i.next(); try { if ((match = matcher.test(data, onlyMimeMatch)) != null) { return match; } } catch (final Throwable e) { throw new MagicException(e); } } throw new MagicMatchNotFoundException(); } }
throw new MagicException(e); } catch (UnsupportedTypeException e) { log.error("getMagicMatch(byte[]): " + e); throw new MagicException(e);
private String getMimeType(ExternalReferenceSPI externalReference, InvocationContext context) { if (!mimeTypes.containsKey(externalReference)) { InputStream inputStream = externalReference.openStream(context); try { byte[] bytes = new byte[64]; inputStream.read(bytes); mimeTypes.put(externalReference, Magic.getMagicMatch(bytes, true).getMimeType()); } catch (IOException e) { e.printStackTrace(); logger.debug("Failed to read from stream to determine mimetype", e); } catch (MagicParseException e) { e.printStackTrace(); logger.debug("Error calling mime magic", e); } catch (MagicMatchNotFoundException e) { e.printStackTrace(); logger.debug("Error calling mime magic", e); } catch (MagicException e) { e.printStackTrace(); logger.debug("Error calling mime magic", e); } finally { try { inputStream.close(); } catch (IOException e) { e.printStackTrace(); logger.debug("Failed to close stream after determining mimetype", e); } } } return mimeTypes.get(externalReference); }
throw new MagicException(e); } catch (IOException e) { log.error("getMagicMatch(File): " + e); throw new MagicException(e); throw new MagicException(e); } catch (IOException e) { log.error("getMagicMatch(File): " + e); throw new MagicException(e);
logger.debug("Error calling mime magic", e); } catch (MagicException e) { e.printStackTrace(); logger.debug("Error calling mime magic", e); } finally {
throw new MagicException(e); } catch (IOException e) { log.error("getMagicMatch(File): " + e); throw new MagicException(e); throw new MagicException(e); } catch (IOException e) { log.error("getMagicMatch(File): " + e); throw new MagicException(e);
} catch (MagicException e1) { e1.printStackTrace();