equal
deleted
inserted
replaced
34 * File type detector that uses the libmagic to guess the MIME type of a file. |
34 * File type detector that uses the libmagic to guess the MIME type of a file. |
35 */ |
35 */ |
36 |
36 |
37 class MagicFileTypeDetector extends AbstractFileTypeDetector { |
37 class MagicFileTypeDetector extends AbstractFileTypeDetector { |
38 |
38 |
39 private static final String UNKNOW_MIME_TYPE = "application/octet-stream"; |
39 private static final String UNKNOWN_MIME_TYPE = "application/octet-stream"; |
40 |
40 |
41 // true if libmagic is available and successfully loaded |
41 // true if libmagic is available and successfully loaded |
42 private final boolean libmagicAvailable; |
42 private final boolean libmagicAvailable; |
43 |
43 |
44 public MagicFileTypeDetector() { |
44 public MagicFileTypeDetector() { |
55 |
55 |
56 NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getByteArrayForSysCalls()); |
56 NativeBuffer buffer = NativeBuffers.asNativeBuffer(path.getByteArrayForSysCalls()); |
57 try { |
57 try { |
58 byte[] type = probe0(buffer.address()); |
58 byte[] type = probe0(buffer.address()); |
59 String mimeType = (type == null) ? null : new String(type); |
59 String mimeType = (type == null) ? null : new String(type); |
60 return UNKNOW_MIME_TYPE.equals(mimeType) ? null : mimeType; |
60 return UNKNOWN_MIME_TYPE.equals(mimeType) ? null : mimeType; |
61 } finally { |
61 } finally { |
62 buffer.release(); |
62 buffer.release(); |
63 } |
63 } |
64 } |
64 } |
65 |
65 |