Example usage for java.util ArrayList toArray

List of usage examples for java.util ArrayList toArray

Introduction

In this page you can find the example usage for java.util ArrayList toArray.

Prototype

@SuppressWarnings("unchecked")
public <T> T[] toArray(T[] a) 

Source Link

Document

Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array.

Usage

From source file:configuration.Cluster.java

public static boolean sendFilesOnCluster(workflow_properties properties) {
    if (isP2RsaHere()) {
        Enumeration<Object> e = properties.keys();
        boolean b = true;
        while (e.hasMoreElements() && b == true) {
            String k = (String) e.nextElement();
            if (k.contains("ClusterLocalInput_")) {
                String file = properties.get(k);
                String dir = Util.getParentOfFile(Util.getCanonicalPath(file));
                ArrayList<String> listFiles = getListOfFilesinDirectory(dir);
                if (listFiles.size() > 0) {
                    String clusterDir = properties.get("ClusterDirPath");
                    String[] tabTmp = listFiles.toArray(new String[listFiles.size()]);
                    String i = getInputsDir4ClusterFile(k) + "/";
                    boolean b2 = runUploadDir(properties, tabTmp, clusterDir + i);
                    if (!b2)
                        return false;
                } else {
                    return false;
                }//  w w  w  .ja  v a 2 s . co  m
            }
        }
        return true;
    }
    return false;
}

From source file:net.shibboleth.idp.shell.IdpCommands.java

/**
 * Run the AACLI.//from   w  w  w  .  ja  v a  2  s.  c  o m
 * 
 * @param configDir the configuration directory
 * @return null
 */
@CliCommand(value = "aacli", help = "aacli")
public String aacli(
        @CliOption(key = "configDir", help = "Path to the configuration directory", unspecifiedDefaultValue = "../idp-attribute-cli/src/main/resources/conf") String configDir) {

    log.info("configDir '{}'", configDir);

    ArrayList<String> list = new ArrayList<String>();

    list.add("--configDir");
    list.add(configDir);

    String[] args = list.toArray(new String[] {});

    Main.main(args);

    return null;
}

From source file:net.sf.keystore_explorer.crypto.x509.X509CertUtil.java

private static X509Certificate[] loadCertificatesPkiPath(InputStream is) throws CryptoException {
    try {// www. java 2 s  .  co  m
        CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());
        CertPath certPath = cf.generateCertPath(is, PKI_PATH_ENCODING);

        List<? extends Certificate> certs = certPath.getCertificates();

        ArrayList<X509Certificate> loadedCerts = new ArrayList<X509Certificate>();

        for (Iterator<? extends Certificate> itr = certs.iterator(); itr.hasNext();) {
            X509Certificate cert = (X509Certificate) itr.next();

            if (cert != null) {
                loadedCerts.add(cert);
            }
        }

        return loadedCerts.toArray(new X509Certificate[loadedCerts.size()]);
    } catch (CertificateException e) {
        throw new CryptoException(res.getString("NoLoadPkiPath.exception.message"), e);
    } catch (NoSuchProviderException e) {
        throw new CryptoException(res.getString("NoLoadPkiPath.exception.message"), e);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:net.larry1123.elec.util.config.fieldhanders.strings.StringArrayListFieldHandler.java

/**
 * {@inheritDoc}//from   w ww. j  a v a  2s  . c  om
 */
@Override
public void setToFile(ArrayList<String> value) {
    if (CollectionUtils.isNotEmpty(value)) {
        getPropertiesFile().setStringArray(getPropertyKey(), value.toArray(new String[value.size()]),
                getSpacer());
    }
}

From source file:gedi.util.FileUtils.java

public static String[] find(String path, String glob, boolean stripPath) throws IOException {
    if (!path.endsWith("/"))
        path = path + "/";
    String cpath = path;//from   www .  j a v a  2 s  . co m
    ArrayList<String> re = new ArrayList<String>();
    PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + path + glob);
    Files.find(Paths.get(path), 9999, (p, per) -> {
        return matcher.matches(p);
    }, FileVisitOption.FOLLOW_LINKS).forEach(f -> {
        String file = f.toString();
        if (stripPath && file.startsWith(cpath))
            file = file.substring(cpath.length());
        re.add(file);
    });
    return re.toArray(new String[0]);
}

From source file:jat.examples.ephemeris.DE405PropagatePlot.java

double[][] getXYforPlot(ArrayList<Double> xsol, ArrayList<Double> ysol) {
    int arraySize = xsol.size();
    double[] xsolArray = ArrayUtils.toPrimitive(xsol.toArray(new Double[arraySize]));
    double[] ysolArray = ArrayUtils.toPrimitive(ysol.toArray(new Double[arraySize]));
    double[][] XY = new double[arraySize][2];
    for (int i = 0; i < arraySize; i++) {
        XY[i][0] = xsolArray[i];/*from  w w w  .  ja va 2 s  .c o  m*/
        XY[i][1] = ysolArray[i];
    }

    return XY;
}

From source file:de.fau.amos4.service.TranslatorServiceImpl.java

@Override
public String[] translate(String... messages) {
    ArrayList<String> translated = new ArrayList<>();

    for (String s : messages) {
        translated.add(translate(s));/*from w  w  w  . j av a 2s . c o m*/
    }

    return translated.toArray(new String[translated.size()]);
}

From source file:com.eviware.soapui.support.uri.HttpParser.java

public static Header[] parseHeaders(InputStream is, String charset) throws IOException, HttpException {
    ArrayList<Header> headers = new ArrayList<Header>();
    String name = null;/*from w w w  .  j  a v  a2s. c  o m*/
    StringBuffer value = null;
    for (;;) {
        String line = HttpParser.readLine(is, charset);
        if ((line == null) || (line.trim().length() < 1)) {
            break;
        }

        if ((line.charAt(0) == ' ') || (line.charAt(0) == '\t')) {
            if (value != null) {
                value.append(' ');
                value.append(line.trim());
            }
        } else {
            if (name != null) {
                headers.add(new BasicHeader(name, value.toString()));
            }

            int colon = line.indexOf(":");
            if (colon < 0) {
                throw new ProtocolException("Unable to parse header: " + line);
            }
            name = line.substring(0, colon).trim();
            value = new StringBuffer(line.substring(colon + 1).trim());
        }

    }

    if (name != null) {
        headers.add(new BasicHeader(name, value.toString()));
    }

    return (Header[]) headers.toArray(new Header[headers.size()]);
}

From source file:edu.umn.cs.spatialHadoop.operations.Sampler.java

private static <T extends TextSerializable> int sampleLocalByCount(Path[] files, ResultCollector<T> output,
        OperationsParams params) throws IOException {

    ArrayList<Path> data_files = new ArrayList<Path>();
    for (Path file : files) {
        FileSystem fs = file.getFileSystem(params);
        if (fs.getFileStatus(file).isDir()) {
            // Directory, process all data files in this directory (visible files)
            FileStatus[] fileStatus = fs.listStatus(file, hiddenFileFilter);
            for (FileStatus f : fileStatus) {
                data_files.add(f.getPath());
            }//  ww  w  .  j  a v  a2s  .  c o  m
        } else {
            // File, process this file
            data_files.add(file);
        }
    }

    files = data_files.toArray(new Path[data_files.size()]);

    TextSerializable inObj1, outObj1;
    inObj1 = OperationsParams.getTextSerializable(params, "shape", new Text2());
    outObj1 = OperationsParams.getTextSerializable(params, "outshape", new Text2());

    // Make the objects final to be able to use in the anonymous inner class
    final TextSerializable inObj = inObj1;
    final T outObj = (T) outObj1;

    ResultCollector<TextSerializable> converter = createConverter(output, inObj, outObj);
    long[] files_start_offset = new long[files.length + 1]; // Prefix sum of files sizes
    long total_length = 0;
    for (int i_file = 0; i_file < files.length; i_file++) {
        FileSystem fs = files[i_file].getFileSystem(params);
        files_start_offset[i_file] = total_length;
        total_length += fs.getFileStatus(files[i_file]).getLen();
    }
    files_start_offset[files.length] = total_length;

    // Generate offsets to read from and make sure they are ordered to minimize
    // seeks between different HDFS blocks
    Random random = new Random(params.getLong("seed", System.currentTimeMillis()));
    long[] offsets = new long[params.getInt("count", 0)];
    for (int i = 0; i < offsets.length; i++) {
        if (total_length == 0)
            offsets[i] = 0;
        else
            offsets[i] = Math.abs(random.nextLong()) % total_length;
    }
    Arrays.sort(offsets);

    int record_i = 0; // Number of records read so far
    int records_returned = 0;

    int file_i = 0; // Index of the current file being sampled
    while (record_i < offsets.length) {
        // Skip to the file that contains the next sample
        while (offsets[record_i] > files_start_offset[file_i + 1])
            file_i++;

        long current_file_size = files_start_offset[file_i + 1] - files_start_offset[file_i];
        FileSystem fs = files[file_i].getFileSystem(params);
        ShapeLineRecordReader reader = new ShapeLineRecordReader(fs.getConf(),
                new FileSplit(files[file_i], 0, current_file_size, new String[] {}));
        Rectangle key = reader.createKey();
        Text line = reader.createValue();
        long pos = files_start_offset[file_i];

        while (record_i < offsets.length && offsets[record_i] <= files_start_offset[file_i + 1]
                && reader.next(key, line)) {
            pos += line.getLength();
            if (pos > offsets[record_i]) {
                // Passed the offset of record_i
                // Report this element to output
                if (converter != null) {
                    inObj.fromText(line);
                    converter.collect(inObj);
                }
                record_i++;
                records_returned++;
            }
        }
        reader.close();

        // Skip any remaining records that were supposed to be read from this file
        // This case might happen if a generated random position was in the middle
        // of the last line.
        while (record_i < offsets.length && offsets[record_i] <= files_start_offset[file_i + 1])
            record_i++;
    }
    return records_returned;
}

From source file:net.sf.keystore_explorer.crypto.x509.X509CertUtil.java

public static X509Certificate[] loadCertificates(InputStream is, String keyStoreType) throws CryptoException {
    byte[] certsBytes = null;
    CertificateFactory cf = null;
    try {//from  w w w.ja  v  a 2  s.  c o  m
        certsBytes = ReadUtil.readFully(is);

        // fix common input certificate problems by converting PEM/B64 to DER
        certsBytes = fixCommonInputCertProblems(certsBytes);

        is = new ByteArrayInputStream(certsBytes);

        if (keyStoreType.equals("HTKS")) {
            cf = CertificateFactory.getInstance(X509_CERT_TYPE, "GNU-PKI");
        } else {
            cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());
        }
        Collection<? extends Certificate> certs = cf.generateCertificates(is);
        ArrayList<X509Certificate> loadedCerts = new ArrayList<X509Certificate>();
        for (Iterator<? extends Certificate> itr = certs.iterator(); itr.hasNext();) {
            X509Certificate cert = (X509Certificate) itr.next();

            if (cert != null) {
                loadedCerts.add(cert);
            }
        }

        return loadedCerts.toArray(new X509Certificate[loadedCerts.size()]);
    } catch (IOException ex) {
        throw new CryptoException(res.getString("NoLoadCertificate.exception.message"), ex);
    } catch (NoSuchProviderException e) {
        throw new CryptoException(res.getString("NoLoadCertificate.exception.message"), e);
    } catch (CertificateException ex) {
        // Failed to load certificates, may be pki path encoded - try loading as that
        try {
            return loadCertificatesPkiPath(new ByteArrayInputStream(certsBytes));
        } catch (CryptoException ex2) {
            throw new CryptoException(res.getString("NoLoadCertificate.exception.message"), ex);
        }
    } finally {
        IOUtils.closeQuietly(is);
    }
}