List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:de.luhmer.owncloudnewsreader.reader.GoogleReaderApi.GoogleReaderMethods.java
public static String[] getStarredList(String _USERNAME, String _PASSWORD) { Log.d("mygr", "METHOD: getStarredList()"); String returnString = null;/*from ww w .j a v a 2s . c om*/ String _TAG_LABEL = null; try { _TAG_LABEL = "stream/contents/user/" + AuthenticationManager.getGoogleUserID(_USERNAME, _PASSWORD) + "/state/com.google/starred"; } catch (IOException e) { e.printStackTrace(); } try { HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(GoogleReaderConstants._API_URL + _TAG_LABEL); request.addHeader("Authorization", GoogleReaderConstants._AUTHPARAMS + AuthenticationManager.getGoogleAuthKey(_USERNAME, _PASSWORD)); HttpResponse response = client.execute(request); returnString = HttpHelper.request(response); Pattern pattern = Pattern.compile("\"alternate\":\\[\\{\"href\":\"(.*?)\","); Matcher matcher = pattern.matcher(returnString); ArrayList<String> resultList = new ArrayList<String>(); while (matcher.find()) resultList.add(matcher.group(1)); String[] ret = new String[resultList.size()]; resultList.toArray(ret); return ret; } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:gdsc.smlm.ij.plugins.FilterResults.java
/** * Build a list of all the image names.// www .j a v a2 s . c om * * @return The list of images */ public static String[] getImageList() { ArrayList<String> newImageList = new ArrayList<String>(); newImageList.add("[None]"); for (int id : getIDList()) { ImagePlus imp = WindowManager.getImage(id); if (imp == null) continue; if (!imp.getProcessor().isBinary()) continue; newImageList.add(imp.getTitle()); } return newImageList.toArray(new String[0]); }
From source file:de.bayern.gdi.utils.StringUtils.java
/** * Splits a string by a pattern./*from ww w. j a v a2s .c o m*/ * @param s The string to split. * @param delim The delimeter. * @param keep Indicates if the delimeters should be kept. * @return The splitted string. */ public static String[] split(String s, Pattern delim, boolean keep) { if (s == null) { s = ""; } int lastMatch = 0; ArrayList<String> parts = new ArrayList<>(); Matcher m = delim.matcher(s); while (m.find()) { String x = s.substring(lastMatch, m.start()); if (!x.isEmpty()) { parts.add(x); } if (keep) { parts.add(m.group(0)); } lastMatch = m.end(); } String x = s.substring(lastMatch); if (!x.isEmpty()) { parts.add(x); } return parts.toArray(new String[parts.size()]); }
From source file:com.iw.plugins.spindle.core.util.JarEntryFileUtil.java
public static IPackageFragment[] getPackageFragments(IWorkspaceRoot root, IJarEntryResource entry) throws CoreException { ArrayList result = new ArrayList(); IProject[] projects = root.getProjects(); for (int i = 0; i < projects.length; i++) { if (!projects[i].isOpen() || !projects[i].hasNature(JavaCore.NATURE_ID)) continue; IPackageFragment frag = getPackageFragment(JavaCore.create(projects[i]), entry, false); if (frag != null) result.add(frag);/* w w w.j a v a 2 s . c o m*/ } return (IPackageFragment[]) result.toArray(new IPackageFragment[result.size()]); }
From source file:com.google.cloud.dataflow.examples.opinionanalysis.IndexerPipelineUtils.java
public static byte[] extractRecordDelimiters(String paramValue) { String[] delimiters = paramValue.split(","); ArrayList<Byte> resList = new ArrayList<Byte>(); for (String d : delimiters) resList.add(Byte.parseByte(d)); Byte[] resArray = new Byte[resList.size()]; resList.toArray(resArray); byte[] result = ArrayUtils.toPrimitive(resArray); return result; }
From source file:com.aspose.email.examples.outlook.pst.SplitAndMergePSTFile.java
public static void mergeMultiplePSTsIntoASinglePST() { // Path to files that will be merged into "source.pst". String mergeWithFolderPath = dataDir + "MergeWith"; String mergeIntoFolderPath = dataDir + "MergeInto" + File.separator; // This will ensure that we can run this example as many times as we want. // It will discard changes made to to the Source file in last run of this example. deleteAndRecopySampleFiles(mergeIntoFolderPath, dataDir + "MergeMultiplePSTsIntoASinglePST/"); final PersonalStorage pst = PersonalStorage.fromFile(mergeIntoFolderPath + "source.pst"); try {//ww w. j ava 2 s.com pst.StorageProcessed.add(new StorageProcessedEventHandler() { public void invoke(Object sender, StorageProcessedEventArgs e) { pstMerge_OnStorageProcessed(sender, e); } }); pst.ItemMoved.add(new ItemMovedEventHandler() { public void invoke(Object sender, ItemMovedEventArgs e) { pstMerge_OnItemMoved(sender, e); } }); //Get a collection of all files in the directory ArrayList<String> results = new ArrayList<String>(); File[] files = new File(mergeWithFolderPath).listFiles(); //If this path name does not denote a directory, then listFiles() returns null. if (files == null) return; for (File file : files) { if (file.isFile() && file.getName().endsWith(".pst")) { results.add(file.getAbsolutePath()); } } String[] fileNames = results.toArray(new String[0]); pst.mergeWith(fileNames); } finally { if (pst != null) (pst).dispose(); } }
From source file:com.baystep.jukeberry.JsonConfiguration.java
public static SourceDescription[] getSourceDescriptionArray(JSONObject obj, String key) { ArrayList<SourceDescription> list = new ArrayList<>(); JSONArray array = (JSONArray) obj.get(key); if (array != null) { Iterator it = array.iterator(); while (it.hasNext()) { JSONObject element = (JSONObject) it.next(); SourceDescription sd = new SourceDescription(); sd.name = element.get("name").toString(); sd.fqn = element.get("fqn").toString(); list.add(sd);/*from w ww . j av a2 s. c om*/ } } SourceDescription[] output = new SourceDescription[list.size()]; list.toArray(output); return output; }
From source file:com.limegroup.gnutella.gui.iTunesMediator.java
private static String[] createWSHScriptCommand(String playlist, File[] files) { ArrayList<String> command = new ArrayList<String>(); command.add("wscript"); command.add("//B"); command.add("//NoLogo"); command.add(new File(CommonUtils.getUserSettingsDir(), JS_IMPORT_SCRIPT_NAME).getAbsolutePath()); command.add(playlist);/*from w ww . ja va2 s . c om*/ for (File file : files) { command.add(file.getAbsolutePath()); } return command.toArray(new String[0]); }
From source file:com.jaspersoft.jasperserver.export.util.CommandUtils.java
protected static String[] checkSpringConfigs(String[] args) { ArrayList list = new ArrayList(); for (int i = 0; i < args.length; i++) { if (args[i].indexOf(SPRING_CONFIG_ARG) >= 0) { // we have the spring resource option, does the option point // to a dir or the actual files if (args[i].indexOf(SPRING_CONFIG_FILE) < 0) { list.add(getSpringFiles(args[i])); } else { list.add(args[i]);/*ww w.ja va2s . c o m*/ } } else { list.add(args[i]); } } return (String[]) list.toArray(new String[list.size()]); }
From source file:com.sun.faban.harness.webclient.RunUploader.java
/** * Client call to upload the run back to the originating server. * This method does nothing if the run is local. * @param runId The id of the run//from w w w .j a v a 2s .c om * @throws IOException If the upload fails */ public static void uploadIfOrigin(String runId) throws IOException { // 1. Check origin File originFile = new File( Config.OUT_DIR + File.separator + runId + File.separator + "META-INF" + File.separator + "origin"); if (!originFile.isFile()) return; // Is local run, do nothing. String originSpec = readStringFromFile(originFile); int idx = originSpec.lastIndexOf('.'); if (idx == -1) { // This is wrong, we do not accept this. logger.severe("Bad origin spec."); return; } idx = originSpec.lastIndexOf('.', idx - 1); if (idx == -1) { logger.severe("Bad origin spec."); return; } String host = originSpec.substring(0, idx); String key = null; URL target = null; String proxyHost = null; int proxyPort = -1; // Search the poll hosts for this origin. for (int i = 0; i < Config.pollHosts.length; i++) { Config.HostInfo pollHost = Config.pollHosts[i]; if (host.equals(pollHost.name)) { key = pollHost.key; target = new URL(pollHost.url, "upload"); proxyHost = pollHost.proxyHost; proxyPort = pollHost.proxyPort; break; } } if (key == null) { logger.severe("Origin host/url/key not found!"); return; } // 2. Jar up the run String[] files = new File(Config.OUT_DIR, runId).list(); File jarFile = new File(Config.TMP_DIR, runId + ".jar"); jar(Config.OUT_DIR + runId, files, jarFile.getAbsolutePath()); // 3. Upload the run ArrayList<Part> params = new ArrayList<Part>(); //MultipartPostMethod post = new MultipartPostMethod(target.toString()); params.add(new StringPart("host", Config.FABAN_HOST)); params.add(new StringPart("key", key)); params.add(new StringPart("origin", "true")); params.add(new FilePart("jarfile", jarFile)); Part[] parts = new Part[params.size()]; parts = params.toArray(parts); PostMethod post = new PostMethod(target.toString()); post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams())); HttpClient client = new HttpClient(); if (proxyHost != null) client.getHostConfiguration().setProxy(proxyHost, proxyPort); client.getHttpConnectionManager().getParams().setConnectionTimeout(5000); int status = client.executeMethod(post); if (status == HttpStatus.SC_FORBIDDEN) logger.severe("Server " + host + " denied permission to upload run " + runId + '!'); else if (status == HttpStatus.SC_NOT_ACCEPTABLE) logger.severe("Run " + runId + " origin error!"); else if (status != HttpStatus.SC_CREATED) logger.severe( "Server responded with status code " + status + ". Status code 201 (SC_CREATED) expected."); jarFile.delete(); }