java.util.Arrays#copyOf ( )源码实例Demo

下面列出了java.util.Arrays#copyOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: incubator-pinot   文件: AvroUtils.java
/**
 * Handles the conversion of each value of the Collection.
 * Converts the Collection to an Object array
 */
public static Object handleMultiValue(Collection values) {

  if (values.isEmpty()) {
    return null;
  }
  int numValues = values.size();
  Object[] array = new Object[numValues];
  int index = 0;
  for (Object value : values) {
    Object convertedValue = convert(value);
    if (convertedValue != null && !convertedValue.toString().equals("")) {
      array[index++] = convertedValue;
    }
  }
  if (index == numValues) {
    return array;
  } else if (index == 0) {
    return null;
  } else {
    return Arrays.copyOf(array, index);
  }
}
 
源代码2 项目: Bytecoder   文件: CopyOnWriteArrayList.java
/**
 * Inserts the specified element at the specified position in this
 * list. Shifts the element currently at that position (if any) and
 * any subsequent elements to the right (adds one to their indices).
 *
 * @throws IndexOutOfBoundsException {@inheritDoc}
 */
public void add(int index, E element) {
    synchronized (lock) {
        Object[] es = getArray();
        int len = es.length;
        if (index > len || index < 0)
            throw new IndexOutOfBoundsException(outOfBounds(index, len));
        Object[] newElements;
        int numMoved = len - index;
        if (numMoved == 0)
            newElements = Arrays.copyOf(es, len + 1);
        else {
            newElements = new Object[len + 1];
            System.arraycopy(es, 0, newElements, 0, index);
            System.arraycopy(es, index, newElements, index + 1,
                             numMoved);
        }
        newElements[index] = element;
        setArray(newElements);
    }
}
 
源代码3 项目: dragonwell8_jdk   文件: CipherCore.java
/**
 * Continues a multiple-part encryption or decryption operation
 * (depending on how this cipher was initialized), processing another data
 * part.
 *
 * <p>The first <code>inputLen</code> bytes in the <code>input</code>
 * buffer, starting at <code>inputOffset</code>, are processed, and the
 * result is stored in a new buffer.
 *
 * @param input the input buffer
 * @param inputOffset the offset in <code>input</code> where the input
 * starts
 * @param inputLen the input length
 *
 * @return the new buffer with the result
 *
 * @exception IllegalStateException if this cipher is in a wrong state
 * (e.g., has not been initialized)
 */
byte[] update(byte[] input, int inputOffset, int inputLen) {
    checkReinit();

    byte[] output = null;
    try {
        output = new byte[getOutputSizeByOperation(inputLen, false)];
        int len = update(input, inputOffset, inputLen, output,
                         0);
        if (len == output.length) {
            return output;
        } else {
            byte[] copy = Arrays.copyOf(output, len);
            if (decrypting) {
                // Zero out internal buffer which is no longer required
                Arrays.fill(output, (byte) 0x00);
            }
            return copy;
        }
    } catch (ShortBufferException e) {
        // should never happen
        throw new ProviderException("Unexpected exception", e);
    }
}
 
源代码4 项目: openjdk-jdk8u-backup   文件: ThreadGroup.java
void list(PrintStream out, int indent) {
    int ngroupsSnapshot;
    ThreadGroup[] groupsSnapshot;
    synchronized (this) {
        for (int j = 0 ; j < indent ; j++) {
            out.print(" ");
        }
        out.println(this);
        indent += 4;
        for (int i = 0 ; i < nthreads ; i++) {
            for (int j = 0 ; j < indent ; j++) {
                out.print(" ");
            }
            out.println(threads[i]);
        }
        ngroupsSnapshot = ngroups;
        if (groups != null) {
            groupsSnapshot = Arrays.copyOf(groups, ngroupsSnapshot);
        } else {
            groupsSnapshot = null;
        }
    }
    for (int i = 0 ; i < ngroupsSnapshot ; i++) {
        groupsSnapshot[i].list(out, indent);
    }
}
 
源代码5 项目: cxf   文件: JweUtils.java
public static byte[] getAdditionalAuthenticationData(String headersJson, byte[] aad) {
    byte[] headersAAD = JweHeaders.toCipherAdditionalAuthData(headersJson);
    if (aad != null) {
        // JWE JSON can provide the extra aad
        byte[] newAAD = Arrays.copyOf(headersAAD, headersAAD.length + 1 + aad.length);
        newAAD[headersAAD.length] = '.';
        System.arraycopy(aad, 0, newAAD, headersAAD.length + 1, aad.length);
        return newAAD;
    }
    return headersAAD;
}
 
源代码6 项目: jdk8u60   文件: SpinedBuffer.java
@Override
public String toString() {
    int[] array = asPrimitiveArray();
    if (array.length < 200) {
        return String.format("%s[length=%d, chunks=%d]%s",
                             getClass().getSimpleName(), array.length,
                             spineIndex, Arrays.toString(array));
    }
    else {
        int[] array2 = Arrays.copyOf(array, 200);
        return String.format("%s[length=%d, chunks=%d]%s...",
                             getClass().getSimpleName(), array.length,
                             spineIndex, Arrays.toString(array2));
    }
}
 
源代码7 项目: openjdk-jdk8u   文件: Window.java
private static Window[] getWindows(AppContext appContext) {
    synchronized (Window.class) {
        Window realCopy[];
        @SuppressWarnings("unchecked")
        Vector<WeakReference<Window>> windowList =
            (Vector<WeakReference<Window>>)appContext.get(Window.class);
        if (windowList != null) {
            int fullSize = windowList.size();
            int realSize = 0;
            Window fullCopy[] = new Window[fullSize];
            for (int i = 0; i < fullSize; i++) {
                Window w = windowList.get(i).get();
                if (w != null) {
                    fullCopy[realSize++] = w;
                }
            }
            if (fullSize != realSize) {
                realCopy = Arrays.copyOf(fullCopy, realSize);
            } else {
                realCopy = fullCopy;
            }
        } else {
            realCopy = new Window[0];
        }
        return realCopy;
    }
}
 
源代码8 项目: flink   文件: AbstractHeapPriorityQueue.java
protected void resizeQueueArray(int desiredSize, int minRequiredSize) {
	if (isValidArraySize(desiredSize)) {
		queue = Arrays.copyOf(queue, desiredSize);
	} else if (isValidArraySize(minRequiredSize)) {
		queue = Arrays.copyOf(queue, MAX_ARRAY_SIZE);
	} else {
		throw new OutOfMemoryError("Required minimum heap size " + minRequiredSize +
			" exceeds maximum size of " + MAX_ARRAY_SIZE + ".");
	}
}
 
源代码9 项目: jdk8u-dev-jdk   文件: PriorityBlockingQueue.java
/**
 * Creates a {@code PriorityBlockingQueue} containing the elements
 * in the specified collection.  If the specified collection is a
 * {@link SortedSet} or a {@link PriorityQueue}, this
 * priority queue will be ordered according to the same ordering.
 * Otherwise, this priority queue will be ordered according to the
 * {@linkplain Comparable natural ordering} of its elements.
 *
 * @param  c the collection whose elements are to be placed
 *         into this priority queue
 * @throws ClassCastException if elements of the specified collection
 *         cannot be compared to one another according to the priority
 *         queue's ordering
 * @throws NullPointerException if the specified collection or any
 *         of its elements are null
 */
public PriorityBlockingQueue(Collection<? extends E> c) {
    this.lock = new ReentrantLock();
    this.notEmpty = lock.newCondition();
    boolean heapify = true; // true if not known to be in heap order
    boolean screen = true;  // true if must screen for nulls
    if (c instanceof SortedSet<?>) {
        SortedSet<? extends E> ss = (SortedSet<? extends E>) c;
        this.comparator = (Comparator<? super E>) ss.comparator();
        heapify = false;
    }
    else if (c instanceof PriorityBlockingQueue<?>) {
        PriorityBlockingQueue<? extends E> pq =
            (PriorityBlockingQueue<? extends E>) c;
        this.comparator = (Comparator<? super E>) pq.comparator();
        screen = false;
        if (pq.getClass() == PriorityBlockingQueue.class) // exact match
            heapify = false;
    }
    Object[] a = c.toArray();
    int n = a.length;
    // If c.toArray incorrectly doesn't return Object[], copy it.
    if (a.getClass() != Object[].class)
        a = Arrays.copyOf(a, n, Object[].class);
    if (screen && (n == 1 || this.comparator != null)) {
        for (int i = 0; i < n; ++i)
            if (a[i] == null)
                throw new NullPointerException();
    }
    this.queue = a;
    this.size = n;
    if (heapify)
        heapify();
}
 
源代码10 项目: lua-for-android   文件: MultiTaskListener.java
public void add(TaskListener listener) {
    for (TaskListener l: listeners) {
        if (ccw.unwrap(l) == listener)
            throw new IllegalStateException();
    }
    listeners = Arrays.copyOf(listeners, listeners.length + 1);
    listeners[listeners.length - 1] = ccw.wrap(listener);
}
 
源代码11 项目: wildfly-core   文件: BasicHistoryUnitTestCase.java
@Test
public void testAutoResolveConflicts() throws Exception {

    final PatchingTestBuilder builder = createDefaultBuilder();

    // Create a file
    final File existing = builder.getFile(FILE_EXISTING);
    touch(existing);
    dump(existing, randomString());
    final byte[] existingHash = hashFile(existing);
    final byte[] initialHash = Arrays.copyOf(existingHash, existingHash.length);

    final byte[] moduleHash = new byte[20];

    final PatchingTestStepBuilder oo1 = builder.createStepBuilder();
    oo1.setPatchId("one-off-one")
            .oneOffPatchIdentity(PRODUCT_VERSION)
            .updateFileWithRandomContent(initialHash, existingHash, FILE_EXISTING)
            .oneOffPatchElement("base-one-off", "base", false)
            .addModuleWithRandomContent("test.module", moduleHash)
    ;
    // Apply OO1
    apply(oo1);

    final PatchingTestStepBuilder cp1 = builder.createStepBuilder();
    cp1.setPatchId("CP1")
            .upgradeIdentity(PRODUCT_VERSION, PRODUCT_VERSION)
            .updateFileWithRandomContent(initialHash, existingHash, FILE_EXISTING)
            .upgradeElement("base-cp1", "base", false)
            .addModuleWithRandomContent("test.module", moduleHash)
    ;
    // Apply CP1
    apply(cp1);
    rollback(cp1);
    rollback(oo1);
}
 
源代码12 项目: meka   文件: HARAMNetwork.java
private void ARAMm_Add_New_Category() {

		weightsA = Arrays.copyOf(weightsA, numCategories + 1);
		weightsB = Arrays.copyOf(weightsB, numCategories + 1);
		weightsA[numCategories] = new double[numFeatures];
		weightsB[numCategories] = new double[numClasses];
		Arrays.fill(weightsA[numCategories], 1.0);
		Arrays.fill(weightsB[numCategories], 0.0);
		numCategories += 1;

	}
 
源代码13 项目: openjdk-8   文件: NTLM.java
byte[] ntlm2NTLM(byte[] ntlmHash, byte[] nonce, byte[] challenge) {
    byte[] b = Arrays.copyOf(challenge, 16);
    System.arraycopy(nonce, 0, b, 8, 8);
    byte[] sesshash = Arrays.copyOf(md5.digest(b), 8);
    return calcResponse(ntlmHash, sesshash);
}
 
源代码14 项目: terracotta-platform   文件: DefaultCallQuery.java
@Override
public Parameter[] getParameters() {
  return Arrays.copyOf(parameters, parameters.length);
}
 
源代码15 项目: openjdk-jdk9   文件: ZipFile.java
private int getEntryPos(byte[] name, boolean addSlash) {
    if (total == 0) {
        return -1;
    }
    int hsh = hashN(name, 0, name.length);
    int idx = table[(hsh & 0x7fffffff) % tablelen];
    /*
     * This while loop is an optimization where a double lookup
     * for name and name+/ is being performed. The name char
     * array has enough room at the end to try again with a
     * slash appended if the first table lookup does not succeed.
     */
    while(true) {
        /*
         * Search down the target hash chain for a entry whose
         * 32 bit hash matches the hashed name.
         */
        while (idx != ZIP_ENDCHAIN) {
            if (getEntryHash(idx) == hsh) {
                // The CEN name must match the specfied one
                int pos = getEntryPos(idx);
                if (name.length == CENNAM(cen, pos)) {
                    boolean matched = true;
                    int nameoff = pos + CENHDR;
                    for (int i = 0; i < name.length; i++) {
                        if (name[i] != cen[nameoff++]) {
                            matched = false;
                            break;
                        }
                    }
                    if (matched) {
                        return pos;
                    }
                 }
            }
            idx = getEntryNext(idx);
        }
        /* If not addSlash, or slash is already there, we are done */
        if (!addSlash  || name.length == 0 || name[name.length - 1] == '/') {
             return -1;
        }
        /* Add slash and try once more */
        name = Arrays.copyOf(name, name.length + 1);
        name[name.length - 1] = '/';
        hsh = hash_append(hsh, (byte)'/');
        //idx = table[hsh % tablelen];
        idx = table[(hsh & 0x7fffffff) % tablelen];
        addSlash = false;
    }
}
 
源代码16 项目: AndroidChromium   文件: MediaSource.java
/**
 * @return application capabilities
 */
public String[] getCapabilities() {
    return mCapabilities == null ? null : Arrays.copyOf(mCapabilities, mCapabilities.length);
}
 
源代码17 项目: zigbee4java   文件: ZToolAddress64.java
public ZToolAddress64(byte[] address) {
    this.address = Arrays.copyOf(address, address.length);
}
 
源代码18 项目: constellation   文件: StringAttributeDescription.java
@Override
public Object saveData() {
    return Arrays.copyOf(data, data.length);
}
 
源代码19 项目: sql-layer   文件: TInstanceGenerator.java
public TInstanceGenerator(TClass tclass, int... attrs) {
    this.tclass = tclass;
    this.attrs = Arrays.copyOf(attrs, attrs.length);
}
 
/**
 * Returns the value of the OUI.
 * @return The value of the OUI .
 */
public byte[] getOUI() {
    return Arrays.copyOf(oui, oui.length);
}