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:gov.nasa.ensemble.core.plan.advisor.view.PlanAdvisorPage.java

private static ISelection getCombinedSelection(ISelection selection1, ISelection selection2) {
    if (selection2 == null || selection2.isEmpty() || !(selection2 instanceof IStructuredSelection)) {
        return selection1;
    }/*w  ww  .  j  a v a  2 s  .  c o m*/
    if (selection1 == null || selection1.isEmpty() || !(selection1 instanceof IStructuredSelection)) {
        return selection2;
    }
    Object[] elements1 = ((IStructuredSelection) selection1).toArray();
    Object[] elements2 = ((IStructuredSelection) selection2).toArray();
    Object[] combinedArray = ArrayUtils.addAll(elements1, elements2);
    return new StructuredSelection(combinedArray);
}

From source file:com.ec.android.module.bluetooth40.base.BaseBluetoothControlWithProtocolActivity.java

/**
 * ?//from  w  w w  .  j  a  va2 s  .co  m
 * TODO ?
 *
 * @param data
 */
private void onReceiveData(byte[] data) {
    if (data.length < 7) {
        //?7header??
        return;
    }
    //
    byte magic = data[0];

    if (magic != Packet.MAGIC_BYTE) {
        //?
        return;
    }
    //
    byte dataMuti = data[1];
    byte errFlag = (byte) (dataMuti & 0x08);
    //
    int payloadLength = data[2];

    if (payloadLength < 0) {
        payloadLength = 256 + payloadLength;
    }
    ////
    byte sequenceIdHigh8 = data[3];
    byte sequenceIdLow8 = data[4];
    //
    int sequenceIdHigh8Int = sequenceIdHigh8;
    int sequenceIdLow8Int = sequenceIdLow8;
    //
    if (sequenceIdHigh8 < 0) {
        sequenceIdHigh8Int = (256 + sequenceIdHigh8);
    }
    if (sequenceIdLow8 < 0) {
        sequenceIdLow8Int = (256 + sequenceIdLow8);
    }
    //
    //        short sequenceIdTemp = 0;
    //sequenceIdpacket
    short sequenceId = (short) ((sequenceIdHigh8Int << 8) + sequenceIdLow8Int);
    //
    if (errFlag == 0x08) {
        //??1
        mProtocolDataUtils.putErrFlag(sequenceId, true);
        return;
    } else {
        //???0
        mProtocolDataUtils.putErrFlag(sequenceId, false);
    }
    //
    byte ackFlag = (byte) (dataMuti & 0x04);
    if (ackFlag == 0x04) {
        //??1
        //packet?

    } else {
        //???
        //??
        //
        byte beginFlag = (byte) (dataMuti & 0x02);
        byte endFlag = (byte) (dataMuti & 0x01);
        //?packet
        //
        int myCrc = magic ^ data[1] ^ payloadLength ^ sequenceId;

        int crcHigh = data[5];
        int crcLow = data[6];

        if (crcHigh < 0) {
            crcHigh = 256 + crcHigh;
        }
        if (crcLow < 0) {
            crcLow = 256 + crcLow;
        }

        //            int crcTemp = 0x00;
        //
        int crc = (crcHigh << 8) + crcLow;

        if (crc != myCrc) {
            //?
            mProtocolDataUtils.removeGetDataMap(sequenceId);
            return;
        }
        //?
        byte[] bodyBytes = ArrayUtils.subarray(data, 7, data.length);
        //
        if (beginFlag == 0x02) {
            //??1?packet
            //packet??sequenceId??????
            mProtocolDataUtils.removeGetDataMap(sequenceId);
            mProtocolDataUtils.plusGetDataMap(sequenceId, ArrayUtils.toObject(bodyBytes));
        } else {
            //??0??packet
            //???sequenceId???
            ArrayList<Byte[]> getDataMapList = mProtocolDataUtils.getGetDataMap(sequenceId);
            if (getDataMapList == null || getDataMapList.isEmpty()) {
                return;
            } else {
                //??
                mProtocolDataUtils.plusGetDataMap(sequenceId, ArrayUtils.toObject(bodyBytes));
            }
        }
        //
        if (endFlag == 0x01) {
            //??1??packet
            //??
            ArrayList<Byte[]> getDataMapList = mProtocolDataUtils.getGetDataMap(sequenceId);

            if (getDataMapList != null) {
                Byte[] myAllBytes = null;
                for (Byte[] bytes : getDataMapList) {
                    myAllBytes = (Byte[]) ArrayUtils.addAll(myAllBytes, bytes);
                }
                //?
                mProtocolDataUtils.removeGetDataMap(sequenceId);
                //
                onActionDataAvailable(myAllBytes);
            }
        }
    }
    //
}

From source file:io.fabric8.kubernetes.api.KubernetesFactory.java

private void configureCaCert(WebClient webClient) {
    try (InputStream pemInputStream = getInputStreamFromDataOrFile(caCertData, caCertFile)) {
        CertificateFactory certFactory = CertificateFactory.getInstance("X509");
        X509Certificate cert = (X509Certificate) certFactory.generateCertificate(pemInputStream);

        KeyStore trustStore = KeyStore.getInstance("JKS");
        trustStore.load(null);/*from ww w.j a  v  a  2s  .  c om*/

        String alias = cert.getSubjectX500Principal().getName();
        trustStore.setCertificateEntry(alias, cert);

        TrustManagerFactory trustManagerFactory = TrustManagerFactory
                .getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustManagerFactory.init(trustStore);

        HTTPConduit conduit = WebClient.getConfig(webClient).getHttpConduit();

        TLSClientParameters params = conduit.getTlsClientParameters();

        if (params == null) {
            params = new TLSClientParameters();
            conduit.setTlsClientParameters(params);
        }

        TrustManager[] existingTrustManagers = params.getTrustManagers();
        TrustManager[] trustManagers;

        if (existingTrustManagers == null || ArrayUtils.isEmpty(existingTrustManagers)) {
            trustManagers = trustManagerFactory.getTrustManagers();
        } else {
            trustManagers = (TrustManager[]) ArrayUtils.addAll(existingTrustManagers,
                    trustManagerFactory.getTrustManagers());
        }

        params.setTrustManagers(trustManagers);

    } catch (Exception e) {
        log.error("Could not create trust manager for " + caCertFile, e);
    }
}

From source file:marytts.unitselection.analysis.Phone.java

/**
 * Get the durations (in seconds) of each Datagram in this phone's left and right units
 * //w ww  .j ava 2s.c o m
 * @return the durations of all Datagrams in this phone in an array
 */
public double[] getRealizedFrameDurations() {
    return ArrayUtils.addAll(getLeftUnitFrameDurations(), getRightUnitFrameDurations());
}

From source file:com.rapidminer.gui.properties.RegexpPropertyDialog.java

public RegexpPropertyDialog(final Collection<String> items, String predefinedRegexp, String description) {
    super(ApplicationFrame.getApplicationFrame(), "parameter.regexp", ModalityType.APPLICATION_MODAL,
            new Object[] {});
    this.items = items;
    this.supportsItems = items != null;
    this.infoText = "<html>" + I18N.getMessage(I18N.getGUIBundle(), getKey() + ".title") + ": <br/>"
            + description + "</html>";
    Dimension size = new Dimension(420, 500);
    this.setMinimumSize(size);
    this.setPreferredSize(size);

    JPanel panel = new JPanel(createGridLayout(1, supportsItems ? 2 : 1));

    // create regexp text field
    regexpTextField = new JTextField(predefinedRegexp);
    regexpTextField.setToolTipText(/*from w  w  w  .j  a v a  2 s .  c o m*/
            I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.tip"));
    regexpTextField.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            fireRegularExpressionUpdated();
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

    });
    regexpTextField.requestFocus();

    // create replacement text field
    replacementTextField = new JTextField();
    replacementTextField.setToolTipText(
            I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.replacement.tip"));
    replacementTextField.addKeyListener(new KeyListener() {

        @Override
        public void keyPressed(KeyEvent e) {
        }

        @Override
        public void keyReleased(KeyEvent e) {
            fireRegularExpressionUpdated();
        }

        @Override
        public void keyTyped(KeyEvent e) {
        }

    });

    // create inline search documents
    inlineSearchDocument = new RegexpSearchStyledDocument();
    inlineReplaceDocument = new RegexpReplaceStyledDocument();

    // create search results list
    DefaultListCellRenderer resultCellRenderer = new DefaultListCellRenderer() {

        private static final long serialVersionUID = 1L;

        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            setBackground(list.getBackground());
            setForeground(list.getForeground());
            setBorder(getNoFocusBorder());
            return this;
        }

        private Border getNoFocusBorder() {
            Border border = BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray);
            return border;
        }
    };

    JList<RegExpResult> regexpFindingsList = new JList<RegExpResult>(resultsListModel);
    regexpFindingsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    regexpFindingsList.setLayoutOrientation(JList.VERTICAL);
    regexpFindingsList.setCellRenderer(resultCellRenderer);

    // regexp panel on left side of dialog
    JPanel regexpPanel = new JPanel(new GridBagLayout());
    regexpPanel.setBorder(createTitledBorder(
            I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.regular_expression.border")));
    GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(4, 4, 4, 0);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.fill = GridBagConstraints.BOTH;
    regexpPanel.add(regexpTextField, c);

    // make shortcut button
    final Action nullAction = new DefaultAction();
    PlainArrowDropDownButton autoWireDropDownButton = PlainArrowDropDownButton.makeDropDownButton(nullAction);

    for (String[] popupItem : (String[][]) ArrayUtils.addAll(regexpConstructs, regexpShortcuts)) {
        String shortcut = popupItem[0].length() > 14 ? popupItem[0].substring(0, 14) + "..." : popupItem[0];
        autoWireDropDownButton
                .add(new InsertionAction("<html><table border=0 cellpadding=0 cellspacing=0><tr><td width=100>"
                        + shortcut + "</td><td>" + popupItem[1] + "</td></tr></table></html>", popupItem[0]));
    }
    c.insets = new Insets(4, 0, 4, 0);
    c.gridx = 1;
    c.weightx = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    regexpPanel.add(autoWireDropDownButton.getDropDownArrowButton(), c);

    // make delete button
    c.insets = new Insets(4, 0, 4, 4);
    c.gridx = 2;
    c.weightx = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    JButton clearRegexpTextFieldButton = new JButton(SwingTools.createIcon("16/delete2.png"));
    clearRegexpTextFieldButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            regexpTextField.setText("");
            fireRegularExpressionUpdated();
            regexpTextField.requestFocusInWindow();
        }
    });

    regexpPanel.add(clearRegexpTextFieldButton, c);

    errorMessage = new JLabel(NO_ERROR_MESSAGE, NO_ERROR_ICON, SwingConstants.LEFT);
    errorMessage.setFocusable(false);
    c.insets = new Insets(4, 8, 4, 4);
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    regexpPanel.add(errorMessage, c);

    // create replacement panel
    JPanel replacementPanel = new JPanel(new GridBagLayout());
    replacementPanel.setBorder(createTitledBorder(
            I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.replacement.border")));

    JPanel testerPanel = new JPanel(new GridBagLayout());

    c.insets = new Insets(4, 4, 4, 0);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    replacementPanel.add(replacementTextField, c);

    // create inline search panel
    JPanel inlineSearchPanel = new JPanel(new GridBagLayout());

    c.insets = new Insets(8, 4, 4, 4);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    inlineSearchPanel.add(
            new JLabel(
                    I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.inline_search.search")),
            c);

    c.insets = new Insets(0, 0, 0, 0);
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    inlineSearchPanel.add(new JScrollPane(new JTextPane(inlineSearchDocument)), c);

    c.insets = new Insets(8, 4, 4, 4);
    c.gridx = 0;
    c.gridy = 2;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    inlineSearchPanel.add(
            new JLabel(
                    I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.inline_search.replaced")),
            c);

    c.insets = new Insets(0, 0, 0, 0);
    c.gridx = 0;
    c.gridy = 3;
    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    JTextPane replaceTextPane = new JTextPane(inlineReplaceDocument);
    replaceTextPane.setEditable(false);
    inlineSearchPanel.add(new JScrollPane(replaceTextPane), c);

    // create regexp options panel
    ItemListener defaultOptionListener = new ItemListener() {

        @Override
        public void itemStateChanged(ItemEvent e) {
            fireRegexpOptionsChanged();
        }
    };

    cbCaseInsensitive = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.case_insensitive"));
    cbCaseInsensitive.setToolTipText(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.case_insensitive.tip"));
    cbCaseInsensitive.addItemListener(defaultOptionListener);

    cbMultiline = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.multiline_mode"));
    cbMultiline.setToolTipText(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.multiline_mode.tip"));
    cbMultiline.addItemListener(defaultOptionListener);

    cbDotall = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.dotall_mode"));
    cbDotall.setToolTipText(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.dotall_mode.tip"));
    cbDotall.addItemListener(defaultOptionListener);

    cbUnicodeCase = new JCheckBox(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.unicode_case"));
    cbUnicodeCase.setToolTipText(I18N.getMessage(I18N.getGUIBundle(),
            "gui.dialog.parameter.regexp.regular_expression.regexp_options.unicode_case.tip"));
    cbUnicodeCase.addItemListener(defaultOptionListener);

    JPanel regexpOptionsPanelWrapper = new JPanel(new BorderLayout());
    JPanel regexpOptionsPanel = new JPanel(new GridBagLayout());
    regexpOptionsPanelWrapper.add(regexpOptionsPanel, BorderLayout.NORTH);

    c.insets = new Insets(12, 4, 0, 4);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    regexpOptionsPanel.add(cbMultiline, c);
    c.insets = new Insets(8, 4, 0, 4);
    c.gridy = 1;
    regexpOptionsPanel.add(cbCaseInsensitive, c);
    c.gridy = 2;
    regexpOptionsPanel.add(cbUnicodeCase, c);
    c.gridy = 3;
    regexpOptionsPanel.add(cbDotall, c);

    // create tabbed panel
    c.insets = new Insets(8, 4, 4, 4);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.BOTH;
    testExp = new JTabbedPane();
    testExp.add(
            I18N.getMessage(I18N.getGUIBundle(),
                    "gui.dialog.parameter.regexp.regular_expression.inline_search.title"),
            new JScrollPane(inlineSearchPanel));
    testExp.add(
            I18N.getMessage(I18N.getGUIBundle(),
                    "gui.dialog.parameter.regexp.regular_expression.result_list.title"),
            new JScrollPane(regexpFindingsList));
    testExp.add(
            I18N.getMessage(I18N.getGUIBundle(),
                    "gui.dialog.parameter.regexp.regular_expression.regexp_options.title"),
            regexpOptionsPanelWrapper);
    testerPanel.add(testExp, c);

    JPanel groupPanel = new JPanel(new GridBagLayout());
    c.insets = new Insets(4, 4, 4, 4);
    c.gridx = 0;
    c.gridy = 0;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    groupPanel.add(regexpPanel, c);

    c.insets = new Insets(4, 4, 4, 4);
    c.gridx = 0;
    c.gridy = 1;
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    groupPanel.add(replacementPanel, c);

    c.insets = new Insets(4, 4, 4, 4);
    c.gridx = 0;
    c.gridy = 2;
    c.weightx = 1;
    c.weighty = 1;
    c.fill = GridBagConstraints.BOTH;
    groupPanel.add(testerPanel, c);

    panel.add(groupPanel, 1, 0);

    if (supportsItems) {
        // item shortcuts list
        itemShortcutsList = new JList<String>(items.toArray(new String[items.size()]));
        itemShortcutsList.setToolTipText(
                I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.item_shortcuts.tip"));
        itemShortcutsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        itemShortcutsList.addMouseListener(new MouseListener() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    String text = regexpTextField.getText();
                    int cursorPosition = regexpTextField.getCaretPosition();
                    int index = itemShortcutsList.getSelectedIndex();
                    if (index > -1 && index < itemShortcutsList.getModel().getSize()) {
                        String insertionString = itemShortcutsList.getModel().getElementAt(index).toString();
                        String newText = text.substring(0, cursorPosition) + insertionString
                                + (cursorPosition < text.length() ? text.substring(cursorPosition) : "");
                        regexpTextField.setText(newText);
                        regexpTextField.setCaretPosition(cursorPosition + insertionString.length());
                        regexpTextField.requestFocus();
                        fireRegularExpressionUpdated();
                    }
                }
            }

            @Override
            public void mouseEntered(MouseEvent e) {
            }

            @Override
            public void mouseExited(MouseEvent e) {
            }

            @Override
            public void mousePressed(MouseEvent e) {
            }

            @Override
            public void mouseReleased(MouseEvent e) {
            }
        });
        JScrollPane itemShortcutsPane = new JScrollPane(itemShortcutsList);
        itemShortcutsPane.setBorder(createTitledBorder(
                I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.item_shortcuts.border")));

        // matched items list
        matchedItemsListModel = new DefaultListModel<String>();
        JList<String> matchedItemsList = new JList<String>(matchedItemsListModel);
        matchedItemsList.setToolTipText(
                I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.matched_items.tip"));
        // add custom cell renderer to disallow selections
        matchedItemsList.setCellRenderer(new DefaultListCellRenderer() {

            private static final long serialVersionUID = -5795848004756768378L;

            @Override
            public Component getListCellRendererComponent(JList list, Object value, int index,
                    boolean isSelected, boolean cellHasFocus) {
                return super.getListCellRendererComponent(list, value, index, false, false);
            }
        });
        JScrollPane matchedItemsPanel = new JScrollPane(matchedItemsList);
        matchedItemsPanel.setBorder(createTitledBorder(
                I18N.getMessage(I18N.getGUIBundle(), "gui.dialog.parameter.regexp.matched_items.border")));

        // item panel on right side of dialog
        JPanel itemPanel = new JPanel(createGridLayout(1, 2));
        itemPanel.add(itemShortcutsPane, 0, 0);
        itemPanel.add(matchedItemsPanel, 0, 1);

        panel.add(itemPanel, 0, 1);
    }

    okButton = makeOkButton("regexp_property_dialog_apply");
    fireRegularExpressionUpdated();

    layoutDefault(panel, supportsItems ? NORMAL : NARROW, okButton, makeCancelButton());
}

From source file:de.tudarmstadt.ukp.dkpro.core.mstparser.MstParserTest.java

private JCas runTest(String aLanguage, String aVariant, String aText, Object... aExtraParams) throws Exception {
    AssumeResource.assumeResource(MstParser.class, "parser", aLanguage, aVariant);

    AggregateBuilder aggregate = new AggregateBuilder();

    aggregate.add(createEngineDescription(HunPosTagger.class));
    Object[] params = new Object[] { MstParser.PARAM_VARIANT, aVariant, MstParser.PARAM_PRINT_TAGSET, true };
    params = ArrayUtils.addAll(params, aExtraParams);
    aggregate.add(createEngineDescription(MstParser.class, params));

    return TestRunner.runTest(aggregate.createAggregateDescription(), aLanguage, aText);
}

From source file:marytts.unitselection.analysis.Phone.java

/**
 * Recover the F0 values from each Datagram in this phone's left and right units
 * //from  w  w w .j a  v  a  2s  .co  m
 * @return the F0 values for each Datagram in this phone, or null if either the left or the right unit contain a Datagram with
 *         zero duration
 */
public double[] getUnitFrameF0s() {
    double[] leftUnitFrameF0s = getLeftUnitFrameF0s();
    double[] rightUnitFrameF0s = getRightUnitFrameF0s();
    double[] unitFrameF0s = ArrayUtils.addAll(leftUnitFrameF0s, rightUnitFrameF0s);
    return unitFrameF0s;
}

From source file:com.ibm.jaggr.core.impl.transport.RequestedModuleNamesTest.java

@Test
public void testDecodeModuleIds() throws Exception {
    final String[] idList = new String[0x10005];
    idList[1] = "module1";
    idList[2] = "module2";
    idList[3] = "foo";
    idList[4] = "bar";
    idList[5] = "plugin";
    idList[0x10003] = "bigId";

    int ids[] = new int[] {
            // specifies the following {,,,"module1",,"module2","plugin!foo",,,"bar"}
            // first segment
            3, // start at third slot in module list
            1, // one module id to follow
            // start of module id
            1, // "module1"
            // new segment
            5, // fifth slot in module list
            2, // two module ids to follow
            2, // module2
            // second module id in segment specifies "plugin!foo"
            0, 5, // "plugin"
            3, // "foo"
            // third segment
            10, // slot 10 in modulelist
            1, // one module id to follow
            4 // "bar"
    };//from ww  w.  j a  v a2 s .  c  om

    byte hash[] = new byte[] { 1, 2, 3 };

    // test with 16-bit encoding
    byte[] bytes = new byte[ids.length * 2];
    for (int i = 0; i < ids.length; i++) {
        bytes[i * 2] = (byte) (ids[i] >> 8);
        bytes[i * 2 + 1] = (byte) (ids[i] & 0xFF);
    }
    String encoded = Base64
            .encodeBase64URLSafeString(ArrayUtils.addAll(ArrayUtils.addAll(hash, new byte[] { 0 }), bytes));
    System.out.println(encoded);
    String resultArray[] = new String[11];
    HttpServletRequest mockRequest = TestUtils.createMockRequest(null);
    EasyMock.replay(mockRequest);
    RequestedModuleNames requestedModules = new RequestedModuleNames(mockRequest, Arrays.asList(idList), hash);
    requestedModules.decodeModuleIds(encoded, resultArray);
    Assert.assertArrayEquals(new String[] { null, null, null, "module1", null, "module2", "plugin!foo", null,
            null, null, "bar" }, resultArray);

    // test again with 32-bit encoding
    ids = ArrayUtils.addAll(ids, new int[] { 12, 1, 0x10003 }); // slot 12, 1 module, "bigId"
    bytes = new byte[ids.length * 4];
    for (int i = 0; i < ids.length; i++) {
        bytes[i * 4] = (byte) (ids[i] >> 24);
        bytes[i * 4 + 1] = (byte) ((ids[i] >> 16) & 0xFF);
        bytes[i * 4 + 2] = (byte) ((ids[i] >> 8) & 0xFF);
        bytes[i * 4 + 3] = (byte) (ids[i] & 0xFF);
    }
    encoded = Base64
            .encodeBase64URLSafeString(ArrayUtils.addAll(ArrayUtils.addAll(hash, new byte[] { 1 }), bytes));
    System.out.println(encoded);
    resultArray = new String[13];
    requestedModules.decodeModuleIds(encoded, resultArray);
    Assert.assertArrayEquals(new String[] { null, null, null, "module1", null, "module2", "plugin!foo", null,
            null, null, "bar", null, "bigId" }, resultArray);

    // Make sure exception is thrown if hash is not correct
    try {
        encoded = Base64.encodeBase64URLSafeString(ArrayUtils.addAll(new byte[] { 3, 2, 1 }, bytes));
        requestedModules.decodeModuleIds(encoded, new String[11]);
        fail("Expected exception");
    } catch (BadRequestException ex) {

    }
}

From source file:com.rapidminer.operator.preprocessing.filter.NominalToNumeric.java

@Override
public OperatorVersion[] getIncompatibleVersionChanges() {
    return (OperatorVersion[]) ArrayUtils.addAll(super.getIncompatibleVersionChanges(),
            new OperatorVersion[] { VERSION_5_2_8, VERSION_MAY_WRITE_INTO_DATA });
}

From source file:be.fedict.eid.applet.service.signer.facets.XAdESXLSignatureFacet.java

public static byte[] getC14nValue(List<Node> nodeList, String c14nAlgoId) {
    byte[] c14nValue = null;
    try {//from   w  w  w  .j  a  v  a  2 s.  co  m
        for (Node node : nodeList) {
            /*
             * Re-initialize the c14n else the namespaces will get cached
             * and will be missing from the c14n resulting nodes.
             */
            Canonicalizer c14n;
            try {
                c14n = Canonicalizer.getInstance(c14nAlgoId);
            } catch (InvalidCanonicalizerException e) {
                throw new RuntimeException("c14n algo error: " + e.getMessage(), e);
            }
            c14nValue = ArrayUtils.addAll(c14nValue, c14n.canonicalizeSubtree(node));
        }
    } catch (CanonicalizationException e) {
        throw new RuntimeException("c14n error: " + e.getMessage(), e);
    }
    return c14nValue;
}