List of usage examples for java.util ArrayList toArray
@SuppressWarnings("unchecked") public <T> T[] toArray(T[] a)
From source file:com.cloudera.sqoop.tool.TestToolPlugin.java
public void testPlugin() { // Register the plugin with SqoopTool. Configuration pluginConf = new Configuration(); pluginConf.set(SqoopTool.TOOL_PLUGINS_KEY, PluginClass.class.getName()); SqoopTool.loadPlugins(pluginConf);/*from w ww. j av a2 s.c om*/ ArrayList<String> args = new ArrayList<String>(); args.add("fooTool"); args.add("--username"); args.add("bob"); args.add("--connect"); args.add("anywhere"); int ret = Sqoop.runTool(args.toArray(new String[0])); assertEquals("Expected tool run success", 0, ret); String actualUser = FooTool.getLastUser(); assertEquals("Failed to set username correctly.", "bob", actualUser); }
From source file:atg.tools.dynunit.nucleus.NucleusUtils.java
public static Nucleus startNucleusWithModules(NucleusStartupOptions startupOptions) throws ServletException, FileNotFoundException { notNull(startupOptions);//from w w w. jav a 2 s.c o m notEmpty(startupOptions.getInitialService()); final File dynamoRoot = getExistingFile(findDynamoRoot()); setDynamoPropertyIfEmpty("atg.dynamo.root", dynamoRoot.getAbsolutePath()); final File dynamoHome = new File(dynamoRoot, "home"); setDynamoPropertyIfEmpty("atg.dynamo.home", dynamoHome.getAbsolutePath()); final String modulesPath = StringUtils.join(startupOptions.getModules(), File.pathSeparatorChar); setDynamoProperty("atg.dynamo.modules", modulesPath); setSystemPropertyIfEmpty("atg.dynamo.license.read", "true"); setSystemPropertyIfEmpty("atg.license.read", "true"); // our temporary server directory. File fileServerDir = null; try { AppModuleManager moduleManager = new MultiInstallLocalAppModuleManager(dynamoRoot.getAbsolutePath(), dynamoRoot, modulesPath); AppLauncher launcher = AppLauncher.getLauncher(moduleManager, modulesPath); // Start Nucleus String configpath = DynamoServerLauncher.calculateConfigPath(launcher, startupOptions.getLiveConfig(), startupOptions.getLayersAsString(), false, null); // use the NucleusUtils config dir as a base, since it // empties out license checks, etc. File fileBaseConfig = getConfigPath(NucleusUtils.class, null, false); if ((fileBaseConfig != null) && fileBaseConfig.exists()) { configpath = configpath + File.pathSeparator + fileBaseConfig.getAbsolutePath(); } // add the additional config path as the last arg, if needed File fileTestConfig = getConfigPath(startupOptions.getClassRelativeTo(), startupOptions.getBaseConfigDirectory(), false); // now add it to the end of our config path if ((fileTestConfig != null) && fileTestConfig.exists()) { configpath = configpath + File.pathSeparator + fileTestConfig.getAbsolutePath(); } else if (fileTestConfig != null) { logger.error("Warning: did not find directory {}", fileTestConfig.getAbsolutePath()); } String dynUnitHome = DynUnit.getHome(); if (dynUnitHome != null) { configpath = configpath + File.pathSeparator + dynUnitHome + File.separatorChar + "licenseconfig"; } // finally, create a server dir. fileServerDir = createTempServerDir(); setSystemProperty("atg.dynamo.server.home", fileServerDir.getAbsolutePath()); NucleusServlet.addNamingFactoriesAndProtocolHandlers(); ArrayList<String> listArgs = new ArrayList<String>(); listArgs.add(configpath); listArgs.add("-initialService"); listArgs.add(startupOptions.getInitialService()); PropertyEditors.registerEditors(); logger.info("Starting nucleus with arguments: " + listArgs); Nucleus n = Nucleus.startNucleus(listArgs.toArray(new String[listArgs.size()])); // remember our temporary server directory for later deletion nucleiConfigPathsCache.put(n, fileServerDir); // clear out the variable, so our finally clause knows not to // delete it fileServerDir = null; return n; } catch (AppLauncherException e) { throw logger.throwing(new ServletException(e)); } catch (IOException e) { throw logger.throwing(new ServletException(e)); } finally { if (fileServerDir != null) { try { // a non-null value means it was created, but not added to our list, // so we should nuke it. FileUtils.deleteDirectory(fileServerDir); } catch (IOException e) { logger.catching(Level.ERROR, e); } } } }
From source file:com.thoughtworks.go.domain.materials.svn.SvnMaterialUpdater.java
private BuildCommand update(String workingDir, Revision revision) { ArrayList<String> args = new ArrayList<>(); addCredentials(args);//from w w w . java 2 s . co m args.add("update"); args.add("--non-interactive"); args.add("-r"); args.add(revision.getRevision()); args.add(workingDir); return exec("svn", args.toArray(new String[args.size()])); }
From source file:com.inmobi.messaging.checkpoint.FSCheckpointProvider.java
@Override public byte[] read(String key) { Path currentCheckpoint = getCheckpointPath(key); BufferedInputStream in = null; byte[] buffer = null; try {//from ww w. ja v a2 s. c o m LOG.info("checkpoint path:" + currentCheckpoint); if (!fs.exists(currentCheckpoint)) { LOG.info("No checkpoint to read"); return null; } in = new BufferedInputStream(fs.open(currentCheckpoint)); ArrayList<Byte> tempList = new ArrayList<Byte>(); int next = in.read(); while (next != -1) { tempList.add((byte) next); next = in.read(); } Byte[] bytes = tempList.toArray(new Byte[tempList.size()]); buffer = new byte[tempList.size()]; for (int i = 0; i < buffer.length; i++) { buffer[i] = bytes[i].byteValue(); } } catch (IOException e) { LOG.warn("Could not read checkpoint ", e); throw new RuntimeException(e); } finally { try { if (in != null) in.close(); } catch (IOException e) { LOG.error("Error in closing [" + currentCheckpoint + "]"); throw new RuntimeException(e); } } return buffer; }
From source file:KV78Tester.java
public String[] parseLines(BufferedReader in) throws Exception { JsonFactory f = new JsonFactory(); JsonParser jp = f.createJsonParser(in); ArrayList<String> lines = new ArrayList<String>(); jp.nextToken();/*from w ww . j ava2s . c o m*/ while (jp.nextToken() != JsonToken.END_OBJECT) { String line = jp.getCurrentName(); lines.add(line); jp.nextToken(); } jp.close(); in.close(); return lines.toArray(new String[lines.size()]); }
From source file:jat.application.DE405Propagator.DE405PropagatorPlot.java
double[][] getXYZforPlot(ArrayList<Double> xsol, ArrayList<Double> ysol, ArrayList<Double> zsol) { int arraySize = xsol.size(); double[] xsolArray = ArrayUtils.toPrimitive(xsol.toArray(new Double[arraySize])); double[] ysolArray = ArrayUtils.toPrimitive(ysol.toArray(new Double[arraySize])); double[] zsolArray = ArrayUtils.toPrimitive(zsol.toArray(new Double[arraySize])); double[][] XYZ = new double[arraySize][3]; plotBounds = 0.;// www.j a v a2 s . c o m for (int i = 0; i < arraySize; i++) { XYZ[i][0] = xsolArray[i]; XYZ[i][1] = ysolArray[i]; XYZ[i][2] = zsolArray[i]; plotBounds = Math.max(plotBounds, Math.abs(XYZ[i][0])); plotBounds = Math.max(plotBounds, Math.abs(XYZ[i][1])); plotBounds = Math.max(plotBounds, Math.abs(XYZ[i][2])); } plotBounds /= 1.5; return XYZ; }
From source file:cool.pandora.modeller.ui.BagTableFormBuilder.java
/** * addList.//from w w w . j a v a 2s .c o m * * @param isRequired boolean * @param label String * @param elements Collection * @param defaultValue String * @param checkbox JComponent * @return addBinding */ public JComponent[] addList(final boolean isRequired, final String label, final Collection<String> elements, final String defaultValue, final JComponent checkbox) { final ArrayList<String> listModel = new ArrayList<>(); listModel.addAll(elements); // Set default value selected from value list final JComboBox<String> dropDownTextField = new JComboBox<>( listModel.toArray(new String[listModel.size()])); dropDownTextField.setSelectedItem(defaultValue); final Object obj = dropDownTextField.getSelectedItem(); dropDownTextField.setSelectedItem(obj); return addBinding(isRequired, label, dropDownTextField, checkbox); }
From source file:org.opcfoundation.ua.application.Application.java
public String[] getLocaleIds() { ArrayList<String> result = new ArrayList<String>(locales.size()); for (Locale l : locales) result.add(LocalizedText.toLocaleId(l)); return result.toArray(new String[result.size()]); }
From source file:com.cloudera.sqoop.TestTargetDir.java
/** test invalid argument exception if several output options. */ public void testSeveralOutputsIOException() throws IOException { try {//from ww w. jav a2 s.c o m ArrayList args = getOutputArgv(true); args.add("--warehouse-dir"); args.add(getWarehouseDir()); args.add("--target-dir"); args.add(getWarehouseDir()); String[] argv = (String[]) args.toArray(new String[0]); runImport(argv); fail("warehouse-dir & target-dir were set and run " + "without problem reported"); } catch (IOException e) { // expected } }
From source file:com.morphoss.jumble.models.Word.java
@Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(nameKey);//from w w w.j ava 2s .c o m dest.writeString(imagePath); ArrayList<Localisation> valueList = new ArrayList<Localisation>(); valueList.addAll(localisations.values()); Localisation[] arr = new Localisation[valueList.size()]; valueList.toArray(arr); dest.writeParcelableArray(arr, 0); }