Example usage for org.apache.commons.lang ArrayUtils addAll

List of usage examples for org.apache.commons.lang ArrayUtils addAll

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils addAll.

Prototype

public static double[] addAll(double[] array1, double[] array2) 

Source Link

Document

Adds all the elements of the given arrays into a new array.

Usage

From source file:fit.Binding.java

private static Field[] getAllDeclaredFields(Class<?> clazz) {
    if (clazz.getSuperclass() != null) {
        return (Field[]) ArrayUtils.addAll(getAllDeclaredFields(clazz.getSuperclass()),
                clazz.getDeclaredFields());
    } else {// www .  j  av  a 2 s .  c  o  m
        return clazz.getDeclaredFields();
    }
}

From source file:gov.nih.nci.caarray.domain.MultiPartBlob.java

/**
 * Method that takes an input stream and breaks it up in to multiple blobs. Note that this method loads each chunk
 * in to a byte[], while this is not ideal, this will be done by the mysql driver anyway, so we are not adding a new
 * inefficiency.//w  ww  .jav  a 2 s  .com
 * 
 * @param data the input stream to store.
 * @param compress true to compress the data, false to leave it uncompressed
 * @param blobPartSize the maximum size of a single blob
 * @throws IOException on error reading from the stream.
 */
public void writeData(InputStream data, boolean compress, int blobPartSize) throws IOException {
    final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    OutputStream writeStream;
    if (compress) {
        writeStream = new GZIPOutputStream(byteStream);
    } else {
        writeStream = byteStream;
    }
    byte[] unwritten = new byte[0];
    final byte[] uncompressed = new byte[blobPartSize];
    int len = 0;
    while ((len = data.read(uncompressed)) > 0) {
        uncompressedSize += len;
        writeStream.write(uncompressed, 0, len);
        if (byteStream.size() + unwritten.length >= blobPartSize) {
            compressedSize += byteStream.size();
            unwritten = writeData(ArrayUtils.addAll(unwritten, byteStream.toByteArray()), blobPartSize, false);
            byteStream.reset();
        }
    }
    IOUtils.closeQuietly(writeStream);
    compressedSize += byteStream.size();
    writeData(ArrayUtils.addAll(unwritten, byteStream.toByteArray()), blobPartSize, true);
}

From source file:it.issue.IssueFilterOnCommonRulesTest.java

private void executeAnalysis(String... serverProperties) {
    String[] cpdProperties = new String[] { "sonar.cpd.xoo.minimumTokens", "2", "sonar.cpd.xoo.minimumLines",
            "2" };
    setServerProperties(ORCHESTRATOR, PROJECT_KEY,
            (String[]) ArrayUtils.addAll(serverProperties, cpdProperties));
    runProjectAnalysis(ORCHESTRATOR, PROJECT_DIR);
}

From source file:com.exalttech.trex.packets.TrexEthernetPacket.java

private void fixPacketLength() {
    try {/*from ww w.  j a v  a2s  .co  m*/
        EthernetPacket newPacket = packet;
        if (packet.getRawData().length < getLength()) {
            byte[] pad = new byte[getLength() - packet.getRawData().length];
            newPacket = EthernetPacket.newPacket(ArrayUtils.addAll(packet.getRawData(), pad), 0, getLength());
        } else {
            newPacket = EthernetPacket.newPacket(packet.getRawData(), 0, getLength());
        }

        setPacket((EthernetPacket) newPacket);
    } catch (IllegalRawDataException ex) {
        Logger.getLogger(TrexEthernetPacket.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:com.aliyun.odps.mapred.local.MapOutputBuffer.java

public void add(Record key, Record value) {
    int partition = getPartition(key);
    buffers.get(partition).offer(ArrayUtils.addAll(((WritableRecord) key).toWritableArray().clone(),
            ((WritableRecord) value).toWritableArray().clone()));
}

From source file:com.torodb.integration.mongo.v3m0.jstests.AbstractIntegrationTest.java

protected Process runMongoProcess(String toroConnectionString, URL mongoMocksUrl, String... parameters)
        throws IOException {
    Process mongoProcess = Runtime.getRuntime().exec((String[]) ArrayUtils.addAll(
            new String[] { "mongo", toroConnectionString, mongoMocksUrl.getPath(), script.getURL().getPath(), },
            parameters));// w ww  .  j a v a2 s. co m
    return mongoProcess;
}

From source file:net.iponweb.hadoop.streaming.parquet.TextRecordWriterWrapper.java

@Override
public void write(Text key, Text value) throws IOException {

    Group grp = factory.newGroup();

    String[] strK = key.toString().split(TAB, -1);
    String[] strV = value == null ? new String[0] : value.toString().split(TAB, -1);
    String kv_combined[] = (String[]) ArrayUtils.addAll(strK, strV);

    Iterator<PathAction> ai = recorder.iterator();

    Stack<Group> groupStack = new Stack<>();
    groupStack.push(grp);/*from w  w w .j a  v  a2 s.c o m*/
    int i = 0;

    try {
        while (ai.hasNext()) {

            PathAction a = ai.next();
            switch (a.getAction()) {
            case GROUPEND:
                grp = groupStack.pop();
                break;

            case GROUPSTART:
                groupStack.push(grp);
                grp = grp.addGroup(a.getName());
                break;

            case FIELD:
                String s = null;
                PrimitiveType.PrimitiveTypeName primType = a.getType();
                String colName = a.getName();

                if (i < kv_combined.length)
                    s = kv_combined[i++];

                if (s == null) {
                    if (a.getRepetition() == Type.Repetition.OPTIONAL) {
                        i++;
                        continue;
                    }
                    s = primType == PrimitiveType.PrimitiveTypeName.BINARY ? "" : "0";
                }

                // If we have 'repeated' field, assume that we should expect JSON-encoded array
                // Convert array and append all values
                int repetition = 1;
                boolean repeated = false;
                ArrayList<String> s_vals = null;
                if (a.getRepetition() == Type.Repetition.REPEATED) {
                    repeated = true;
                    s_vals = new ArrayList<>();
                    ObjectMapper mapper = new ObjectMapper();
                    JsonNode node = mapper.readTree(s);
                    Iterator<JsonNode> itr = node.iterator();
                    repetition = 0;
                    while (itr.hasNext()) {

                        String o;
                        switch (primType) {
                        case BINARY:
                            o = itr.next().getTextValue(); // No array-of-objects!
                            break;
                        case BOOLEAN:
                            o = String.valueOf(itr.next().getBooleanValue());
                            break;
                        default:
                            o = String.valueOf(itr.next().getNumberValue());
                        }

                        s_vals.add(o);
                        repetition++;
                    }
                }

                for (int j = 0; j < repetition; j++) {

                    if (repeated)
                        // extract new s
                        s = s_vals.get(j);

                    try {
                        switch (primType) {

                        case INT32:
                            grp.append(colName, new Double(Double.parseDouble(s)).intValue());
                            break;
                        case INT64:
                        case INT96:
                            grp.append(colName, new Double(Double.parseDouble(s)).longValue());
                            break;
                        case DOUBLE:
                            grp.append(colName, Double.parseDouble(s));
                            break;
                        case FLOAT:
                            grp.append(colName, Float.parseFloat(s));
                            break;
                        case BOOLEAN:
                            grp.append(colName, s.equalsIgnoreCase("true") || s.equals("1"));
                            break;
                        case BINARY:
                            grp.append(colName, Binary.fromString(s));
                            break;
                        default:
                            throw new RuntimeException("Can't handle type " + primType);
                        }
                    } catch (NumberFormatException e) {

                        grp.append(colName, 0);
                    }
                }
            }
        }

        realWriter.write(null, (SimpleGroup) grp);

    } catch (InterruptedException e) {
        Thread.interrupted();
        throw new IOException(e);
    } catch (Exception e) {
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(out));
        throw new RuntimeException("Failed on record " + grp + ", schema=" + schema + ", path action="
                + recorder + " exception = " + e.getClass() + ", msg=" + e.getMessage() + ", cause="
                + e.getCause() + ", trace=" + out.toString());
    }

}

From source file:com.gallatinsystems.survey.dao.SurveyUtils.java

public static Question copyQuestion(Question source, Long newQuestionGroupId, Integer order, Long newSurveyId) {

    final QuestionDao qDao = new QuestionDao();
    final QuestionOptionDao qoDao = new QuestionOptionDao();
    final Question tmp = new Question();

    final String[] questionExcludedProps = { "questionOptionMap", "questionHelpMediaMap", "scoringRules",
            "translationMap", "order", "questionId" };

    final String[] allExcludedProps = (String[]) ArrayUtils.addAll(questionExcludedProps,
            Constants.EXCLUDED_PROPERTIES);

    BeanUtils.copyProperties(source, tmp, allExcludedProps);
    tmp.setOrder(order);/*from  w w w .j a va2  s.  co  m*/
    if (source.getQuestionId() != null) {
        tmp.setQuestionId(source.getQuestionId() + "_copy");
    }
    log.log(Level.INFO, "Copying `Question` " + source.getKey().getId());

    final Question newQuestion = qDao.save(tmp, newQuestionGroupId);

    log.log(Level.INFO, "New `Question` ID: " + newQuestion.getKey().getId());

    log.log(Level.INFO, "Copying question translations");

    SurveyUtils.copyTranslation(source.getKey().getId(), newQuestion.getKey().getId(), newSurveyId,
            newQuestionGroupId, ParentType.QUESTION_NAME, ParentType.QUESTION_DESC, ParentType.QUESTION_TEXT,
            ParentType.QUESTION_TIP);

    if (!Question.Type.OPTION.equals(newQuestion.getType())) {
        // Nothing more to do
        return newQuestion;
    }

    final TreeMap<Integer, QuestionOption> options = qoDao.listOptionByQuestion(source.getKey().getId());

    if (options == null) {
        return newQuestion;
    }

    log.log(Level.INFO, "Copying " + options.values().size() + " `QuestionOption`");

    // Copying Question Options
    for (QuestionOption qo : options.values()) {
        SurveyUtils.copyQuestionOption(qo, newQuestion.getKey().getId(), newSurveyId, newQuestionGroupId);
    }

    return newQuestion;
}

From source file:info.magnolia.cms.filters.AbstractMgnlFilter.java

public void setBypasses(Voter[] bypasses) {
    this.bypasses = (Voter[]) ArrayUtils.addAll(this.bypasses, bypasses);
}

From source file:app.Des.java

private String cipher(int[] message, List<int[]> keys) {
    int[] messPermuted = this.tables.getIP_Message(message);
    int[] messL = ArrayUtils.subarray(messPermuted, 0, messPermuted.length / 2);
    int[] messR = ArrayUtils.subarray(messPermuted, messPermuted.length / 2, messPermuted.length);

    for (int[] key1 : keys) {
        int[] eMessR = this.tables.getE_Message(messR);

        int[] xorResult = new int[eMessR.length];
        for (int i = 0; i < eMessR.length; i++) {
            xorResult[i] = binMath.xor(eMessR[i], key1[i]);
        }//w  ww.java2 s.c o m

        String row = "";
        String column = "";
        int[] sTransformedMess = new int[32];
        int sTransformedIndex = 0;
        int sTableIndex = 0;
        for (int i = 0; i < xorResult.length; i = i + 6, sTableIndex++) {
            row = String.valueOf(xorResult[i]) + String.valueOf(xorResult[i + 5]);
            column = String.valueOf(xorResult[i + 1]) + String.valueOf(xorResult[i + 2])
                    + String.valueOf(xorResult[i + 3]) + String.valueOf(xorResult[i + 4]);

            int sTableNumber = this.tables.getSTables().get(sTableIndex)[Integer.parseInt(row, 2)][Integer
                    .parseInt(column, 2)];
            String binary = this.binMath.intToString(sTableNumber);

            for (int bin = 0; bin < binary.length(); bin++) {
                sTransformedMess[sTransformedIndex + bin] = Integer.parseInt(binary.charAt(bin) + "");
            }
            sTransformedIndex += binary.length();
        }
        int[] pMessage = this.tables.getP_Message(sTransformedMess);

        int[] tempR = new int[messR.length];
        for (int i = 0; i < messL.length; i++) {
            tempR[i] = binMath.xor(messL[i], pMessage[i]);
        }
        messL = ArrayUtils.clone(messR);
        messR = ArrayUtils.clone(tempR);
    }
    int[] lastPermuted = this.tables.getIPInverse_Message(ArrayUtils.addAll(messR, messL));
    String hex = binMath.fromBinStringToHexString(getString(lastPermuted, 0));
    return hex;
}