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:org.apache.cactus.WebResponse.java

/**
 * @return the cookies returned by the server
 *//*from w  w w  .  j ava  2s.c om*/
public Cookie[] getCookies() {
    Cookie[] returnCookies = null;

    // There can be several headers named "Set-Cookie", so loop through
    // all the headers, looking for cookies
    String headerName = this.connection.getHeaderFieldKey(0);
    String headerValue = this.connection.getHeaderField(0);

    Vector cookieVector = new Vector();
    CookieSpec cookieSpec = CookiePolicy.getDefaultSpec();

    for (int i = 1; (headerName != null) || (headerValue != null); i++) {
        LOGGER.debug("Header name  = [" + headerName + "]");
        LOGGER.debug("Header value = [" + headerValue + "]");

        if ((headerName != null) && (headerName.toLowerCase().equals("set-cookie")
                || headerName.toLowerCase().equals("set-cookie2"))) {
            // Parse the cookie definition
            org.apache.commons.httpclient.Cookie[] cookies;
            try {
                cookies = cookieSpec.parse(
                        CookieUtil.getCookieDomain(getWebRequest(), getConnection().getURL().getHost()),
                        CookieUtil.getCookiePort(getWebRequest(), getConnection().getURL().getPort()),
                        CookieUtil.getCookiePath(getWebRequest(), getConnection().getURL().getFile()), false,
                        new Header(headerName, headerValue));
            } catch (HttpException e) {
                throw new ChainedRuntimeException("Error parsing cookies", e);
            }

            // Transform the HttpClient cookies into Cactus cookies and
            // add them to the cookieVector vector
            for (int j = 0; j < cookies.length; j++) {
                Cookie cookie = new Cookie(cookies[j].getDomain(), cookies[j].getName(), cookies[j].getValue());

                cookie.setComment(cookies[j].getComment());
                cookie.setExpiryDate(cookies[j].getExpiryDate());
                cookie.setPath(cookies[j].getPath());
                cookie.setSecure(cookies[j].getSecure());

                cookieVector.addElement(cookie);
            }
        }

        headerName = this.connection.getHeaderFieldKey(i);
        headerValue = this.connection.getHeaderField(i);
    }

    returnCookies = new Cookie[cookieVector.size()];
    cookieVector.copyInto(returnCookies);

    return returnCookies;
}

From source file:org.apache.tomcat.util.net.jsse.JSSESocketFactory.java

protected String[] getEnabledCiphers(String requestedCiphers, String[] supportedCiphers) {

    String[] enabledCiphers = null;

    if (requestedCiphers != null) {
        Vector vec = null;
        String cipher = requestedCiphers;
        int index = requestedCiphers.indexOf(',');
        if (index != -1) {
            int fromIndex = 0;
            while (index != -1) {
                cipher = requestedCiphers.substring(fromIndex, index).trim();
                if (cipher.length() > 0) {
                    /*//www  . j av a 2 s  .co  m
                     * Check to see if the requested cipher is among the
                     * supported ciphers, i.e., may be enabled
                     */
                    for (int i = 0; supportedCiphers != null && i < supportedCiphers.length; i++) {
                        if (supportedCiphers[i].equals(cipher)) {
                            if (vec == null) {
                                vec = new Vector();
                            }
                            vec.addElement(cipher);
                            break;
                        }
                    }
                }
                fromIndex = index + 1;
                index = requestedCiphers.indexOf(',', fromIndex);
            } // while
            cipher = requestedCiphers.substring(fromIndex);
        }

        if (cipher != null) {
            cipher = cipher.trim();
            if (cipher.length() > 0) {
                /*
                 * Check to see if the requested cipher is among the
                 * supported ciphers, i.e., may be enabled
                 */
                for (int i = 0; supportedCiphers != null && i < supportedCiphers.length; i++) {
                    if (supportedCiphers[i].equals(cipher)) {
                        if (vec == null) {
                            vec = new Vector();
                        }
                        vec.addElement(cipher);
                        break;
                    }
                }
            }
        }

        if (vec != null) {
            enabledCiphers = new String[vec.size()];
            vec.copyInto(enabledCiphers);
        }
    }

    return enabledCiphers;
}

From source file:com.toughra.mlearnplayer.MLearnPlayerMidlet.java

/**
 * Load the table of contents/*ww w  .j a v  a2  s  . co m*/
 * 
 * @param hide - Do not show the table of contents form itself immediately.  Do not set curFrm
 * 
 */
public void loadTOC(boolean hide) {
    myTOC.readList(currentPackageURI + "/exetoc.xml");

    //now check for feedback sounds
    try {
        FileConnection con = (FileConnection) Connector.open(currentPackageURI);
        String prefixes[] = new String[] { "exesfx_good", "exesfx_wrong" };
        String extsn = ".mp3";

        for (int i = 0; i < prefixes.length; i++) {
            int c = 0;
            Vector foundFiles = new Vector();
            try {
                boolean moreFiles = true;
                do {
                    try {
                        String filename = prefixes[i] + c + extsn;
                        Enumeration e = con.list(filename, true);
                        if (e.hasMoreElements()) {
                            //means this file exists
                            foundFiles.addElement(filename);
                            c++;
                        } else {
                            moreFiles = false;
                        }
                    } catch (Exception e) {
                        moreFiles = false;
                    }
                } while (moreFiles);
            } catch (Exception e) {
                System.out.println("Exception occured looking for audio files");
            } finally {
                if (foundFiles.size() > 0) {
                    if (prefixes[i].equals("exesfx_good")) {
                        posFbURIs = new String[foundFiles.size()];
                        foundFiles.copyInto(posFbURIs);
                    } else {
                        negFbURIs = new String[foundFiles.size()];
                        foundFiles.copyInto(negFbURIs);
                    }
                }
            }
        }
        con.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

    TOCForm = myTOC.getForm();
    myTOC.getList().addActionListener(this);
    if (!hide) {
        curFrm = TOCForm;
    }
}

From source file:com.github.maven_nar.cpptasks.CCTask.java

protected TargetInfo getLinkTarget(final LinkerConfiguration linkerConfig, final Vector<File> objectFiles,
        final Vector<File> sysObjectFiles, final Map<String, TargetInfo> compileTargets,
        final VersionInfo versionInfo) {
    ///*from ww  w  . j a  v a2 s  . c o  m*/
    // walk the compile phase targets and
    // add those sources that have already been
    // assigned to the linker or
    // our output files the linker knows how to consume
    // files the linker knows how to consume
    //
    for (final TargetInfo compileTarget : compileTargets.values()) {
        //
        // output of compile tasks
        //
        final int bid = linkerConfig.bid(compileTarget.getOutput().toString());
        if (bid > 0) {
            objectFiles.addElement(compileTarget.getOutput());
        }
    }
    final File[] objectFileArray = new File[objectFiles.size()];
    objectFiles.copyInto(objectFileArray);
    final File[] sysObjectFileArray = new File[sysObjectFiles.size()];
    sysObjectFiles.copyInto(sysObjectFileArray);
    final String baseName = this._outfile.getName();
    final String[] fullNames = linkerConfig.getOutputFileNames(baseName, versionInfo);
    final File outputFile = new File(this._outfile.getParent(), fullNames[0]);
    return new TargetInfo(linkerConfig, objectFileArray, sysObjectFileArray, outputFile,
            linkerConfig.getRebuild());
}

From source file:org.jsslutils.extra.apachetomcat5.JSSLutilsJSSESocketFactory.java

protected String[] getEnabledCiphers(String requestedCiphers, String[] supportedCiphers) {

    String[] enabledCiphers = null;

    if (requestedCiphers != null) {
        Vector<String> vec = null;
        String cipher = requestedCiphers;
        int index = requestedCiphers.indexOf(',');
        if (index != -1) {
            int fromIndex = 0;
            while (index != -1) {
                cipher = requestedCiphers.substring(fromIndex, index).trim();
                if (cipher.length() > 0) {
                    /*// w  w  w .  j  av a 2 s .  c  om
                     * Check to see if the requested cipher is among the
                     * supported ciphers, i.e., may be enabled
                     */
                    for (int i = 0; supportedCiphers != null && i < supportedCiphers.length; i++) {
                        if (supportedCiphers[i].equals(cipher)) {
                            if (vec == null) {
                                vec = new Vector<String>();
                            }
                            vec.addElement(cipher);
                            break;
                        }
                    }
                }
                fromIndex = index + 1;
                index = requestedCiphers.indexOf(',', fromIndex);
            } // while
            cipher = requestedCiphers.substring(fromIndex);
        }

        if (cipher != null) {
            cipher = cipher.trim();
            if (cipher.length() > 0) {
                /*
                 * Check to see if the requested cipher is among the
                 * supported ciphers, i.e., may be enabled
                 */
                for (int i = 0; supportedCiphers != null && i < supportedCiphers.length; i++) {
                    if (supportedCiphers[i].equals(cipher)) {
                        if (vec == null) {
                            vec = new Vector<String>();
                        }
                        vec.addElement(cipher);
                        break;
                    }
                }
            }
        }

        if (vec != null) {
            enabledCiphers = new String[vec.size()];
            vec.copyInto(enabledCiphers);
        }
    } else {
        enabledCiphers = sslProxy.getDefaultCipherSuites();
    }

    return enabledCiphers;
}

From source file:org.glite.security.trustmanager.tomcat.TMSSLServerSocketFactory.java

/**
 * Determines the SSL cipher suites to be enabled.
 * /* ww  w.j  ava 2  s.  c o  m*/
 * @param requestedCiphers Comma-separated list of requested ciphers @param
 * @param supportedCiphers Array of supported ciphers
 * @return Array of SSL cipher suites to be enabled, or null if none of the requested ciphers are supported
 */
protected String[] getEnabledCiphers(String requestedCiphers, String[] supportedCiphers) {
    LOGGER.debug("TMSSLServerSocketFactory.getEnabledCiphers: enabling:" + requestedCiphers);

    String[] acceptedCiphers = null;

    if (requestedCiphers != null) {
        Vector vec = null;
        String cipher = requestedCiphers;
        int index = requestedCiphers.indexOf(',');

        if (index != -1) {
            int fromIndex = 0;

            while (index != -1) {
                cipher = requestedCiphers.substring(fromIndex, index).trim();

                if (cipher.length() > 0) {
                    /*
                     * Check to see if the requested cipher is among the
                     * supported ciphers, i.e., may be enabled
                     */
                    for (int i = 0; (supportedCiphers != null) && (i < supportedCiphers.length); i++) {
                        if (supportedCiphers[i].equals(cipher)) {
                            if (vec == null) {
                                vec = new Vector();
                            }

                            vec.addElement(cipher);

                            break;
                        }
                    }
                }

                fromIndex = index + 1;
                index = requestedCiphers.indexOf(',', fromIndex);
            } // while
            cipher = requestedCiphers.substring(fromIndex);
        }

        if (cipher != null) {
            cipher = cipher.trim();

            if (cipher.length() > 0) {
                /*
                 * Check to see if the requested cipher is among the
                 * supported ciphers, i.e., may be enabled
                 */
                for (int i = 0; (supportedCiphers != null) && (i < supportedCiphers.length); i++) {
                    if (supportedCiphers[i].equals(cipher)) {
                        if (vec == null) {
                            vec = new Vector();
                        }

                        vec.addElement(cipher);

                        break;
                    }
                }
            }
        }

        if (vec != null) {
            acceptedCiphers = new String[vec.size()];
            vec.copyInto(acceptedCiphers);
        }
    }

    return acceptedCiphers;
}

From source file:org.jsslutils.extra.apachetomcat5.JSSLutilsJSSESocketFactory.java

/**
 * Determines the SSL protocol variants to be enabled.
 * /*  ww w  .  jav a 2 s  . co  m*/
 * @param socket
 *            The socket to get supported list from.
 * @param requestedProtocols
 *            Comma-separated list of requested SSL protocol variants
 * 
 * @return Array of SSL protocol variants to be enabled, or null if none of
 *         the requested protocol variants are supported
 */
protected String[] getEnabledProtocols(SSLServerSocket socket, String requestedProtocols) {
    String[] supportedProtocols = socket.getSupportedProtocols();

    String[] enabledProtocols = null;

    if (requestedProtocols != null) {
        Vector<String> vec = null;
        String protocol = requestedProtocols;
        int index = requestedProtocols.indexOf(',');
        if (index != -1) {
            int fromIndex = 0;
            while (index != -1) {
                protocol = requestedProtocols.substring(fromIndex, index).trim();
                if (protocol.length() > 0) {
                    /*
                     * Check to see if the requested protocol is among the
                     * supported protocols, i.e., may be enabled
                     */
                    for (int i = 0; supportedProtocols != null && i < supportedProtocols.length; i++) {
                        if (supportedProtocols[i].equals(protocol)) {
                            if (vec == null) {
                                vec = new Vector<String>();
                            }
                            vec.addElement(protocol);
                            break;
                        }
                    }
                }
                fromIndex = index + 1;
                index = requestedProtocols.indexOf(',', fromIndex);
            } // while
            protocol = requestedProtocols.substring(fromIndex);
        }

        if (protocol != null) {
            protocol = protocol.trim();
            if (protocol.length() > 0) {
                /*
                 * Check to see if the requested protocol is among the
                 * supported protocols, i.e., may be enabled
                 */
                for (int i = 0; supportedProtocols != null && i < supportedProtocols.length; i++) {
                    if (supportedProtocols[i].equals(protocol)) {
                        if (vec == null) {
                            vec = new Vector<String>();
                        }
                        vec.addElement(protocol);
                        break;
                    }
                }
            }
        }

        if (vec != null) {
            enabledProtocols = new String[vec.size()];
            vec.copyInto(enabledProtocols);
        }
    }

    return enabledProtocols;
}

From source file:org.glite.security.trustmanager.tomcat.TMSSLServerSocketFactory.java

/**
 * DOCUMENT ME!// w  ww .  j  av  a  2s  . c o m
 *
 * @param socket DOCUMENT ME!
 * @param requestedProtocols DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
protected String[] getEnabledProtocols(SSLServerSocket socket, String requestedProtocols) {
    LOGGER.debug("TMSSLServerSocketFactory.getEnabledProtocols:");

    String[] supportedProtocols = socket.getSupportedProtocols();

    String[] enabledProtocols = null;

    if (requestedProtocols != null) {
        Vector vec = null;
        String protocol = requestedProtocols;
        int index = requestedProtocols.indexOf(',');

        if (index != -1) {
            int fromIndex = 0;

            while (index != -1) {
                protocol = requestedProtocols.substring(fromIndex, index).trim();

                if (protocol.length() > 0) {
                    /*
                     * Check to see if the requested protocol is among the
                     * supported protocols, i.e., may be enabled
                     */
                    for (int i = 0; (supportedProtocols != null) && (i < supportedProtocols.length); i++) {
                        if (supportedProtocols[i].equals(protocol)) {
                            if (vec == null) {
                                vec = new Vector();
                            }

                            vec.addElement(protocol);

                            break;
                        }
                    }
                }

                fromIndex = index + 1;
                index = requestedProtocols.indexOf(',', fromIndex);
            }
            // while

            protocol = requestedProtocols.substring(fromIndex);
        }

        if (protocol != null) {
            protocol = protocol.trim();

            if (protocol.length() > 0) {
                /*
                 * Check to see if the requested protocol is among the
                 * supported protocols, i.e., may be enabled
                 */
                for (int i = 0; (supportedProtocols != null) && (i < supportedProtocols.length); i++) {
                    if (supportedProtocols[i].equals(protocol)) {
                        if (vec == null) {
                            vec = new Vector();
                        }

                        vec.addElement(protocol);

                        break;
                    }
                }
            }
        }

        if (vec != null) {
            enabledProtocols = new String[vec.size()];
            vec.copyInto(enabledProtocols);
        }
    }

    return enabledProtocols;
}

From source file:com.netscape.cmsutil.crypto.CryptoUtil.java

/**
 * Retrieves all user certificates from all tokens.
 */// ww  w .  j  a  va 2s. co m
public static X509CertImpl[] getAllUserCerts() throws NotInitializedException, TokenException {
    Vector<X509CertImpl> certs = new Vector<X509CertImpl>();
    CryptoManager cm = CryptoManager.getInstance();
    @SuppressWarnings("unchecked")
    Enumeration<CryptoToken> enums = cm.getAllTokens();

    while (enums.hasMoreElements()) {
        CryptoToken token = enums.nextElement();

        CryptoStore store = token.getCryptoStore();
        org.mozilla.jss.crypto.X509Certificate list[] = store.getCertificates();

        for (int i = 0; i < list.length; i++) {
            try {
                @SuppressWarnings("unused")
                PrivateKey key = cm.findPrivKeyByCert(list[i]); // check for errors
                X509CertImpl impl = null;

                try {
                    impl = new X509CertImpl(list[i].getEncoded());
                } catch (CertificateException e) {
                    continue;
                }
                certs.addElement(impl);
            } catch (TokenException e) {
                continue;
            } catch (ObjectNotFoundException e) {
                continue;
            }
        }
    }
    if (certs.size() == 0) {
        return null;
    } else {
        X509CertImpl c[] = new X509CertImpl[certs.size()];

        certs.copyInto(c);
        return c;
    }
}

From source file:org.eredlab.g4.ccl.net.ftp.FTPClient.java

/***
 * Obtain a list of filenames in a directory (or just the name of a given
 * file, which is not particularly useful).  This information is obtained
 * through the NLST command.  If the given pathname is a directory and
 * contains no files,  a zero length array is returned only
 * if the FTP server returned a positive completion code, otherwise
 * null is returned (the FTP server returned a 550 error No files found.).
 * If the directory is not empty, an array of filenames in the directory is
 * returned. If the pathname corresponds
 * to a file, only that file will be listed.  The server may or may not
 * expand glob expressions./*from ww  w . j a  v  a 2 s .co m*/
 * <p>
 * @param pathname  The file or directory to list.
 * @return The list of filenames contained in the given path.  null if
 *     the list could not be obtained.  If there are no filenames in
 *     the directory, a zero-length array is returned.
 * @exception FTPConnectionClosedException
 *      If the FTP server prematurely closes the connection as a result
 *      of the client being idle or some other reason causing the server
 *      to send FTP reply code 421.  This exception may be caught either
 *      as an IOException or independently as itself.
 * @exception IOException  If an I/O error occurs while either sending a
 *      command to the server or receiving a reply from the server.
 ***/
public String[] listNames(String pathname) throws IOException {
    String line;
    Socket socket;
    BufferedReader reader;
    Vector results;

    if ((socket = _openDataConnection_(FTPCommand.NLST, pathname)) == null)
        return null;

    reader = new BufferedReader(new InputStreamReader(socket.getInputStream(), getControlEncoding()));

    results = new Vector();
    while ((line = reader.readLine()) != null)
        results.addElement(line);
    reader.close();
    socket.close();

    if (completePendingCommand()) {
        String[] result;
        result = new String[results.size()];
        results.copyInto(result);
        return result;
    }

    return null;
}