Changeset 7867 in josm for trunk/src


Ignore:
Timestamp:
2014-12-21T01:30:50+01:00 (5 years ago)
Author:
Don-vip
Message:

see #10448 - Upgrade Bzip2 library to latest version of Apache Commons Compress. The Bzip2 code inside Apache Ant is no longer maintained. Update also CONTRIBUTION and README files + Javadoc update in Utils.

Location:
trunk/src/org
Files:
1 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/Compression.java

    r7119 r7867  
    1313import java.util.zip.ZipOutputStream;
    1414
    15 import org.apache.tools.bzip2.CBZip2OutputStream;
     15import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
    1616import org.openstreetmap.josm.tools.Utils;
    1717
     
    9898        switch (this) {
    9999            case BZIP2:
    100                 out.write('B');
    101                 out.write('Z');
    102                 return new CBZip2OutputStream(out);
     100                return new BZip2CompressorOutputStream(out);
    103101            case GZIP:
    104102                return new GZIPOutputStream(out);
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r7864 r7867  
    5151import java.util.zip.ZipInputStream;
    5252
    53 import org.apache.tools.bzip2.CBZip2InputStream;
     53import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
    5454import org.openstreetmap.josm.Main;
    5555import org.openstreetmap.josm.data.Version;
     
    159159
    160160    /**
    161      * Get minimum of 3 values
     161     * Returns the minimum of three values.
     162     * @param   a   an argument.
     163     * @param   b   another argument.
     164     * @param   c   another argument.
     165     * @return  the smaller of {@code a}, {@code b} and {@code c}.
    162166     */
    163167    public static int min(int a, int b, int c) {
     
    173177    }
    174178
     179    /**
     180     * Returns the greater of four {@code int} values. That is, the
     181     * result is the argument closer to the value of
     182     * {@link Integer#MAX_VALUE}. If the arguments have the same value,
     183     * the result is that same value.
     184     *
     185     * @param   a   an argument.
     186     * @param   b   another argument.
     187     * @param   c   another argument.
     188     * @param   d   another argument.
     189     * @return  the larger of {@code a}, {@code b}, {@code c} and {@code d}.
     190     */
    175191    public static int max(int a, int b, int c, int d) {
    176192        return Math.max(Math.max(a, b), Math.max(c, d));
    177193    }
    178194
     195    /**
     196     * Ensures a logical condition is met. Otherwise throws an assertion error.
     197     * @param condition the condition to be met
     198     * @param message Formatted error message to raise if condition is not met
     199     * @param data Message parameters, optional
     200     * @throws AssertionError if the condition is not met
     201     */
    179202    public static void ensure(boolean condition, String message, Object...data) {
    180203        if (!condition)
     
    209232        if (values == null)
    210233            return null;
    211         if (values.isEmpty())
    212             return "";
    213234        StringBuilder s = null;
    214235        for (Object a : values) {
     
    222243            }
    223244        }
    224         return s.toString();
     245        return s != null ? s.toString() : "";
    225246    }
    226247
     
    361382    }
    362383
     384    /**
     385     * Copy data from source stream to output stream.
     386     * @param source source stream
     387     * @param destination target stream
     388     * @return number of bytes copied
     389     * @throws IOException if any I/O error occurs
     390     */
    363391    public static int copyStream(InputStream source, OutputStream destination) throws IOException {
    364392        int count = 0;
     
    702730     * Opens a connection to the given URL, sets the User-Agent property to JOSM's one, and decompresses stream if necessary.
    703731     * @param url The url to open
    704      * @param decompress whether to wrap steam in a {@link GZIPInputStream} or {@link CBZip2InputStream}
     732     * @param decompress whether to wrap steam in a {@link GZIPInputStream} or {@link BZip2CompressorInputStream}
    705733     *                   if the {@code Content-Type} header is set accordingly.
    706734     * @return An stream for the given URL
     
    729757     * @return a Bzip2 input stream wrapping given input stream, or {@code null} if {@code in} is {@code null}
    730758     * @throws IOException if the given input stream does not contain valid BZ2 header
    731      * @since 7119
    732      */
    733     public static CBZip2InputStream getBZip2InputStream(InputStream in) throws IOException {
     759     * @since 7867
     760     */
     761    public static BZip2CompressorInputStream getBZip2InputStream(InputStream in) throws IOException {
    734762        if (in == null) {
    735763            return null;
    736764        }
    737765        BufferedInputStream bis = new BufferedInputStream(in);
    738         int b = bis.read();
    739         if (b != 'B')
    740             throw new IOException(tr("Invalid bz2 file."));
    741         b = bis.read();
    742         if (b != 'Z')
    743             throw new IOException(tr("Invalid bz2 file."));
    744         return new CBZip2InputStream(bis, /* see #9537 */ true);
     766        return new BZip2CompressorInputStream(bis, /* see #9537 */ true);
    745767    }
    746768
     
    808830     * Opens a connection to the given URL and sets the User-Agent property to JOSM's one.
    809831     * @param url The url to open
    810      * @param decompress whether to wrap steam in a {@link GZIPInputStream} or {@link CBZip2InputStream}
     832     * @param decompress whether to wrap steam in a {@link GZIPInputStream} or {@link BZip2CompressorInputStream}
    811833     *                   if the {@code Content-Type} header is set accordingly.
    812834     * @return An buffered stream reader for the given URL (using UTF-8)
     
    929951     * @since 6354
    930952     */
    931     public static String getDurationString(long elapsedTime) throws IllegalArgumentException {
     953    public static String getDurationString(long elapsedTime) {
    932954        if (elapsedTime < 0) {
    933955            throw new IllegalArgumentException("elapsedTime must be >= 0");
     
    10331055        if (result != null) {
    10341056            Throwable cause = result.getCause();
    1035             while (cause != null && cause != result) {
     1057            while (cause != null && !cause.equals(result)) {
    10361058                result = cause;
    10371059                cause = result.getCause();
     
    10561078    /**
    10571079     * If the string {@code s} is longer than {@code maxLength}, the string is cut and "..." is appended.
     1080     * @param s String to shorten
     1081     * @param maxLength maximum number of characters to keep (not including the "...")
     1082     * @return the shortened string
    10581083     */
    10591084    public static String shortenString(String s, int maxLength) {
Note: See TracChangeset for help on using the changeset viewer.