View | Details | Raw Unified | Return to bug 56913
Collapse All | Expand All

(-)src/scratchpad/src/org/apache/poi/hwpf/model/Sttb.java (-2 / +3 lines)
Lines 16-25 Link Here
16
==================================================================== */
16
==================================================================== */
17
package org.apache.poi.hwpf.model;
17
package org.apache.poi.hwpf.model;
18
18
19
import org.apache.poi.util.ArrayUtil;
20
import org.apache.poi.util.LittleEndian;
19
import org.apache.poi.util.LittleEndian;
21
import org.apache.poi.util.StringUtil;
20
import org.apache.poi.util.StringUtil;
22
21
22
import java.util.Arrays;
23
23
/**
24
/**
24
 * The STTB is a string table that is made up of a header that is followed by an
25
 * The STTB is a string table that is made up of a header that is followed by an
25
 * array of elements. The cData value specifies the number of elements that are
26
 * array of elements. The cData value specifies the number of elements that are
Lines 64-70 Link Here
64
    {
65
    {
65
        this._cDataLength = cDataLength;
66
        this._cDataLength = cDataLength;
66
67
67
        this._data = ArrayUtil.copyOf( data, new String[data.length] );
68
        this._data = Arrays.copyOf(data, data.length);
68
69
69
        this._cbExtra = 0;
70
        this._cbExtra = 0;
70
        this._extraData = null;
71
        this._extraData = null;
(-)src/scratchpad/src/org/apache/poi/hwpf/model/NilPICFAndBinData.java (-3 / +4 lines)
Lines 16-26 Link Here
16
==================================================================== */
16
==================================================================== */
17
package org.apache.poi.hwpf.model;
17
package org.apache.poi.hwpf.model;
18
18
19
import org.apache.poi.util.ArrayUtil;
20
import org.apache.poi.util.LittleEndian;
19
import org.apache.poi.util.LittleEndian;
21
import org.apache.poi.util.POILogFactory;
20
import org.apache.poi.util.POILogFactory;
22
import org.apache.poi.util.POILogger;
21
import org.apache.poi.util.POILogger;
23
22
23
import java.util.Arrays;
24
24
public class NilPICFAndBinData
25
public class NilPICFAndBinData
25
{
26
{
26
27
Lines 52-59 Link Here
52
53
53
        // skip the 62 ignored bytes
54
        // skip the 62 ignored bytes
54
        int binaryLength = lcb - cbHeader;
55
        int binaryLength = lcb - cbHeader;
55
        this._binData = ArrayUtil.copyOfRange( data, offset + cbHeader,
56
        this._binData = Arrays.copyOfRange(data, offset + cbHeader,
56
                offset + cbHeader + binaryLength );
57
                offset + cbHeader + binaryLength);
57
    }
58
    }
58
59
59
    public byte[] getBinData()
60
    public byte[] getBinData()
(-)src/scratchpad/src/org/apache/poi/hwpf/model/PlfLfo.java (-3 / +2 lines)
Lines 23-29 Link Here
23
import java.util.NoSuchElementException;
23
import java.util.NoSuchElementException;
24
24
25
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
25
import org.apache.poi.hwpf.model.io.HWPFOutputStream;
26
import org.apache.poi.util.ArrayUtil;
27
import org.apache.poi.util.LittleEndian;
26
import org.apache.poi.util.LittleEndian;
28
import org.apache.poi.util.POILogFactory;
27
import org.apache.poi.util.POILogFactory;
29
import org.apache.poi.util.POILogger;
28
import org.apache.poi.util.POILogger;
Lines 118-127 Link Here
118
    {
117
    {
119
        final int newLfoMac = _lfoMac + 1;
118
        final int newLfoMac = _lfoMac + 1;
120
119
121
        _rgLfo = ArrayUtil.copyOf( _rgLfo, new LFO[newLfoMac] );
120
        _rgLfo = Arrays.copyOf(_rgLfo, newLfoMac);
122
        _rgLfo[_lfoMac + 1] = lfo;
121
        _rgLfo[_lfoMac + 1] = lfo;
123
122
124
        _rgLfoData = ArrayUtil.copyOf( _rgLfoData, new LFOData[_lfoMac + 1] );
123
        _rgLfoData = Arrays.copyOf(_rgLfoData, newLfoMac);
125
        _rgLfoData[_lfoMac + 1] = lfoData;
124
        _rgLfoData[_lfoMac + 1] = lfoData;
126
125
127
        this._lfoMac = newLfoMac;
126
        this._lfoMac = newLfoMac;
(-)src/java/org/apache/poi/hssf/record/DrawingGroupRecord.java (-1 / +1 lines)
Lines 118-124 Link Here
118
                writeHeader( data, offset, segmentLength );
118
                writeHeader( data, offset, segmentLength );
119
            writtenActualData += 4;
119
            writtenActualData += 4;
120
            offset += 4;
120
            offset += 4;
121
            ArrayUtil.arraycopy( rawData, writtenRawData, data, offset, segmentLength );
121
            System.arraycopy( rawData, writtenRawData, data, offset, segmentLength );
122
            offset += segmentLength;
122
            offset += segmentLength;
123
            writtenRawData += segmentLength;
123
            writtenRawData += segmentLength;
124
            writtenActualData += segmentLength;
124
            writtenActualData += segmentLength;
(-)src/java/org/apache/poi/hssf/record/DConRefRecord.java (-3 / +4 lines)
Lines 18-27 Link Here
18
 */
18
 */
19
package org.apache.poi.hssf.record;
19
package org.apache.poi.hssf.record;
20
20
21
import org.apache.poi.util.ArrayUtil;
22
import org.apache.poi.util.LittleEndian;
21
import org.apache.poi.util.LittleEndian;
23
import org.apache.poi.util.LittleEndianOutput;
22
import org.apache.poi.util.LittleEndianOutput;
24
23
24
import java.util.Arrays;
25
25
/**
26
/**
26
 * DConRef records specify a range in a workbook (internal or external) that serves as a data source
27
 * DConRef records specify a range in a workbook (internal or external) that serves as a data source
27
 * for pivot tables or data consolidation.
28
 * for pivot tables or data consolidation.
Lines 273-279 Link Here
273
     */
274
     */
274
    public byte[] getPath()
275
    public byte[] getPath()
275
    {
276
    {
276
        return ArrayUtil.copyOf(path, path.length);
277
        return Arrays.copyOf(path, path.length);
277
    }
278
    }
278
279
279
    /**
280
    /**
Lines 291-297 Link Here
291
            {
292
            {
292
                offset++;
293
                offset++;
293
            }
294
            }
294
            String out = new String(ArrayUtil.copyOfRange(path, offset, path.length));
295
            String out = new String(Arrays.copyOfRange(path, offset, path.length));
295
            //UNC paths have \u0003 chars as path separators.
296
            //UNC paths have \u0003 chars as path separators.
296
            out = out.replaceAll("\u0003", "/");
297
            out = out.replaceAll("\u0003", "/");
297
            return out;
298
            return out;
(-)src/java/org/apache/poi/util/ArrayUtil.java (-85 lines)
Lines 106-194 Link Here
106
    	// We're done - array will now have everything moved as required
106
    	// We're done - array will now have everything moved as required
107
    }
107
    }
108
108
109
    /**
110
     * Copies the specified array, truncating or padding with zeros (if
111
     * necessary) so the copy has the specified length. This method is temporary
112
     * replace for Arrays.copyOf() until we start to require JDK 1.6.
113
     * 
114
     * @param source
115
     *            the array to be copied
116
     * @param newLength
117
     *            the length of the copy to be returned
118
     * @return a copy of the original array, truncated or padded with zeros to
119
     *         obtain the specified length
120
     * @throws NegativeArraySizeException
121
     *             if <tt>newLength</tt> is negative
122
     * @throws NullPointerException
123
     *             if <tt>original</tt> is null
124
     */
125
    public static byte[] copyOf( byte[] source, int newLength )
126
    {
127
        byte[] result = new byte[newLength];
128
        System.arraycopy( source, 0, result, 0,
129
                Math.min( source.length, newLength ) );
130
        return result;
131
    }
132
133
    /**
134
     * Copies the specified array into specified result array, truncating or
135
     * padding with zeros (if necessary) so the copy has the specified length.
136
     * This method is temporary replace for Arrays.copyOf() until we start to
137
     * require JDK 1.6.
138
     * 
139
     * @param source
140
     *            the array to be copied
141
     * @param result
142
     *            the array to be filled and returned
143
     * @throws NegativeArraySizeException
144
     *             if <tt>newLength</tt> is negative
145
     * @throws NullPointerException
146
     *             if <tt>original</tt> is null
147
     */
148
    public static <T> T[] copyOf( T[] source, T[] result )
149
    {
150
        System.arraycopy( source, 0, result, 0,
151
                Math.min( source.length, result.length ) );
152
        return result;
153
    }
154
155
    /**
156
     * Copies the specified range of the specified array into a new array.
157
     * The initial index of the range (<tt>from</tt>) must lie between zero
158
     * and <tt>original.length</tt>, inclusive.  The value at
159
     * <tt>original[from]</tt> is placed into the initial element of the copy
160
     * (unless <tt>from == original.length</tt> or <tt>from == to</tt>).
161
     * Values from subsequent elements in the original array are placed into
162
     * subsequent elements in the copy.  The final index of the range
163
     * (<tt>to</tt>), which must be greater than or equal to <tt>from</tt>,
164
     * may be greater than <tt>original.length</tt>, in which case
165
     * <tt>(byte)0</tt> is placed in all elements of the copy whose index is
166
     * greater than or equal to <tt>original.length - from</tt>.  The length
167
     * of the returned array will be <tt>to - from</tt>.
168
     *
169
     * This method is temporary
170
     * replace for Arrays.copyOfRange() until we start to require JDK 1.6.
171
     *
172
     * @param original the array from which a range is to be copied
173
     * @param from the initial index of the range to be copied, inclusive
174
     * @param to the final index of the range to be copied, exclusive.
175
     *     (This index may lie outside the array.)
176
     * @return a new array containing the specified range from the original array,
177
     *     truncated or padded with zeros to obtain the required length
178
     * @throws ArrayIndexOutOfBoundsException if <tt>from &lt; 0</tt>
179
     *     or <tt>from &gt; original.length()</tt>
180
     * @throws IllegalArgumentException if <tt>from &gt; to</tt>
181
     * @throws NullPointerException if <tt>original</tt> is null
182
     * @since 1.6
183
     */
184
    public static byte[] copyOfRange(byte[] original, int from, int to) {
185
        int newLength = to - from;
186
        if (newLength < 0)
187
            throw new IllegalArgumentException(from + " > " + to);
188
        byte[] copy = new byte[newLength];
189
        System.arraycopy(original, from, copy, 0,
190
                Math.min(original.length - from, newLength));
191
        return copy;
192
    }
193
194
}
109
}
(-)src/testcases/org/apache/poi/hssf/record/TestDConRefRecord.java (-2 / +1 lines)
Lines 23-29 Link Here
23
import java.io.IOException;
23
import java.io.IOException;
24
import java.util.Arrays;
24
import java.util.Arrays;
25
import junit.framework.TestCase;
25
import junit.framework.TestCase;
26
import org.apache.poi.util.ArrayUtil;
27
import org.apache.poi.util.LittleEndianOutputStream;
26
import org.apache.poi.util.LittleEndianOutputStream;
28
27
29
/**
28
/**
Lines 288-294 Link Here
288
    public void testGetPath()
287
    public void testGetPath()
289
    {
288
    {
290
        DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1));
289
        DConRefRecord instance = new DConRefRecord(TestcaseRecordInputStream.create(81, data1));
291
        byte[] expResult = ArrayUtil.copyOfRange(data1, 9, data1.length);
290
        byte[] expResult = Arrays.copyOfRange(data1, 9, data1.length);
292
        byte[] result = instance.getPath();
291
        byte[] result = instance.getPath();
293
        assertTrue("get path", Arrays.equals(expResult, result));
292
        assertTrue("get path", Arrays.equals(expResult, result));
294
    }
293
    }
(-)src/ooxml/testcases/org/apache/poi/xwpf/usermodel/TestXWPFDocument.java (-2 / +2 lines)
Lines 19-24 Link Here
19
19
20
import java.io.IOException;
20
import java.io.IOException;
21
import java.io.OutputStream;
21
import java.io.OutputStream;
22
import java.util.Arrays;
22
import java.util.List;
23
import java.util.List;
23
24
24
import junit.framework.TestCase;
25
import junit.framework.TestCase;
Lines 32-38 Link Here
32
import org.apache.poi.openxml4j.opc.PackageRelationship;
33
import org.apache.poi.openxml4j.opc.PackageRelationship;
33
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
34
import org.apache.poi.openxml4j.opc.PackagingURIHelper;
34
import org.apache.poi.openxml4j.opc.TargetMode;
35
import org.apache.poi.openxml4j.opc.TargetMode;
35
import org.apache.poi.util.ArrayUtil;
36
import org.apache.poi.xwpf.XWPFTestDataSamples;
36
import org.apache.poi.xwpf.XWPFTestDataSamples;
37
import org.apache.xmlbeans.XmlCursor;
37
import org.apache.xmlbeans.XmlCursor;
38
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
38
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTP;
Lines 307-313 Link Here
307
	    String id1 = doc.addPictureData(newPic, Document.PICTURE_TYPE_JPEG);
307
	    String id1 = doc.addPictureData(newPic, Document.PICTURE_TYPE_JPEG);
308
	    assertEquals(2,doc.getAllPackagePictures().size());
308
	    assertEquals(2,doc.getAllPackagePictures().size());
309
	    /* copy data, to avoid instance-equality */
309
	    /* copy data, to avoid instance-equality */
310
	    byte[] newPicCopy = ArrayUtil.copyOf(newPic, newPic.length);
310
	    byte[] newPicCopy = Arrays.copyOf(newPic, newPic.length);
311
	    String id2 = doc.addPictureData(newPicCopy, Document.PICTURE_TYPE_JPEG);
311
	    String id2 = doc.addPictureData(newPicCopy, Document.PICTURE_TYPE_JPEG);
312
	    assertEquals(id1,id2);
312
	    assertEquals(id1,id2);
313
	    doc.getPackage().revert();
313
	    doc.getPackage().revert();

Return to bug 56913