Changeset 8132 in josm for trunk/src/com/drew/lang


Ignore:
Timestamp:
2015-03-10T01:17:39+01:00 (10 years ago)
Author:
Don-vip
Message:

fix #11162 - update to metadata-extractor 2.7.2

Location:
trunk/src/com/drew/lang
Files:
6 added
1 deleted
10 edited

Legend:

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

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121
    2222package com.drew.lang;
    2323
    24 import com.drew.lang.annotations.NotNull;
    25 
    2624import java.io.IOException;
    2725
    2826/**
    29  * A checked replacement for IndexOutOfBoundsException.  Used by BufferReader.
    30  * 
    31  * @author Drew Noakes http://drewnoakes.com
     27 * A checked replacement for {@link IndexOutOfBoundsException}.  Used by {@link RandomAccessReader}.
     28 *
     29 * @author Drew Noakes https://drewnoakes.com
    3230 */
    33 public final class BufferBoundsException extends Exception
     31public final class BufferBoundsException extends IOException
    3432{
    3533    private static final long serialVersionUID = 2911102837808946396L;
    3634
    37     public BufferBoundsException(@NotNull byte[] buffer, int index, int bytesRequested)
     35    public BufferBoundsException(int index, int bytesRequested, long bufferLength)
    3836    {
    39         super(getMessage(buffer, index, bytesRequested));
     37        super(getMessage(index, bytesRequested, bufferLength));
    4038    }
    4139
     
    4543    }
    4644
    47     public BufferBoundsException(final String message, final IOException innerException)
    48     {
    49         super(message, innerException);
    50     }
    51 
    52     private static String getMessage(@NotNull byte[] buffer, int index, int bytesRequested)
     45    private static String getMessage(int index, int bytesRequested, long bufferLength)
    5346    {
    5447        if (index < 0)
    55             return String.format("Attempt to read from buffer using a negative index (%s)", index);
     48            return String.format("Attempt to read from buffer using a negative index (%d)", index);
    5649
    57         return String.format("Attempt to read %d byte%s from beyond end of buffer (requested index: %d, max index: %d)",
    58                 bytesRequested, bytesRequested==1?"":"s", index, buffer.length - 1);
     50        if (bytesRequested < 0)
     51            return String.format("Number of requested bytes cannot be negative (%d)", bytesRequested);
     52
     53        if ((long)index + (long)bytesRequested - 1L > (long)Integer.MAX_VALUE)
     54            return String.format("Number of requested bytes summed with starting index exceed maximum range of signed 32 bit integers (requested index: %d, requested count: %d)", index, bytesRequested);
     55
     56        return String.format("Attempt to read from beyond end of underlying data source (requested index: %d, requested count: %d, max index: %d)",
     57                index, bytesRequested, bufferLength - 1);
    5958    }
    6059}
  • trunk/src/com/drew/lang/ByteArrayReader.java

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121
     
    2424import com.drew.lang.annotations.NotNull;
    2525
    26 import java.io.UnsupportedEncodingException;
     26import java.io.IOException;
    2727
    2828/**
    2929 * Provides methods to read specific values from a byte array, with a consistent, checked exception structure for
    3030 * issues.
    31  * <p/>
     31 * <p>
    3232 * By default, the reader operates with Motorola byte order (big endianness).  This can be changed by calling
    33  * {@see setMotorolaByteOrder(boolean)}.
    34  * 
    35  * @author Drew Noakes http://drewnoakes.com
     33 * <code>setMotorolaByteOrder(boolean)</code>.
     34 *
     35 * @author Drew Noakes https://drewnoakes.com
    3636 * */
    37 public class ByteArrayReader implements BufferReader
     37public class ByteArrayReader extends RandomAccessReader
    3838{
    3939    @NotNull
    4040    private final byte[] _buffer;
    41     private boolean _isMotorolaByteOrder = true;
    4241
    4342    @SuppressWarnings({ "ConstantConditions" })
     
    4746        if (buffer == null)
    4847            throw new NullPointerException();
    49        
     48
    5049        _buffer = buffer;
    5150    }
     
    5756    }
    5857
    59 
    6058    @Override
    61     public void setMotorolaByteOrder(boolean motorolaByteOrder)
     59    protected byte getByte(int index) throws IOException
    6260    {
    63         _isMotorolaByteOrder = motorolaByteOrder;
    64     }
    65 
    66     @Override
    67     public boolean isMotorolaByteOrder()
    68     {
    69         return _isMotorolaByteOrder;
    70     }
    71 
    72     @Override
    73     public short getUInt8(int index) throws BufferBoundsException
    74     {
    75         checkBounds(index, 1);
    76 
    77         return (short) (_buffer[index] & 255);
    78     }
    79 
    80     @Override
    81     public byte getInt8(int index) throws BufferBoundsException
    82     {
    83         checkBounds(index, 1);
    84 
    8561        return _buffer[index];
    8662    }
    8763
    8864    @Override
    89     public int getUInt16(int index) throws BufferBoundsException
     65    protected void validateIndex(int index, int bytesRequested) throws IOException
    9066    {
    91         checkBounds(index, 2);
    92 
    93         if (_isMotorolaByteOrder) {
    94             // Motorola - MSB first
    95             return (_buffer[index    ] << 8 & 0xFF00) |
    96                    (_buffer[index + 1]      & 0xFF);
    97         } else {
    98             // Intel ordering - LSB first
    99             return (_buffer[index + 1] << 8 & 0xFF00) |
    100                    (_buffer[index    ]      & 0xFF);
    101         }
     67        if (!isValidIndex(index, bytesRequested))
     68            throw new BufferBoundsException(index, bytesRequested, _buffer.length);
    10269    }
    10370
    10471    @Override
    105     public short getInt16(int index) throws BufferBoundsException
     72    protected boolean isValidIndex(int index, int bytesRequested) throws IOException
    10673    {
    107         checkBounds(index, 2);
    108 
    109         if (_isMotorolaByteOrder) {
    110             // Motorola - MSB first
    111             return (short) (((short)_buffer[index    ] << 8 & (short)0xFF00) |
    112                             ((short)_buffer[index + 1]      & (short)0xFF));
    113         } else {
    114             // Intel ordering - LSB first
    115             return (short) (((short)_buffer[index + 1] << 8 & (short)0xFF00) |
    116                             ((short)_buffer[index    ]      & (short)0xFF));
    117         }
     74        return bytesRequested >= 0
     75            && index >= 0
     76            && (long)index + (long)bytesRequested - 1L < (long)_buffer.length;
    11877    }
    11978
    12079    @Override
    121     public long getUInt32(int index) throws BufferBoundsException
     80    @NotNull
     81    public byte[] getBytes(int index, int count) throws IOException
    12282    {
    123         checkBounds(index, 4);
    124 
    125         if (_isMotorolaByteOrder) {
    126             // Motorola - MSB first (big endian)
    127             return (((long)_buffer[index    ]) << 24 & 0xFF000000L) |
    128                     (((long)_buffer[index + 1]) << 16 & 0xFF0000L) |
    129                     (((long)_buffer[index + 2]) << 8  & 0xFF00L) |
    130                     (((long)_buffer[index + 3])       & 0xFFL);
    131         } else {
    132             // Intel ordering - LSB first (little endian)
    133             return (((long)_buffer[index + 3]) << 24 & 0xFF000000L) |
    134                     (((long)_buffer[index + 2]) << 16 & 0xFF0000L) |
    135                     (((long)_buffer[index + 1]) << 8  & 0xFF00L) |
    136                     (((long)_buffer[index    ])       & 0xFFL);
    137         }
    138     }
    139 
    140     @Override
    141     public int getInt32(int index) throws BufferBoundsException
    142     {
    143         checkBounds(index, 4);
    144 
    145         if (_isMotorolaByteOrder) {
    146             // Motorola - MSB first (big endian)
    147             return (_buffer[index    ] << 24 & 0xFF000000) |
    148                    (_buffer[index + 1] << 16 & 0xFF0000) |
    149                    (_buffer[index + 2] << 8  & 0xFF00) |
    150                    (_buffer[index + 3]       & 0xFF);
    151         } else {
    152             // Intel ordering - LSB first (little endian)
    153             return (_buffer[index + 3] << 24 & 0xFF000000) |
    154                    (_buffer[index + 2] << 16 & 0xFF0000) |
    155                    (_buffer[index + 1] << 8  & 0xFF00) |
    156                    (_buffer[index    ]       & 0xFF);
    157         }
    158     }
    159 
    160     @Override
    161     public long getInt64(int index) throws BufferBoundsException
    162     {
    163         checkBounds(index, 8);
    164 
    165         if (_isMotorolaByteOrder) {
    166             // Motorola - MSB first
    167             return ((long)_buffer[index    ] << 56 & 0xFF00000000000000L) |
    168                    ((long)_buffer[index + 1] << 48 & 0xFF000000000000L) |
    169                    ((long)_buffer[index + 2] << 40 & 0xFF0000000000L) |
    170                    ((long)_buffer[index + 3] << 32 & 0xFF00000000L) |
    171                    ((long)_buffer[index + 4] << 24 & 0xFF000000L) |
    172                    ((long)_buffer[index + 5] << 16 & 0xFF0000L) |
    173                    ((long)_buffer[index + 6] << 8  & 0xFF00L) |
    174                    ((long)_buffer[index + 7]       & 0xFFL);
    175         } else {
    176             // Intel ordering - LSB first
    177             return ((long)_buffer[index + 7] << 56 & 0xFF00000000000000L) |
    178                    ((long)_buffer[index + 6] << 48 & 0xFF000000000000L) |
    179                    ((long)_buffer[index + 5] << 40 & 0xFF0000000000L) |
    180                    ((long)_buffer[index + 4] << 32 & 0xFF00000000L) |
    181                    ((long)_buffer[index + 3] << 24 & 0xFF000000L) |
    182                    ((long)_buffer[index + 2] << 16 & 0xFF0000L) |
    183                    ((long)_buffer[index + 1] << 8  & 0xFF00L) |
    184                    ((long)_buffer[index    ]       & 0xFFL);
    185         }
    186     }
    187 
    188     @Override
    189     public float getS15Fixed16(int index) throws BufferBoundsException
    190     {
    191         checkBounds(index, 4);
    192 
    193         if (_isMotorolaByteOrder) {
    194             float res = (_buffer[index    ] & 255) << 8 |
    195                         (_buffer[index + 1] & 255);
    196             int d =     (_buffer[index + 2] & 255) << 8 |
    197                         (_buffer[index + 3] & 255);
    198             return (float)(res + d/65536.0);
    199         } else {
    200             // this particular branch is untested
    201             float res = (_buffer[index + 3] & 255) << 8 |
    202                         (_buffer[index + 2] & 255);
    203             int d =     (_buffer[index + 1] & 255) << 8 |
    204                         (_buffer[index    ] & 255);
    205             return (float)(res + d/65536.0);
    206         }
    207     }
    208 
    209     @Override
    210     public float getFloat32(int index) throws BufferBoundsException
    211     {
    212         return Float.intBitsToFloat(getInt32(index));
    213     }
    214 
    215     @Override
    216     public double getDouble64(int index) throws BufferBoundsException
    217     {
    218         return Double.longBitsToDouble(getInt64(index));
    219     }
    220    
    221     @Override
    222     @NotNull
    223     public byte[] getBytes(int index, int count) throws BufferBoundsException
    224     {
    225         checkBounds(index, count);
     83        validateIndex(index, count);
    22684
    22785        byte[] bytes = new byte[count];
     
    22987        return bytes;
    23088    }
    231 
    232     @Override
    233     @NotNull
    234     public String getString(int index, int bytesRequested) throws BufferBoundsException
    235     {
    236         return new String(getBytes(index, bytesRequested));
    237     }
    238 
    239     @Override
    240     @NotNull
    241     public String getString(int index, int bytesRequested, String charset) throws BufferBoundsException
    242     {
    243         byte[] bytes = getBytes(index, bytesRequested);
    244         try {
    245             return new String(bytes, charset);
    246         } catch (UnsupportedEncodingException e) {
    247             return new String(bytes);
    248         }
    249     }
    250 
    251     @Override
    252     @NotNull
    253     public String getNullTerminatedString(int index, int maxLengthBytes) throws BufferBoundsException
    254     {
    255         // NOTE currently only really suited to single-byte character strings
    256 
    257         checkBounds(index, maxLengthBytes);
    258 
    259         // Check for null terminators
    260         int length = 0;
    261         while ((index + length) < _buffer.length && _buffer[index + length] != '\0' && length < maxLengthBytes)
    262             length++;
    263 
    264         byte[] bytes = getBytes(index, length);
    265         return new String(bytes);
    266     }
    267 
    268     private void checkBounds(final int index, final int bytesRequested) throws BufferBoundsException
    269     {
    270         if (bytesRequested < 0 || index < 0 || (long)index + (long)bytesRequested - 1L >= (long)_buffer.length)
    271             throw new BufferBoundsException(_buffer, index, bytesRequested);
    272     }
    27389}
  • trunk/src/com/drew/lang/CompoundException.java

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121package com.drew.lang;
     
    3232 * of these previous JDK versions.
    3333 *
    34  * @author Drew Noakes http://drewnoakes.com
     34 * @author Drew Noakes https://drewnoakes.com
    3535 */
    3636public class CompoundException extends Exception
     
    6363    }
    6464
     65    @Override
    6566    @NotNull
    6667    public String toString()
     
    7778    }
    7879
     80    @Override
    7981    public void printStackTrace(@NotNull PrintStream s)
    8082    {
     
    8688    }
    8789
     90    @Override
    8891    public void printStackTrace(@NotNull PrintWriter s)
    8992    {
     
    9598    }
    9699
     100    @Override
    97101    public void printStackTrace()
    98102    {
  • trunk/src/com/drew/lang/GeoLocation.java

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121
     
    2525import com.drew.lang.annotations.Nullable;
    2626
     27import java.text.DecimalFormat;
     28
    2729/**
    2830 * Represents a latitude and longitude pair, giving a position on earth in spherical coordinates.
     31 * <p>
    2932 * Values of latitude and longitude are given in degrees.
     33 * <p>
    3034 * This type is immutable.
    3135 */
     
    7983    {
    8084        double[] dms = decimalToDegreesMinutesSeconds(decimal);
    81         return dms[0] + "° " + dms[1] + "' " + dms[2] + '"';
     85        DecimalFormat format = new DecimalFormat("0.##");
     86        return String.format("%s° %s' %s\"", format.format(dms[0]), format.format(dms[1]), format.format(dms[2]));
    8287    }
    8388
  • trunk/src/com/drew/lang/NullOutputStream.java

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121package com.drew.lang;
     
    2727 * An implementation of OutputSteam that ignores write requests by doing nothing.  This class may be useful in tests.
    2828 *
    29  * @author Drew Noakes http://drewnoakes.com
     29 * @author Drew Noakes https://drewnoakes.com
    3030 */
    3131public class NullOutputStream extends OutputStream
     
    3636    }
    3737
     38    @Override
    3839    public void write(int b) throws IOException
    3940    {
  • trunk/src/com/drew/lang/Rational.java

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121
     
    2929/**
    3030 * Immutable class for holding a rational number without loss of precision.  Provides
    31  * a familiar representation via toString() in form <code>numerator/denominator</code>.
    32  *
    33  * @author Drew Noakes http://drewnoakes.com
     31 * a familiar representation via {@link Rational#toString} in form <code>numerator/denominator</code>.
     32 *
     33 * Note that any value with a numerator of zero will be treated as zero, even if the
     34 * denominator is also zero.
     35 *
     36 * @author Drew Noakes https://drewnoakes.com
    3437 */
    3538public class Rational extends java.lang.Number implements Serializable
     
    6164     *         to type <code>double</code>.
    6265     */
     66    @Override
    6367    public double doubleValue()
    6468    {
    65         return (double) _numerator / (double) _denominator;
     69        return _numerator == 0
     70            ? 0.0
     71            : (double) _numerator / (double) _denominator;
    6672    }
    6773
     
    7379     *         to type <code>float</code>.
    7480     */
     81    @Override
    7582    public float floatValue()
    7683    {
    77         return (float) _numerator / (float) _denominator;
     84        return _numerator == 0
     85            ? 0.0f
     86            : (float) _numerator / (float) _denominator;
    7887    }
    7988
     
    8190     * Returns the value of the specified number as a <code>byte</code>.
    8291     * This may involve rounding or truncation.  This implementation simply
    83      * casts the result of <code>doubleValue()</code> to <code>byte</code>.
     92     * casts the result of {@link Rational#doubleValue} to <code>byte</code>.
    8493     *
    8594     * @return the numeric value represented by this object after conversion
    8695     *         to type <code>byte</code>.
    8796     */
     97    @Override
    8898    public final byte byteValue()
    8999    {
     
    94104     * Returns the value of the specified number as an <code>int</code>.
    95105     * This may involve rounding or truncation.  This implementation simply
    96      * casts the result of <code>doubleValue()</code> to <code>int</code>.
     106     * casts the result of {@link Rational#doubleValue} to <code>int</code>.
    97107     *
    98108     * @return the numeric value represented by this object after conversion
    99109     *         to type <code>int</code>.
    100110     */
     111    @Override
    101112    public final int intValue()
    102113    {
     
    107118     * Returns the value of the specified number as a <code>long</code>.
    108119     * This may involve rounding or truncation.  This implementation simply
    109      * casts the result of <code>doubleValue()</code> to <code>long</code>.
     120     * casts the result of {@link Rational#doubleValue} to <code>long</code>.
    110121     *
    111122     * @return the numeric value represented by this object after conversion
    112123     *         to type <code>long</code>.
    113124     */
     125    @Override
    114126    public final long longValue()
    115127    {
     
    120132     * Returns the value of the specified number as a <code>short</code>.
    121133     * This may involve rounding or truncation.  This implementation simply
    122      * casts the result of <code>doubleValue()</code> to <code>short</code>.
     134     * casts the result of {@link Rational#doubleValue} to <code>short</code>.
    123135     *
    124136     * @return the numeric value represented by this object after conversion
    125137     *         to type <code>short</code>.
    126138     */
     139    @Override
    127140    public final short shortValue()
    128141    {
     
    154167    }
    155168
    156     /** Checks if this rational number is an Integer, either positive or negative. */
     169    /** Checks if this {@link Rational} number is an Integer, either positive or negative. */
    157170    public boolean isInteger()
    158171    {
     
    167180     * @return a string representation of the object.
    168181     */
     182    @Override
    169183    @NotNull
    170184    public String toString()
     
    173187    }
    174188
    175     /** Returns the simplest representation of this Rational's value possible. */
     189    /** Returns the simplest representation of this {@link Rational}'s value possible. */
    176190    @NotNull
    177191    public String toSimpleString(boolean allowDecimal)
     
    211225
    212226    /**
    213      * Compares two <code>Rational</code> instances, returning true if they are mathematically
     227     * Compares two {@link Rational} instances, returning true if they are mathematically
    214228     * equivalent.
    215229     *
    216      * @param obj the Rational to compare this instance to.
     230     * @param obj the {@link Rational} to compare this instance to.
    217231     * @return true if instances are mathematically equivalent, otherwise false.  Will also
    218      *         return false if <code>obj</code> is not an instance of <code>Rational</code>.
     232     *         return false if <code>obj</code> is not an instance of {@link Rational}.
    219233     */
    220234    @Override
     
    235249    /**
    236250     * <p>
    237      * Simplifies the Rational number.</p>
     251     * Simplifies the {@link Rational} number.</p>
    238252     * <p>
    239253     * Prime number series: 1, 2, 3, 5, 7, 9, 11, 13, 17</p>
     
    244258     * <p>
    245259     * However, generating the prime number series seems to be a hefty task.  Perhaps
    246      * it's simpler to check if both d & n are divisible by all numbers from 2 ->
     260     * it's simpler to check if both d &amp; n are divisible by all numbers from 2 {@literal ->}
    247261     * (Math.min(denominator, numerator) / 2).  In doing this, one can check for 2
    248262     * and 5 once, then ignore all even numbers, and all numbers ending in 0 or 5.
     
    250264     * <p>
    251265     * Therefore, the max number of pairs of modulus divisions required will be:</p>
    252      * <code><pre>
     266     * <pre><code>
    253267     *    4   Math.min(denominator, numerator) - 1
    254268     *   -- * ------------------------------------ + 2
    255269     *   10                    2
    256      * <p/>
     270     *
    257271     *   Math.min(denominator, numerator) - 1
    258272     * = ------------------------------------ + 2
    259273     *                  5
    260      * </pre></code>
     274     * </code></pre>
    261275     *
    262276     * @return a simplified instance, or if the Rational could not be simplified,
  • trunk/src/com/drew/lang/StringUtil.java

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121
     
    2323
    2424import com.drew.lang.annotations.NotNull;
     25import com.drew.lang.annotations.Nullable;
    2526
     27import java.io.BufferedReader;
     28import java.io.IOException;
     29import java.io.InputStream;
     30import java.io.InputStreamReader;
    2631import java.util.Iterator;
    2732
    28 /** @author Drew Noakes http://drewnoakes.com */
     33/**
     34 * @author Drew Noakes https://drewnoakes.com
     35 */
    2936public class StringUtil
    3037{
     38    @NotNull
    3139    public static String join(@NotNull Iterable<? extends CharSequence> strings, @NotNull String delimiter)
    3240    {
     
    5058    }
    5159
     60    @NotNull
    5261    public static <T extends CharSequence> String join(@NotNull T[] strings, @NotNull String delimiter)
    5362    {
     
    6978        return buffer.toString();
    7079    }
     80
     81    @NotNull
     82    public static String fromStream(@NotNull InputStream stream) throws IOException
     83    {
     84        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));
     85        StringBuilder sb = new StringBuilder();
     86        String line;
     87        while ((line = reader.readLine()) != null) {
     88            sb.append(line);
     89        }
     90        return sb.toString();
     91    }
     92
     93    public static int compare(@Nullable String s1, @Nullable String s2)
     94    {
     95        boolean null1 = s1 == null;
     96        boolean null2 = s2 == null;
     97
     98        if (null1 && null2) {
     99            return 0;
     100        } else if (null1) {
     101            return -1;
     102        } else if (null2) {
     103            return 1;
     104        } else {
     105            return s1.compareTo(s2);
     106        }
     107    }
     108
     109    @NotNull
     110    public static String urlEncode(@NotNull String name)
     111    {
     112        // Sufficient for now, it seems
     113        return name.replace(" ", "%20");
     114    }
    71115}
  • trunk/src/com/drew/lang/annotations/NotNull.java

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121
     
    2323
    2424/**
    25  * @author Drew Noakes http://drewnoakes.com
     25 * @author Drew Noakes https://drewnoakes.com
    2626 */
    2727public @interface NotNull
  • trunk/src/com/drew/lang/annotations/Nullable.java

    r6127 r8132  
    11/*
    2  * Copyright 2002-2012 Drew Noakes
     2 * Copyright 2002-2015 Drew Noakes
    33 *
    44 *    Licensed under the Apache License, Version 2.0 (the "License");
     
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121
     
    2323
    2424/**
    25  * @author Drew Noakes http://drewnoakes.com
     25 * @author Drew Noakes https://drewnoakes.com
    2626 */
    2727public @interface Nullable
  • trunk/src/com/drew/lang/annotations/SuppressWarnings.java

    r6127 r8132  
    1616 * More information about this project is available at:
    1717 *
    18  *    http://drewnoakes.com/code/exif/
    19  *    http://code.google.com/p/metadata-extractor/
     18 *    https://drewnoakes.com/code/exif/
     19 *    https://github.com/drewnoakes/metadata-extractor
    2020 */
    2121
Note: See TracChangeset for help on using the changeset viewer.