Ignore:
Timestamp:
2017-10-30T22:46:09+01:00 (8 years ago)
Author:
Don-vip
Message:

fix #15505 - update to metadata-extractor 2.10.1

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/com/drew/lang/ByteArrayReader.java

    r10862 r13061  
    11/*
    2  * Copyright 2002-2016 Drew Noakes
     2 * Copyright 2002-2017 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    2222package com.drew.lang;
    2323
     24import com.drew.lang.annotations.NotNull;
     25
    2426import java.io.IOException;
    25 
    26 import com.drew.lang.annotations.NotNull;
    2727
    2828/**
     
    3939    @NotNull
    4040    private final byte[] _buffer;
     41    private final int _baseOffset;
    4142
     43    @SuppressWarnings({ "ConstantConditions" })
     44    @com.drew.lang.annotations.SuppressWarnings(value = "EI_EXPOSE_REP2", justification = "Design intent")
    4245    public ByteArrayReader(@NotNull byte[] buffer)
     46    {
     47        this(buffer, 0);
     48    }
     49
     50    @SuppressWarnings({ "ConstantConditions" })
     51    @com.drew.lang.annotations.SuppressWarnings(value = "EI_EXPOSE_REP2", justification = "Design intent")
     52    public ByteArrayReader(@NotNull byte[] buffer, int baseOffset)
    4353    {
    4454        if (buffer == null)
    4555            throw new NullPointerException();
     56        if (baseOffset < 0)
     57            throw new IllegalArgumentException("Must be zero or greater");
    4658
    4759        _buffer = buffer;
     60        _baseOffset = baseOffset;
     61    }
     62
     63    @Override
     64    public int toUnshiftedOffset(int localOffset)
     65    {
     66        return localOffset + _baseOffset;
    4867    }
    4968
     
    5170    public long getLength()
    5271    {
    53         return _buffer.length;
     72        return _buffer.length - _baseOffset;
    5473    }
    5574
    5675    @Override
    57     protected byte getByte(int index) throws IOException
     76    public byte getByte(int index) throws IOException
    5877    {
    59         return _buffer[index];
     78        validateIndex(index, 1);
     79        return _buffer[index + _baseOffset];
    6080    }
    6181
     
    6484    {
    6585        if (!isValidIndex(index, bytesRequested))
    66             throw new BufferBoundsException(index, bytesRequested, _buffer.length);
     86            throw new BufferBoundsException(toUnshiftedOffset(index), bytesRequested, _buffer.length);
    6787    }
    6888
     
    7292        return bytesRequested >= 0
    7393            && index >= 0
    74             && (long)index + (long)bytesRequested - 1L < _buffer.length;
     94            && (long)index + (long)bytesRequested - 1L < getLength();
    7595    }
    7696
     
    82102
    83103        byte[] bytes = new byte[count];
    84         System.arraycopy(_buffer, index, bytes, 0, count);
     104        System.arraycopy(_buffer, index + _baseOffset, bytes, 0, count);
    85105        return bytes;
    86106    }
Note: See TracChangeset for help on using the changeset viewer.