Helper function to concat two byte[]s into a new, larger one.

@param src
@param dst
@param srcPos
@param srcLength
@param dstPos
@param dstLength
@return byte[] (null if any errors)
177012
static public byte[] expandByteArray(byte[] src, byte[] dst, int srcPos, int srcLength, int dstPos, int dstLength) {
        byte[] rc = null;
        int totalLen = 0;
        if (null != src) {
            totalLen += srcLength;
        }
        if (null != dst) {
            totalLen += dstLength;
        }
        if (0 < totalLen) {
            rc = new byte[totalLen];
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Created byte[] of size " + totalLen);
            }
            try {
                if (null != src) {
                    System.arraycopy(src, srcPos, rc, 0, srcLength);
                }
                if (null != dst) {
                    System.arraycopy(dst, dstPos, rc, srcLength, dstLength);
                }
            } catch (Exception e) {
                // no FFDC required
                // any error from arraycopy, we'll just return null
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                    Tr.debug(tc, "Exception " + e + " while copying.");
                }
                rc = null;
            }
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "expandByteArray returning: [" + getEnglishString(rc) + "]");
        }
        return rc;
    }
364690
private byte[] concat(final byte[] input1, final byte[] input2, final int position) {
        // Preconition checks
        assert input1 != null : "Input 1 must be specified";
        assert input2 != null : "Input 2 must be specified";
        assert position >= 0 : "Position must be 0 or higher";
        // Allocate a new array of enough space (either current size or position + input2.length, whichever is greater)
        final int newSize = position < input1.length ? input1.length + input2.length : position + input2.length;
        final byte[] merged = new byte[newSize];
        // Copy in the contents of input 1 with 0 offset
        System.arraycopy(input1, 0, merged, 0, input1.length);
        // Copy in the contents of input2 with offset the length of input 1
        System.arraycopy(input2, 0, merged, position, input2.length);
        return merged;
    }
1344874
public static Double[] boxDoubles(Object src, int srcPos, int len) {
        return boxDoubles(array(src), srcPos, len);
    }
531350
public static void convert(DMatrixRMaj src , DMatrixRBlock dst ) {
        if( src.numRows != dst.numRows || src.numCols != dst.numCols )
            throw new IllegalArgumentException("Must be the same size.");

        for( int i = 0; i < dst.numRows; i += dst.blockLength ) {
            int blockHeight = Math.min( dst.blockLength , dst.numRows - i);

            for( int j = 0; j < dst.numCols; j += dst.blockLength ) {
                int blockWidth = Math.min( dst.blockLength , dst.numCols - j);

                int indexDst = i*dst.numCols + blockHeight*j;
                int indexSrcRow = i*dst.numCols + j;

                for( int k = 0; k < blockHeight; k++ ) {
                    System.arraycopy(src.data,indexSrcRow,dst.data,indexDst,blockWidth);
                    indexDst += blockWidth;
                    indexSrcRow += dst.numCols;
                }
            }
        }
    }
996355
private int merge(String[] dst, String[] srcA, int lengthA, Tag[] srcB, int lengthB) {
    int i = 0;
    int ai = 0;
    int bi = 0;

    while (ai < lengthA && bi < lengthB) {
      final String ak = srcA[ai];
      final String av = srcA[ai + 1];
      Tag b = srcB[bi];
      int cmp = ak.compareTo(b.key());
      if (cmp < 0) {
        dst[i++] = ak;
        dst[i++] = av;
        ai += 2;
      } else if (cmp > 0) {
        dst[i++] = b.key();
        dst[i++] = b.value();
        ++bi;
      } else {
        // Newer tags should override, use source B if there are duplicate keys.
        // If source B has duplicates, then use the last value for the given key.
        int j = bi + 1;
        for (; j < lengthB && ak.equals(srcB[j].key()); ++j) {
          b = srcB[j];
        }
        dst[i++] = b.key();
        dst[i++] = b.value();
        bi = j;
        ai += 2; // Ignore
      }
    }

    if (ai < lengthA) {
      System.arraycopy(srcA, ai, dst, i, lengthA - ai);
      i += lengthA - ai;
    } else if (bi < lengthB) {
      i = dedup(srcB, bi, dst, i, lengthB - bi);
    }

    return i;
  }
342420
static public byte[] expandByteArray(byte[] src, byte b) {

        int srcLength = (null != src) ? src.length : 0;
        int totalLen = srcLength + 1;
        byte[] rc = new byte[totalLen];
        try {
            if (null != src) {
                System.arraycopy(src, 0, rc, 0, srcLength);
            }
            rc[srcLength] = b;
        } catch (Exception e) {
            // no FFDC required
            // any error from arraycopy, we'll just return null
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                Tr.debug(tc, "Exception " + e + " while copying.");
            }
            rc = null;
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc,
                     "expandByteArray returning: [" + getEnglishString(rc) + "]");
        }
        return rc;
    }
1161271
public static Double decodeDoubleObjDesc(byte[] src, int srcOffset)
        throws CorruptEncodingException
    {
        long bits = DataDecoder.decodeDoubleBits(src, srcOffset);
        if (bits >= 0) {
            bits ^= 0x7fffffffffffffffL;
        }
        return bits == 0x7fffffffffffffffL ? null : Double.longBitsToDouble(bits);
    }
499941
public static Byte[] boxBytes(Object src, int srcPos, int len) {
        return boxBytes(array(src), srcPos, len);
    }
1211980
public static byte[] padLeftBytes(final byte[] src, final int bytes) {
    final byte[] dst = new byte[bytes];
    for (int i = 1; i <= src.length; i++) {
      dst[dst.length - i] = src[src.length - i];
    }
    return dst;
  }
1088472
public void concatInternal(String target, String [] srcs) 
    throws IOException {
    // actual move
    waitForReady();

    long now = FSNamesystem.now();
    unprotectedConcat(target, srcs, now);
    fsImage.getEditLog().logConcat(target, srcs, now);
  }
347869
public static char[] utf2chars(byte[] src, int sindex, int len) {
        char[] dst = new char[len];
        int len1 = utf2chars(src, sindex, dst, 0, len);
        char[] result = new char[len1];
        System.arraycopy(dst, 0, result, 0, len1);
        return result;
    }
146765
public static byte[] shiftRight(final byte[] src, final int bits) {
    final byte[] dst = new byte[src.length];
    shiftRight(src, bits, dst);
    return dst;
  }
1109135
public void copyTo(int srcOffs, byte[] dst, int offs, int len) {
        arraycopy(bytes, srcOffs, dst, offs, len);
    }
889002
public static <T extends Appendable> T toHexString(T dst, byte[] src, int offset, int length) {
        assert length >= 0;
        if (length == 0) {
            return dst;
        }

        final int end = offset + length;
        final int endMinusOne = end - 1;
        int i;

        // Skip preceding zeroes.
        for (i = offset; i < endMinusOne; i++) {
            if (src[i] != 0) {
                break;
            }
        }

        byteToHexString(dst, src[i++]);
        int remaining = end - i;
        toHexStringPadded(dst, src, i, remaining);

        return dst;
    }
194146
public static void encodeDesc(Boolean value, byte[] dst, int dstOffset) {
        if (value == null) {
            dst[dstOffset] = NULL_BYTE_LOW;
        } else {
            dst[dstOffset] = value.booleanValue() ? (byte)127 : (byte)128;
        }
    }
156966
public void addMapping( byte[] src, String dest ) throws IOException
    {
        if( src.length == 1 )
        {
        	singleByteMappings.put( Integer.valueOf( src[0] & 0xff ), dest );
        }
        else if( src.length == 2 )
        {
            int intSrc = src[0]&0xFF;
            intSrc <<= 8;
            intSrc |= (src[1]&0xFF);
            doubleByteMappings.put( Integer.valueOf( intSrc ), dest );
        }
        else
        {
            throw new IOException( "Mapping code should be 1 or two bytes and not " + src.length );
        }
    }
606692
private static byte[] concat(byte[] a, byte[] b)
    {
        byte[] c = new byte[a.length + b.length];
        System.arraycopy(a, 0, c, 0, a.length);
        System.arraycopy(b, 0, c, a.length, b.length);

        return c;
    }