com.drew.lang.annotations.NotNull Java Examples
The following examples show how to use
com.drew.lang.annotations.NotNull.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RandomAccessFileReader.java From metadata-extractor with Apache License 2.0 | 6 votes |
@Override @NotNull public byte[] getBytes(int index, int count) throws IOException { validateIndex(index, count); if (index != _currentIndex) seek(index); byte[] bytes = new byte[count]; final int bytesRead = _file.read(bytes); _currentIndex += bytesRead; if (bytesRead != count) throw new BufferBoundsException("Unexpected end of file encountered."); return bytes; }
Example #2
Source File: ExifTiffHandler.java From metadata-extractor with Apache License 2.0 | 6 votes |
private static boolean handlePrintIM(@NotNull final Directory directory, final int tagId) { if (tagId == ExifDirectoryBase.TAG_PRINT_IMAGE_MATCHING_INFO) return true; if (tagId == 0x0E00) { // Tempting to say every tagid of 0x0E00 is a PIM tag, but can't be 100% sure if (directory instanceof CasioType2MakernoteDirectory || directory instanceof KyoceraMakernoteDirectory || directory instanceof NikonType2MakernoteDirectory || directory instanceof OlympusMakernoteDirectory || directory instanceof PanasonicMakernoteDirectory || directory instanceof PentaxMakernoteDirectory || directory instanceof RicohMakernoteDirectory || directory instanceof SanyoMakernoteDirectory || directory instanceof SonyType1MakernoteDirectory) return true; } return false; }
Example #3
Source File: ProcessAllImagesInFolderUtility.java From metadata-extractor with Apache License 2.0 | 6 votes |
@Override public void onExtractionError(@NotNull File file, @NotNull Throwable throwable, @NotNull PrintStream log) { super.onExtractionError(file, throwable, log); try { PrintWriter writer = null; try { writer = openWriter(file); writer.write("EXCEPTION: " + throwable.getMessage() + NEW_LINE); writer.write(NEW_LINE); } finally { closeWriter(writer); } } catch (IOException e) { log.printf("IO exception writing metadata file: %s%s", e.getMessage(), NEW_LINE); } }
Example #4
Source File: JpegMetadataReader.java From metadata-extractor with Apache License 2.0 | 6 votes |
public static void process(@NotNull Metadata metadata, @NotNull InputStream inputStream, @Nullable Iterable<JpegSegmentMetadataReader> readers) throws JpegProcessingException, IOException { if (readers == null) readers = ALL_READERS; Set<JpegSegmentType> segmentTypes = new HashSet<JpegSegmentType>(); for (JpegSegmentMetadataReader reader : readers) { for (JpegSegmentType type : reader.getSegmentTypes()) { segmentTypes.add(type); } } JpegSegmentData segmentData = JpegSegmentReader.readSegments(new StreamReader(inputStream), segmentTypes); processJpegSegmentData(metadata, readers, segmentData); }
Example #5
Source File: PngHeader.java From metadata-extractor with Apache License 2.0 | 6 votes |
public PngHeader(@NotNull byte[] bytes) throws PngProcessingException { if (bytes.length != 13) { throw new PngProcessingException("PNG header chunk must have 13 data bytes"); } SequentialReader reader = new SequentialByteArrayReader(bytes); try { _imageWidth = reader.getInt32(); _imageHeight = reader.getInt32(); _bitsPerSample = reader.getInt8(); byte colorTypeNumber = reader.getInt8(); _colorType = PngColorType.fromNumericValue(colorTypeNumber); _compressionType = reader.getInt8(); _filterMethod = reader.getInt8(); _interlaceMethod = reader.getInt8(); } catch (IOException e) { // Should never happen throw new PngProcessingException(e); } }
Example #6
Source File: QuickTimeMediaHandler.java From metadata-extractor with Apache License 2.0 | 5 votes |
@Override public QuickTimeMediaHandler<?> processAtom(@NotNull Atom atom, @Nullable byte[] payload, QuickTimeContext context) throws IOException { if (payload != null) { SequentialReader reader = new SequentialByteArrayReader(payload); if (atom.type.equals(getMediaInformation())) { processMediaInformation(reader, atom); } else if (atom.type.equals(QuickTimeAtomTypes.ATOM_SAMPLE_DESCRIPTION)) { processSampleDescription(reader, atom); } else if (atom.type.equals(QuickTimeAtomTypes.ATOM_TIME_TO_SAMPLE)) { processTimeToSample(reader, atom, context); } } return this; }
Example #7
Source File: StringUtil.java From metadata-extractor with Apache License 2.0 | 5 votes |
@NotNull public static String fromStream(@NotNull InputStream stream) throws IOException { BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); StringBuilder sb = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { sb.append(line); } return sb.toString(); }
Example #8
Source File: IccReader.java From metadata-extractor with Apache License 2.0 | 5 votes |
@NotNull public static String getStringFromInt32(int d) { // MSB byte[] b = new byte[] { (byte) ((d & 0xFF000000) >> 24), (byte) ((d & 0x00FF0000) >> 16), (byte) ((d & 0x0000FF00) >> 8), (byte) ((d & 0x000000FF)) }; return new String(b); }
Example #9
Source File: HuffmanTablesDirectory.java From metadata-extractor with Apache License 2.0 | 5 votes |
/** * @return A byte array with the V values for this table. */ @NotNull public byte[] getValueBytes() { byte[] result = new byte[_valueBytes.length]; System.arraycopy(_valueBytes, 0, result, 0, _valueBytes.length); return result; }
Example #10
Source File: JfifReader.java From metadata-extractor with Apache License 2.0 | 5 votes |
public void readJpegSegments(@NotNull Iterable<byte[]> segments, @NotNull Metadata metadata, @NotNull JpegSegmentType segmentType) { for (byte[] segmentBytes : segments) { // Skip segments not starting with the required header if (segmentBytes.length >= PREAMBLE.length() && PREAMBLE.equals(new String(segmentBytes, 0, PREAMBLE.length()))) extract(new ByteArrayReader(segmentBytes), metadata); } }
Example #11
Source File: StreamReader.java From metadata-extractor with Apache License 2.0 | 5 votes |
@Override public void getBytes(@NotNull byte[] buffer, int offset, int count) throws IOException { int totalBytesRead = 0; while (totalBytesRead != count) { final int bytesRead = _stream.read(buffer, offset + totalBytesRead, count - totalBytesRead); if (bytesRead == -1) throw new EOFException("End of data reached."); totalBytesRead += bytesRead; assert(totalBytesRead <= count); } _pos += totalBytesRead; }
Example #12
Source File: ProcessAllImagesInFolderUtility.java From metadata-extractor with Apache License 2.0 | 5 votes |
private static void processDirectory(@NotNull File path, @NotNull FileHandler handler, @NotNull String relativePath, PrintStream log) { handler.onStartingDirectory(path); String[] pathItems = path.list(); if (pathItems == null) { return; } // Order alphabetically so that output is stable across invocations Arrays.sort(pathItems); for (String pathItem : pathItems) { File file = new File(path, pathItem); if (file.isDirectory()) { processDirectory(file, handler, relativePath.length() == 0 ? pathItem : relativePath + "/" + pathItem, log); } else if (handler.shouldProcess(file)) { handler.onBeforeExtraction(file, log, relativePath); // Read metadata final Metadata metadata; try { metadata = ImageMetadataReader.readMetadata(file); } catch (Throwable t) { handler.onExtractionError(file, t, log); continue; } handler.onExtractionSuccess(file, metadata, relativePath, log); } } }
Example #13
Source File: ProcessAllImagesInFolderUtility.java From metadata-extractor with Apache License 2.0 | 5 votes |
public void onExtractionSuccess(@NotNull File file, @NotNull Metadata metadata, @NotNull String relativePath, @NotNull PrintStream log) { if (metadata.hasErrors()) { log.print(file); log.print('\n'); for (Directory directory : metadata.getDirectories()) { if (!directory.hasErrors()) continue; for (String error : directory.getErrors()) { log.printf("\t[%s] %s\n", directory.getName(), error); _errorCount++; } } } }
Example #14
Source File: RafMetadataReader.java From metadata-extractor with Apache License 2.0 | 5 votes |
@NotNull public static Metadata readMetadata(@NotNull InputStream inputStream) throws JpegProcessingException, IOException { if (!inputStream.markSupported()) throw new IOException("Stream must support mark/reset"); inputStream.mark(512); byte[] data = new byte[512]; int bytesRead = inputStream.read(data); if (bytesRead == -1) throw new IOException("Stream is empty"); inputStream.reset(); for (int i = 0; i < bytesRead - 2; i++) { // Look for the first three bytes of a JPEG encoded file if (data[i] == (byte) 0xff && data[i + 1] == (byte) 0xd8 && data[i + 2] == (byte) 0xff) { long bytesSkipped = inputStream.skip(i); if (bytesSkipped != i) throw new IOException("Skipping stream bytes failed"); break; } } return JpegMetadataReader.readMetadata(inputStream); }
Example #15
Source File: Face.java From metadata-extractor with Apache License 2.0 | 5 votes |
@Override @NotNull public String toString() { StringBuilder result = new StringBuilder(); result.append("x: ").append(_x); result.append(" y: ").append(_y); result.append(" width: ").append(_width); result.append(" height: ").append(_height); if (_name != null) result.append(" name: ").append(_name); if (_age != null) result.append(" age: ").append(_age.toFriendlyString()); return result.toString(); }
Example #16
Source File: JpegSegmentData.java From metadata-extractor with Apache License 2.0 | 5 votes |
/** * Returns all instances of a given JPEG segment. If no instances exist, an empty sequence is returned. * * @param segmentType a number which identifies the type of JPEG segment being queried * @return zero or more byte arrays, each holding the data of a JPEG segment */ @NotNull public Iterable<byte[]> getSegments(byte segmentType) { final List<byte[]> segmentList = getSegmentList(segmentType); return segmentList == null ? new ArrayList<byte[]>() : segmentList; }
Example #17
Source File: TagDescriptor.java From metadata-extractor with Apache License 2.0 | 5 votes |
@Nullable protected String getIndexedDescription(final int tagType, final int baseIndex, @NotNull String... descriptions) { final Long index = _directory.getLongObject(tagType); if (index == null) return null; final long arrayIndex = index - baseIndex; if (arrayIndex >= 0 && arrayIndex < (long)descriptions.length) { String description = descriptions[(int)arrayIndex]; if (description != null) return description; } return "Unknown (" + index + ")"; }
Example #18
Source File: JpegDhtReader.java From metadata-extractor with Apache License 2.0 | 5 votes |
private byte[] getBytes(@NotNull final SequentialReader reader, int count) throws IOException { byte[] bytes = new byte[count]; for (int i = 0; i < count; i++) { byte b = reader.getByte(); if ((b & 0xFF) == 0xFF) { byte stuffing = reader.getByte(); if (stuffing != 0x00) { throw new IOException("Marker " + JpegSegmentType.fromByte(stuffing) + " found inside DHT segment"); } } bytes[i] = b; } return bytes; }
Example #19
Source File: XmpDirectory.java From metadata-extractor with Apache License 2.0 | 5 votes |
/** * Gets the XMPMeta object used to populate this directory. It can be used for more XMP-oriented operations. * If one does not exist it will be created. */ @NotNull public XMPMeta getXMPMeta() { if (_xmpMeta == null) _xmpMeta = new XMPMetaImpl(); return _xmpMeta; }
Example #20
Source File: GifMetadataReader.java From metadata-extractor with Apache License 2.0 | 5 votes |
@NotNull public static Metadata readMetadata(@NotNull File file) throws IOException { InputStream inputStream = new FileInputStream(file); Metadata metadata; try { metadata = readMetadata(inputStream); } finally { inputStream.close(); } new FileSystemMetadataReader().read(file, metadata); return metadata; }
Example #21
Source File: QuickTimeHandler.java From metadata-extractor with Apache License 2.0 | 4 votes |
protected QuickTimeHandler<?> processContainer(@NotNull Atom atom, QuickTimeContext context) throws IOException { return processAtom(atom, null, context); }
Example #22
Source File: SequentialReader.java From metadata-extractor with Apache License 2.0 | 4 votes |
@NotNull public String getString(int bytesRequested) throws IOException { return new String(getBytes(bytesRequested)); }
Example #23
Source File: QuickTimeMusicHandler.java From metadata-extractor with Apache License 2.0 | 4 votes |
@Override protected void processSampleDescription(@NotNull SequentialReader reader, @NotNull Atom atom) throws IOException { MusicSampleDescriptionAtom musicSampleDescriptionAtom = new MusicSampleDescriptionAtom(reader, atom); musicSampleDescriptionAtom.addMetadata(directory); }
Example #24
Source File: PsdHeaderDirectory.java From metadata-extractor with Apache License 2.0 | 4 votes |
@Override @NotNull protected HashMap<Integer, String> getTagNameMap() { return _tagNameMap; }
Example #25
Source File: PhotoshopReader.java From metadata-extractor with Apache License 2.0 | 4 votes |
@NotNull public Iterable<JpegSegmentType> getSegmentTypes() { return Collections.singletonList(JpegSegmentType.APPD); }
Example #26
Source File: PanasonicRawDistortionDirectory.java From metadata-extractor with Apache License 2.0 | 4 votes |
@Override @NotNull public String getName() { return "PanasonicRaw DistortionInfo"; }
Example #27
Source File: SamsungType2MakernoteDescriptor.java From metadata-extractor with Apache License 2.0 | 4 votes |
public SamsungType2MakernoteDescriptor(@NotNull SamsungType2MakernoteDirectory directory) { super(directory); }
Example #28
Source File: Mp4MetaDirectory.java From metadata-extractor with Apache License 2.0 | 4 votes |
@NotNull @Override public String getName() { return "MP4 Metadata"; }
Example #29
Source File: HeifPictureHandler.java From metadata-extractor with Apache License 2.0 | 4 votes |
@Override protected boolean shouldAcceptContainer(@NotNull Box box) { return containersCanProcess.contains(box.type); }
Example #30
Source File: QuickTimeVideoDirectory.java From metadata-extractor with Apache License 2.0 | 4 votes |
@Override @NotNull protected HashMap<Integer, String> getTagNameMap() { return _tagNameMap; }