Java Code Examples for com.drew.lang.annotations.NotNull

The following examples show how to use com.drew.lang.annotations.NotNull. These examples are extracted from open source projects. 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 Project: metadata-extractor   Source File: PngHeader.java    License: Apache License 2.0 6 votes vote down vote up
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 2
Source Project: metadata-extractor   Source File: JpegMetadataReader.java    License: Apache License 2.0 6 votes vote down vote up
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 3
@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 Project: metadata-extractor   Source File: RandomAccessFileReader.java    License: Apache License 2.0 6 votes vote down vote up
@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 5
Source Project: metadata-extractor   Source File: ExifTiffHandler.java    License: Apache License 2.0 6 votes vote down vote up
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 6
Source Project: metadata-extractor   Source File: JfifReader.java    License: Apache License 2.0 5 votes vote down vote up
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 7
Source Project: metadata-extractor   Source File: HuffmanTablesDirectory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @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 8
Source Project: metadata-extractor   Source File: IccReader.java    License: Apache License 2.0 5 votes vote down vote up
@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 Project: metadata-extractor   Source File: StringUtil.java    License: Apache License 2.0 5 votes vote down vote up
@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 10
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 11
Source Project: metadata-extractor   Source File: JpegSegmentData.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 12
Source Project: metadata-extractor   Source File: TagDescriptor.java    License: Apache License 2.0 5 votes vote down vote up
@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 13
Source Project: metadata-extractor   Source File: JpegDhtReader.java    License: Apache License 2.0 5 votes vote down vote up
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 14
Source Project: metadata-extractor   Source File: GifMetadataReader.java    License: Apache License 2.0 5 votes vote down vote up
@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 15
Source Project: metadata-extractor   Source File: StreamReader.java    License: Apache License 2.0 5 votes vote down vote up
@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 16
Source Project: metadata-extractor   Source File: Face.java    License: Apache License 2.0 5 votes vote down vote up
@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 17
Source Project: metadata-extractor   Source File: RafMetadataReader.java    License: Apache License 2.0 5 votes vote down vote up
@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 18
Source Project: metadata-extractor   Source File: XmpDirectory.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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 19
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 20
Source Project: metadata-extractor   Source File: QuickTimeMediaHandler.java    License: Apache License 2.0 5 votes vote down vote up
@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 21
Source Project: Bats   Source File: GenericMetadataDirectory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@NotNull
public String getName()
{
  return "Generic Metadata";
}
 
Example 22
Source Project: metadata-extractor   Source File: Directory.java    License: Apache License 2.0 4 votes vote down vote up
public void setParent(@NotNull Directory parent)
{
    _parent = parent;
}
 
Example 23
Source Project: metadata-extractor   Source File: KeyValuePair.java    License: Apache License 2.0 4 votes vote down vote up
public KeyValuePair(@NotNull String key, @NotNull StringValue value)
{
    _key = key;
    _value = value;
}
 
Example 24
Source Project: metadata-extractor   Source File: WavDirectory.java    License: Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public String getName()
{
    return "WAV";
}
 
Example 25
public OlympusMakernoteDescriptor(@NotNull OlympusMakernoteDirectory directory)
{
    super(directory);
}
 
Example 26
Source Project: metadata-extractor   Source File: HuffmanTablesDirectory.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @param tableNumber The zero-based index of the table. This number is normally between 0 and 3.
 *                    Use {@link #getNumberOfTables} for bounds-checking.
 * @return The {@link HuffmanTable} having the specified number.
 */
@NotNull
public HuffmanTable getTable(int tableNumber)
{
    return tables.get(tableNumber);
}
 
Example 27
Source Project: metadata-extractor   Source File: IcoDirectory.java    License: Apache License 2.0 4 votes vote down vote up
@Override
@NotNull
public String getName()
{
    return "ICO";
}
 
Example 28
Source Project: metadata-extractor   Source File: ByteArrayReader.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "ConstantConditions" })
@com.drew.lang.annotations.SuppressWarnings(value = "EI_EXPOSE_REP2", justification = "Design intent")
public ByteArrayReader(@NotNull byte[] buffer)
{
    this(buffer, 0);
}
 
Example 29
@Override
@NotNull
public String getName()
{
    return "Samsung Makernote";
}
 
Example 30
public OlympusFocusInfoMakernoteDescriptor(@NotNull OlympusFocusInfoMakernoteDirectory directory)
{
    super(directory);
}