Example usage for java.util Vector copyInto

List of usage examples for java.util Vector copyInto

Introduction

In this page you can find the example usage for java.util Vector copyInto.

Prototype

public synchronized void copyInto(Object[] anArray) 

Source Link

Document

Copies the components of this vector into the specified array.

Usage

From source file:com.openmeap.json.JSONObjectBuilder.java

private Object[] toTypedArray(Vector list) {
    if (list.isEmpty()) {
        return null;
    }/* ww w  .  j a  v  a2s  .  co m*/
    Object first = list.elementAt(0);
    Object[] ret = null;
    if (first instanceof String) {
        ret = new String[list.size()];
    } else if (first instanceof Double) {
        ret = new Double[list.size()];
    } else if (first instanceof Integer) {
        ret = new Integer[list.size()];
    } else if (first instanceof Long) {
        ret = new Long[list.size()];
    } else if (first instanceof Boolean) {
        ret = new Boolean[list.size()];
    }
    list.copyInto(ret);
    return (Object[]) ret;
}

From source file:netscape.security.pkcs.PKCS7.java

/**
 * Returns all signerInfos which self-verify.
 *
 * @param bytes the DER encoded content information.
 *
 * @exception NoSuchAlgorithmException on unrecognized algorithms.
 * @exception SignatureException on signature handling errors.
 *//*from ww  w. ja  va2 s.co m*/
public SignerInfo[] verify(byte[] bytes) throws NoSuchAlgorithmException, SignatureException {

    Vector<SignerInfo> intResult = new Vector<SignerInfo>();
    for (int i = 0; i < signerInfos.length; i++) {

        SignerInfo signerInfo = verify(signerInfos[i], bytes);
        if (signerInfo != null) {
            intResult.addElement(signerInfo);
        }
    }
    if (intResult.size() != 0) {

        SignerInfo[] result = new SignerInfo[intResult.size()];
        intResult.copyInto(result);
        return result;
    }
    return null;
}

From source file:JavaViewer.java

/**
 * Event.detail line start offset (input) Event.text line text (input)
 * LineStyleEvent.styles Enumeration of StyleRanges, need to be in order.
 * (output) LineStyleEvent.background line background color (output)
 *//*from ww  w .  j a  v a  2  s  .  c  o m*/
public void lineGetStyle(LineStyleEvent event) {
    Vector styles = new Vector();
    int token;
    StyleRange lastStyle;
    // If the line is part of a block comment, create one style for the
    // entire line.
    if (inBlockComment(event.lineOffset, event.lineOffset + event.lineText.length())) {
        styles.addElement(new StyleRange(event.lineOffset, event.lineText.length(), getColor(COMMENT), null));
        event.styles = new StyleRange[styles.size()];
        styles.copyInto(event.styles);
        return;
    }
    Color defaultFgColor = ((Control) event.widget).getForeground();
    scanner.setRange(event.lineText);
    token = scanner.nextToken();
    while (token != EOF) {
        if (token == OTHER) {
            // do nothing for non-colored tokens
        } else if (token != WHITE) {
            Color color = getColor(token);
            // Only create a style if the token color is different than the
            // widget's default foreground color and the token's style is
            // not
            // bold. Keywords are bolded.
            if ((!color.equals(defaultFgColor)) || (token == KEY)) {
                StyleRange style = new StyleRange(scanner.getStartOffset() + event.lineOffset,
                        scanner.getLength(), color, null);
                if (token == KEY) {
                    style.fontStyle = SWT.BOLD;
                }
                if (styles.isEmpty()) {
                    styles.addElement(style);
                } else {
                    // Merge similar styles. Doing so will improve
                    // performance.
                    lastStyle = (StyleRange) styles.lastElement();
                    if (lastStyle.similarTo(style) && (lastStyle.start + lastStyle.length == style.start)) {
                        lastStyle.length += style.length;
                    } else {
                        styles.addElement(style);
                    }
                }
            }
        } else if ((!styles.isEmpty())
                && ((lastStyle = (StyleRange) styles.lastElement()).fontStyle == SWT.BOLD)) {
            int start = scanner.getStartOffset() + event.lineOffset;
            lastStyle = (StyleRange) styles.lastElement();
            // A font style of SWT.BOLD implies that the last style
            // represents a java keyword.
            if (lastStyle.start + lastStyle.length == start) {
                // Have the white space take on the style before it to
                // minimize the number of style ranges created and the
                // number of font style changes during rendering.
                lastStyle.length += scanner.getLength();
            }
        }
        token = scanner.nextToken();
    }
    event.styles = new StyleRange[styles.size()];
    styles.copyInto(event.styles);
}

From source file:org.springframework.util.exec.Execute.java

/**
 * Patch the current environment with the new values from the user.
 *
 * @return the patched environment//from ww w. ja  v  a 2 s. c  o  m
 */
private String[] patchEnvironment() {
    @SuppressWarnings("unchecked")
    Vector<String> osEnv = (Vector<String>) getProcEnvironment().clone();
    for (int i = 0; i < env.length; i++) {
        int pos = env[i].indexOf('=');
        // Get key including "="
        String key = env[i].substring(0, pos + 1);
        int size = osEnv.size();
        for (int j = 0; j < size; j++) {
            if ((osEnv.elementAt(j)).startsWith(key)) {
                osEnv.removeElementAt(j);
                break;
            }
        }
        osEnv.addElement(env[i]);
    }
    String[] result = new String[osEnv.size()];
    osEnv.copyInto(result);
    return result;
}

From source file:org.hyperic.util.exec.Execute.java

/**
 * Patch the current environment with the new values from the user.
 * @return the patched environment//from   w  w w  .ja v a  2 s .c om
 */
private String[] patchEnvironment() {
    Vector osEnv = (Vector) getProcEnvironment().clone();
    for (int i = 0; i < env.length; i++) {
        int pos = env[i].indexOf('=');
        // Get key including "="
        String key = env[i].substring(0, pos + 1);
        int size = osEnv.size();
        for (int j = 0; j < size; j++) {
            if (((String) osEnv.elementAt(j)).startsWith(key)) {
                osEnv.removeElementAt(j);
                break;
            }
        }
        osEnv.addElement(env[i]);
    }
    String[] result = new String[osEnv.size()];
    osEnv.copyInto(result);
    return result;
}

From source file:org.pentaho.di.job.entries.sftp.SFTPClient.java

public String[] dir() throws KettleJobException {
    String[] fileList = null;/*www .ja  v a  2s.  co m*/

    try {
        java.util.Vector<?> v = c.ls(".");
        java.util.Vector<String> o = new java.util.Vector<String>();
        if (v != null) {
            for (int i = 0; i < v.size(); i++) {
                Object obj = v.elementAt(i);
                if (obj != null && obj instanceof com.jcraft.jsch.ChannelSftp.LsEntry) {
                    LsEntry lse = (com.jcraft.jsch.ChannelSftp.LsEntry) obj;
                    if (!lse.getAttrs().isDir()) {
                        o.add(lse.getFilename());
                    }
                }
            }
        }
        if (o.size() > 0) {
            fileList = new String[o.size()];
            o.copyInto(fileList);
        }
    } catch (SftpException e) {
        throw new KettleJobException(e);
    }

    return fileList;
}

From source file:org.pentaho.di.trans.steps.sftpscan.client.SFTPClient.java

public String[] dir() throws KettleJobException {
    String[] fileList = null;//from w  w w  .  j  a  v  a2  s .  c  o  m

    try {
        java.util.Vector<?> v = c.ls(".");
        java.util.Vector<String> o = new java.util.Vector<String>();
        if (v != null) {
            for (int i = 0; i < v.size(); i++) {
                Object obj = v.elementAt(i);
                if (obj != null && obj instanceof LsEntry) {
                    LsEntry lse = (LsEntry) obj;
                    if (!lse.getAttrs().isDir()) {
                        o.add(lse.getFilename());
                    }
                }
            }
        }
        if (o.size() > 0) {
            fileList = new String[o.size()];
            o.copyInto(fileList);
        }
    } catch (SftpException e) {
        throw new KettleJobException(e);
    }

    return fileList;
}

From source file:org.gudy.azureus2.pluginsimpl.local.utils.xml.simpleparser.SimpleXMLParserDocumentImpl.java

protected SimpleXMLParserDocumentNodeImpl[] parseNode(Node node, boolean skip_this_node) {
    int type = node.getNodeType();

    if ((type == Node.ELEMENT_NODE || type == Node.PROCESSING_INSTRUCTION_NODE) && !skip_this_node) {

        return (new SimpleXMLParserDocumentNodeImpl[] { new SimpleXMLParserDocumentNodeImpl(this, node) });
    }//from   ww  w  .  j  a v a  2  s  .  c  o  m

    Vector v = new Vector();

    for (Node child = node.getFirstChild(); child != null; child = child.getNextSibling()) {

        SimpleXMLParserDocumentNodeImpl[] kids = parseNode(child, false);

        for (int i = 0; i < kids.length; i++) {

            v.addElement(kids[i]);
        }
    }

    SimpleXMLParserDocumentNodeImpl[] res = new SimpleXMLParserDocumentNodeImpl[v.size()];

    v.copyInto(res);

    return (res);
}

From source file:com.clustercontrol.jobmanagement.util.SendApprovalMail.java

/**
 * ?????<code> InternetAddress </code>???
 *
 * @param addressList//from w w w  . j a va 2 s.c o  m
 *            ???
 * @return <code> InternetAddress </code>??
 */
private InternetAddress[] getAddress(String[] addressList) {
    InternetAddress toAddress[] = null;
    Vector<InternetAddress> list = new Vector<InternetAddress>();
    if (addressList != null) {
        for (String address : addressList) {
            try {
                list.add(new InternetAddress(address));
            } catch (AddressException e) {
                m_log.info("getAddress() : " + e.getClass().getSimpleName() + ", " + address + ", "
                        + e.getMessage());
            }
        }
        if (list.size() > 0) {
            toAddress = new InternetAddress[list.size()];
            list.copyInto(toAddress);
        }
    }
    return toAddress;
}

From source file:com.thoughtworks.cruise.util.command.CommandLine.java

public static String[] translateCommandLine(String toProcess) throws CommandLineException {
    if (toProcess == null || toProcess.length() == 0) {
        return new String[0];
    }//from ww  w . j  a  v a2 s.c  om

    // parse with a simple finite state machine

    final int normal = 0;
    final int inQuote = 1;
    final int inDoubleQuote = 2;
    int state = normal;
    StringTokenizer tok = new StringTokenizer(toProcess, "\"\' ", true);
    Vector v = new Vector();
    StringBuffer current = new StringBuffer();

    while (tok.hasMoreTokens()) {
        String nextTok = tok.nextToken();
        switch (state) {
        case inQuote:
            if ("\'".equals(nextTok)) {
                state = normal;
            } else {
                current.append(nextTok);
            }
            break;
        case inDoubleQuote:
            if ("\"".equals(nextTok)) {
                state = normal;
            } else {
                current.append(nextTok);
            }
            break;
        default:
            if ("\'".equals(nextTok)) {
                state = inQuote;
            } else if ("\"".equals(nextTok)) {
                state = inDoubleQuote;
            } else if (" ".equals(nextTok)) {
                if (current.length() != 0) {
                    v.addElement(current.toString());
                    current.setLength(0);
                }
            } else {
                current.append(nextTok);
            }
            break;
        }
    }

    if (current.length() != 0) {
        v.addElement(current.toString());
    }

    if (state == inQuote || state == inDoubleQuote) {
        throw new CommandLineException("unbalanced quotes in " + toProcess);
    }

    String[] args = new String[v.size()];
    v.copyInto(args);
    return args;
}