List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:RequestUtil.java
/** * Parse a cookie header into an array of cookies according to RFC 2109. * /*from w w w. ja va 2 s . com*/ * @param header * Value of an HTTP "Cookie" header */ public static Cookie[] parseCookieHeader(String header) { if ((header == null) || (header.length() < 1)) return (new Cookie[0]); ArrayList cookies = new ArrayList(); while (header.length() > 0) { int semicolon = header.indexOf(';'); if (semicolon < 0) semicolon = header.length(); if (semicolon == 0) break; String token = header.substring(0, semicolon); if (semicolon < header.length()) header = header.substring(semicolon + 1); else header = ""; try { int equals = token.indexOf('='); if (equals > 0) { String name = token.substring(0, equals).trim(); String value = token.substring(equals + 1).trim(); cookies.add(new Cookie(name, value)); } } catch (Throwable e) { ; } } return ((Cookie[]) cookies.toArray(new Cookie[cookies.size()])); }
From source file:com.github.lynxdb.server.core.repository.EntryRepo.java
public void insert(Vhost _vhost, Metric _metric) { ArrayList<Insert> inserts = new ArrayList<>(); processMetric(_vhost, inserts, _metric); ct.execute(QueryBuilder.batch(inserts.toArray(new Insert[inserts.size()]))); monitor.queryBatchCount.incrementAndGet(); monitor.queryPutCount.addAndGet(inserts.size()); }
From source file:net.sf.keystore_explorer.crypto.x509.X509CertUtil.java
/** * Load one or more certificates from the specified stream. * * @param is/* www . j av a 2 s.co m*/ * Stream to load certificates from * @return The certificates * @throws CryptoException * Problem encountered while loading the certificate(s) */ public static X509Certificate[] loadCertificates(InputStream is) throws CryptoException { byte[] certsBytes = null; try { certsBytes = ReadUtil.readFully(is); // fix common input certificate problems by converting PEM/B64 to DER certsBytes = fixCommonInputCertProblems(certsBytes); is = new ByteArrayInputStream(certsBytes); CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, "GNU-PKI"); 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); } }
From source file:de.kapsi.net.daap.DaapHeaderConstructor.java
/** * Creates an Audio Header/*from ww w . j a v a 2 s . c o m*/ * * @param request * @param contentLength * @return */ public static byte[] createAudioHeader(DaapRequest request, int pos, int end, int contentLength) { try { DaapConnection connection = request.getConnection(); int version = connection.getProtocolVersion(); if (version == DaapUtil.NULL) throw new IOException("Client Protocol Version is unknown"); String serverName = connection.getServer().getConfig().getServerName(); String statusLine = null; ArrayList headers = new ArrayList(); headers.add(new Header("Date", DaapUtil.now())); headers.add(new Header("DAAP-Server", serverName)); headers.add(new Header("Content-Type", "application/x-dmap-tagged")); // if (pos == 0 || version <= DaapUtil.VERSION_2) { statusLine = HTTP_OK; headers.add(new Header("Content-Length", Integer.toString(contentLength))); } else { statusLine = HTTP_PARTIAL_CONTENT; String cotentLengthStr = Integer.toString(contentLength - pos); String contentRange = "bytes " + pos + "-" + (contentLength - 1) + "/" + contentLength; headers.add(new Header("Content-Length", cotentLengthStr)); headers.add(new Header("Content-Range", contentRange)); } headers.add(new Header("Accept-Ranges", "bytes")); return toByteArray(statusLine, (Header[]) headers.toArray(new Header[0])); } catch (UnsupportedEncodingException err) { // Should never happen throw new RuntimeException(err); } catch (IOException err) { // Should never happen throw new RuntimeException(err); } }
From source file:com.brienwheeler.apps.main.MainBaseTest.java
@Test public void testProcessArgs() { String[] args = new String[] { ONE, TWO }; Main1 main = new Main1(args); main.run();//ww w .ja va 2s. com ArrayList<String> processedArgs = main.getProcessedArgs(); Assert.assertTrue(Arrays.equals(args, processedArgs.toArray(new String[processedArgs.size()]))); }
From source file:cn.codepub.redis.directory.io.InputOutputStream.java
default String[] getAllFileNames(String directoryMedata) { Objects.requireNonNull(directoryMedata); Set<byte[]> hkeys = hkeys(directoryMedata.getBytes()); Objects.requireNonNull(hkeys); ArrayList<String> names = Lists.newArrayList(); hkeys.forEach(key -> names.add(new String(key, StandardCharsets.UTF_8))); return names.toArray(ArrayUtils.EMPTY_STRING_ARRAY); }
From source file:org.waarp.openr66.database.data.DbHostAuth.java
/** * Get All DbHostAuth from database or from internal hashMap in case of no database support * /*from w ww . j a va2s.com*/ * @param dbSession * may be null * @return the array of DbHostAuth * @throws WaarpDatabaseNoConnectionException * @throws WaarpDatabaseSqlException */ public static DbHostAuth[] getAllHosts(DbSession dbSession) throws WaarpDatabaseNoConnectionException, WaarpDatabaseSqlException { if (dbSession == null) { DbHostAuth[] result = new DbHostAuth[0]; return dbR66HostAuthHashMap.values().toArray(result); } String request = "SELECT " + selectAllFields; request += " FROM " + table; DbPreparedStatement preparedStatement = new DbPreparedStatement(dbSession, request); ArrayList<DbHostAuth> dbArrayList = new ArrayList<DbHostAuth>(); preparedStatement.executeQuery(); while (preparedStatement.getNext()) { DbHostAuth hostAuth = getFromStatement(preparedStatement); dbArrayList.add(hostAuth); } preparedStatement.realClose(); DbHostAuth[] result = new DbHostAuth[0]; return dbArrayList.toArray(result); }
From source file:com.brienwheeler.apps.main.MainBaseTest.java
@Test public void testSkipBaseArgs() { String[] args = new String[] { P, TestDataConstants.PROPS_FILE1 }; Main1 main = new Main1(args); main.dontUseBastOpts();/*from ww w.j av a 2 s .c om*/ System.clearProperty(TestDataConstants.PROPS_FILE1_PROP); Assert.assertNull(System.getProperty(TestDataConstants.PROPS_FILE1_PROP)); main.run(); Assert.assertNull(System.getProperty(TestDataConstants.PROPS_FILE1_PROP)); ArrayList<String> processedArgs = main.getProcessedArgs(); Assert.assertTrue(Arrays.equals(args, processedArgs.toArray(new String[processedArgs.size()]))); }
From source file:com.forerunnergames.tools.common.Strings.java
/** * Splits a word into multiple words using uppercase characters as a delimiter, but the delimiter is not discarded. * For example: ThisWordHasUpperCASECharactersInIT will be split into the separate words: { "This", "Word", "Has", * "Upper", "C", "A", "S", "E", "Characters", "In", "I", "T" } * * @param word/*from w w w .j a v a2s . c o m*/ * The word to split, must not be null, may be empty, may be blank (whitespace only), may contain whitespace, * may contain Unicode characters. * * @return An array of the split words, each one maintaining their original case, or the original word in a single * element array, if there was nothing to split, or an empty array of length 0 if the original word was empty. */ public static String[] splitByUpperCase(final String word) { Arguments.checkIsNotNull(word, "word"); final String[] rawSplitWords = word.split("(?=\\p{Lu})"); final ArrayList<String> nonEmptySplitWords = new ArrayList<>(); for (final String splitWord : rawSplitWords) { if (!splitWord.isEmpty()) nonEmptySplitWords.add(splitWord); } return nonEmptySplitWords.toArray(new String[nonEmptySplitWords.size()]); }
From source file:dk.dma.navnet.messages.TextMessageReader.java
public String[] takeStringArray() throws IOException { if (jp.nextToken() != JsonToken.START_ARRAY) { throw new IOException("Expected an String, but was '" + jp.getText() + "'"); }//from ww w . j ava 2 s .co m ArrayList<String> result = new ArrayList<>(); while (jp.nextToken() != JsonToken.END_ARRAY) { result.add(jp.getText()); } return result.toArray(new String[result.size()]); }