List of usage examples for org.apache.commons.lang ArrayUtils toString
public static String toString(Object array)
Outputs an array as a String, treating null
as an empty array.
From source file:org.gradoop.flink.model.impl.operators.matching.single.cypher.operators.join.functions.ExtractPropertyJoinColumnsTest.java
@Test public void testMultiColumn() throws Exception { PropertyValue a = PropertyValue.create("Foo"); PropertyValue b = PropertyValue.create(42); Embedding embedding = new Embedding(); embedding.add(GradoopId.get(), a, b); ExtractPropertyJoinColumns udf = new ExtractPropertyJoinColumns(Arrays.asList(0, 1)); Assert.assertEquals(//from w w w .jav a 2 s. com ArrayUtils.toString(embedding.getRawProperty(0)) + ArrayUtils.toString(embedding.getRawProperty(1)), udf.getKey(embedding)); }
From source file:org.hippoecm.hst.demo.components.Algebra.java
@Override public void doBeforeRender(final HstRequest request, final HstResponse response) throws HstComponentException { RandomGenerator randomGenerator = HstServices.getComponentManager().getComponent("randomGenerator", RANDOM_NUMBERS_MODULE_NAME); MatrixOperator matrixOperator = HstServices.getComponentManager().getComponent("matrixOperator", LINEAR_ALGEBRA_MODULE_NAME); if (!(matrixOperator instanceof MyMatrixOperator)) { throw new AssertionError("matrixOperator is expected to be an instanceof MyMatrixOperator"); }//from w w w . ja v a 2 s .co m InverseOperator inverseOperator = HstServices.getComponentManager().getComponent("inverseOperator", LINEAR_ALGEBRA_MODULE_NAME); if (!(inverseOperator.getMatrixOperator() instanceof MyMatrixOperator)) { throw new AssertionError("matrixOperator is expected to be an instanceof MyMatrixOperator"); } double[][] matrixData = new double[2][2]; for (int i = 0; i < 2; i++) { double[] randomNums = randomGenerator.generate(2); for (int j = 0; j < 2; j++) { matrixData[i][j] = randomNums[j]; } } double[][] inverseMatrixData = matrixOperator.inverse(matrixData); request.setAttribute("matrix", ArrayUtils.toString(matrixData)); request.setAttribute("inverse", ArrayUtils.toString(inverseMatrixData)); double[][] multiplied = matrixOperator.multiply(matrixData, inverseMatrixData); request.setAttribute("multiplied", ArrayUtils.toString(multiplied)); }
From source file:org.hyperic.hq.autoinventory.server.session.AutoinventoryManagerImpl.java
/** * Called by agents to report platforms, servers, and services detected via * autoinventory scans.//from w w w .j a v a 2 s .c o m * @param agentToken The token identifying the agent that sent the report. * @param stateCore The ScanState that was detected during the autoinventory * scan. */ public AIPlatformValue reportAIData(String agentToken, ScanStateCore stateCore) throws AutoinventoryException { final StopWatch watch = new StopWatch(); final boolean debug = log.isDebugEnabled(); ScanState state = new ScanState(stateCore); AIPlatformValue aiPlatform = state.getPlatform(); // This could happen if there was a serious error in the scan, // and not even the platform could be detected. if (state.getPlatform() == null) { log.warn("ScanState did not even contain a platform, ignoring."); return null; } // TODO: G log.info("Received auto-inventory report from " + aiPlatform.getFqdn() + "; IPs -> " + ArrayUtils.toString(aiPlatform.getAIIpValues()) + "; CertDN -> " + aiPlatform.getCertdn() + "; (" + state.getAllServers().size() + " servers)"); if (debug) { log.debug("AutoinventoryManager.reportAIData called, " + "scan state=" + state); log.debug("AISERVERS=" + state.getAllServers()); } // In the future we may want this method to act as // another user besides "admin". It might make sense to have // a user per-agent, so that actions that are agent-initiated // can be tracked. Of course, this will be difficult when the // agent is reporting itself to the server for the first time. // In that case, we'd have to act as admin and be careful about // what we allow that codepath to do. AuthzSubject subject = getHQAdmin(); aiPlatform.setAgentToken(agentToken); if (debug) { log.debug("AImgr.reportAIData: state.getPlatform()=" + aiPlatform); } addAIServersToAIPlatform(stateCore, state, aiPlatform); aiPlatform = aiQueueManager.queue(subject, aiPlatform, stateCore.getAreServersIncluded(), false, true); approvePlatformDevice(subject, aiPlatform); checkAgentAssignment(subject, agentToken, aiPlatform); if (debug) { log.debug("reportAIData " + watch); } return aiPlatform; }
From source file:org.isatools.tablib.parser.TabCsvReader.java
@Override public String[] readNext() throws IOException { String[] result = null;/* w ww . j a v a2 s . com*/ log.trace("TabCsvReader, current status: " + status); switch (status) { case NORMAL: // Keep reading until we meet the field of a section that has no header String[] next = super.readNext(); lastReadLineIndex++; if (isCommentLine(next)) { result = next; } else { String header = next != null && next.length > 0 ? StringUtils.trimToNull(next[0]) : null; Section section = header == null ? null : format.getSectionByField(header); if (section != null) { if ("true".equals(section.getAttr("is-header-omitted"))) { // If we are in such a section, return \n and a generated header result = new String[0]; generatedHeader = new String[] { section.getAttr("header") }; status = Status.HEADER_OMITTED_SECTION_ENTERED; } else { result = next; } } else if (TabCsvReader.isHeaderLine(next) && format.getSectionByHeader(header, false) != null) { // If we have a section header, first return a blank line (which can be omitted), then return // the header itself. You can continue with omitted-header case // result = new String[0]; status = Status.ADD_BLANK_LINE_TO_HEADER; } else { result = next; } } // Actual data line will be returned after the generated header lastRead = next; break; case HEADER_OMITTED_SECTION_ENTERED: // We fall here after having entered a section without header, // if we still have to return the generated header, do it if (generatedHeader != null) { result = generatedHeader; generatedHeader = null; } else { // otherwise return the line we kept and go ahead in normal status result = lastRead; status = Status.INSIDE_HEADER_OMITTED_SECTION; } break; case INSIDE_HEADER_OMITTED_SECTION: next = super.readNext(); lastReadLineIndex++; // We stay inside the header-omitted section until we meet a blank line, or the header of the next section, // or a field which does not belong to the current header-omitted section if (!isCommentLine(next) && (isBlankLine(next) || isHeaderLine(next) || format.getSectionByField(next[0]) != null)) // we have another section, go to the closing state { status = Status.HEADER_OMITTED_SECTION_EXITED; } // Returns the line inside the header-omitted section in any case result = next; lastRead = next; break; case HEADER_OMITTED_SECTION_EXITED: // If we are closing a header-omitted section, return a blank line and then go back to normal model result = new String[0]; status = Status.NORMAL; break; case ADD_BLANK_LINE_TO_HEADER: result = lastRead; status = Status.NORMAL; // no other case possible } log.trace("TabCsvReader, new status: " + status + ", last read: " + ArrayUtils.toString(lastRead) + ", result: " + ArrayUtils.toString(result)); return result; }
From source file:org.isatools.tablib.parser.TabLoader.java
/** * Loads a tabular file from a stream, parses it and spawns the * in-memory format object model. Instantiate a new {@link FormatInstance} and returns it. * <p/>//from www .jav a 2 s .c om * TODO: move the code in a specific parser. * * @param fileId used to store it in the resulting format instance. * @param reader the TSV stream to read lines from * @param formatId the name of format expected in the reader */ public FormatInstance parse(String fileId, Reader reader, Format format) throws IOException { // ____________ Init ______________ // if (format == null) { throw new TabInternalErrorException("parse(): null format"); } log.trace("Parsing the format: " + format.getId()); // The CSV reader TabCsvReader csvrdr = new TabCsvReader(reader, format); List<String[]> csvLines = new ArrayList<String[]>(); // The current parser status ParserState status = ParserState.WAITING_SECTION_BEGIN; // Use the format FormatInstance formatInstance = new FormatInstance(format, formatSetInstance); formatInstance.setFileId(fileId); // Step through the sections while scanning the lines // // TODO: remove int lineNo = 1; Section curSection = null; int sectionStartingLine = -1; for (String[] csvLine = null; (csvLine = csvrdr.readNext()) != null;) { log.trace("Parsing line: " + ArrayUtils.toString(csvLine)); if (TabCsvReader.isCommentLine(csvLine)) // Comment, go ahead { continue; } switch (status) { case WAITING_SECTION_BEGIN: if (TabCsvReader.isBlankLine(csvLine)) // Go ahead, we allow for multiple blank lines { continue; } if (TabCsvReader.isHeaderLine(csvLine)) { String csvHeader = csvLine[0]; Section section = (Section) format.getSectionByHeader(csvHeader, false); if (section != null) { // Convert the header into the preferred format (e.g.: upper case) csvLine[0] = section.getAttr("header"); // Start considering the next section status = ParserState.READING_SECTION_LINES; curSection = section; sectionStartingLine = csvrdr.getLastReadLineIndex(); log.trace(String.format("Start parsing the section: '%s' ('%s') at line %d", section.getId(), csvHeader, sectionStartingLine)); } else { throw new TabStructureError( i18n.msg("wrong_section_header", csvHeader, csvrdr.getLastReadLineIndex())); } } else { throw new TabStructureError(i18n.msg("missing_section_header", csvrdr.getLastReadLineIndex())); } break; case READING_SECTION_LINES: if (TabCsvReader.isBlankLine(csvLine)) { // Pass the accumulated lines to the section parser log.trace("Invoking the parser"); SectionInstance sectionInstance = curSection.getParser(formatInstance).parseCsvLines(csvLines); sectionInstance.setStartingLine(sectionStartingLine); formatInstance.addSectionInstance(sectionInstance); // Clear parsed lines and move to the next section csvLines.clear(); curSection = null; status = ParserState.WAITING_SECTION_BEGIN; } else { // Accumulate the lines for the section csvLines.add(csvLine); log.trace("Added the line:\n" + Arrays.toString(csvLine) + "\nlen: " + csvLine.length); } // no other case will occur } // switch // TODO: remove lineNo++; } // loop on the lines // Check final status and possible inconsistencies // if (status == ParserState.READING_SECTION_LINES) { // Pass the last accumulated lines to the section parser log.trace("Invoking the parser (at the EOF)"); SectionInstance sectionInstance = curSection.getParser(formatInstance).parseCsvLines(csvLines); sectionInstance.setStartingLine(sectionStartingLine); formatInstance.addSectionInstance(sectionInstance); } log.trace("Done parsing format: " + format.getId()); return formatInstance; }
From source file:org.jenkinsci.plugins.proccleaner.PsBasedHPUXProcessTree.java
@Override public PsBasedProcessTree createProcessTreeFor(String user) throws InterruptedException, IOException { String[] cmd = { "ps", "-u", user, "-f" }; ProcessBuilder pb = new ProcessBuilder(cmd); pb.redirectErrorStream(true);//from ww w.j a v a2s .c om Process proc = pb.start(); final StringWriter writer = new StringWriter(); try { IOUtils.copy(proc.getInputStream(), writer); } catch (IOException e) { LOGGER.warning("'ps' command invocation IOException occurred!"); } BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream())); if (proc.waitFor() != 0) { LOGGER.warning("'ps' command invocation " + ArrayUtils.toString(cmd) + " failed! Return code: " + proc.exitValue()); LOGGER.fine("Received output from 'ps' command invocation follows:"); if (getLog() != null) { getLog().println("WARNING: 'ps' command invocation " + ArrayUtils.toString(cmd) + " failed! Return code: " + proc.exitValue()); getLog().println("DEBUG: Received output from 'ps' command invocation follows:"); } String line; while ((line = reader.readLine()) != null) { LOGGER.fine(line); if (getLog() != null) getLog().println("DEBUG: '" + line + "'"); } return null; } String line = reader.readLine(); // first line should be "UID PID PPID C STIME TTY TIME COMMAND" - skip it if (StringUtils.isEmpty(line)) { LOGGER.fine("Unrecognized output from 'ps' command invocation! Output is empty!"); if (getLog() != null) { getLog().println("DEBUG: Unrecognized output from 'ps' command invocation! Output is empty!"); } return null; } if (!line.matches("^\\s*UID\\s*PID\\s*PPID\\s*C\\s*STIME\\s*TTY\\s*TIME\\s*COMMAND\\s*$")) { LOGGER.fine("Unrecognized first output line from 'ps' command invocation! Was: '" + line + "'"); if (getLog() != null) { getLog().println( "DEBUG: Unrecognized first output line from 'ps' command invocation! Was: '" + line + "'"); } return null; } PsBasedProcessTree ptree = new PsBasedHPUXProcessTree(); while ((line = reader.readLine()) != null) { String[] ps = line.trim().split(" +", 8); if (ps.length < 8) { LOGGER.fine("Unrecognized output line from 'ps' command invocation! Was: '" + line + "'"); if (getLog() != null) { getLog().println( "DEBUG: Unrecognized output line from 'ps' command invocation! Was '" + line + "'"); } return null; } if (getLog() != null) getLog().println("DEBUG: '" + line + "'"); ptree.addProcess(ps[1] + ' ' + ps[2] + ' ' + ps[7]); } ptree.setLog(getLog()); return ptree; }
From source file:org.jenkinsci.plugins.proccleaner.PsBasedUnixProcessTree.java
@Override public PsBasedProcessTree createProcessTreeFor(String user) throws InterruptedException, IOException { String[] cmd = { "ps", "-u", user, "-o", "pid,ppid,args" }; ProcessBuilder pb = new ProcessBuilder(cmd); pb.redirectErrorStream(true);/* ww w . j a va2 s . c om*/ final Process proc = pb.start(); final StringWriter writer = new StringWriter(); try { IOUtils.copy(proc.getInputStream(), writer); } catch (IOException e) { LOGGER.warning("'ps' command invocation IOException occurred!"); } BufferedReader reader = new BufferedReader(new StringReader(writer.toString())); if (proc.waitFor() != 0) { LOGGER.warning("'ps' command invocation " + ArrayUtils.toString(cmd) + " failed! Return code: " + proc.exitValue()); LOGGER.fine("Received output from 'ps' command invocation follows:"); if (getLog() != null) { getLog().println("WARNING: 'ps' command invocation " + ArrayUtils.toString(cmd) + " failed! Return code: " + proc.exitValue()); getLog().println("DEBUG: Received output from 'ps' command invocation follows:"); } String line; while ((line = reader.readLine()) != null) { LOGGER.fine(line); if (getLog() != null) getLog().println("DEBUG: '" + line + "'"); } return null; } String line = reader.readLine(); // first line should be "PID PPID COMMAND" - skip it if (StringUtils.isEmpty(line)) { LOGGER.fine("Unrecognized output from 'ps' command invocation! Output is empty!"); if (getLog() != null) { getLog().println("DEBUG: Unrecognized output from 'ps' command invocation! Output is empty!"); } return null; } if (!line.matches("^\\s*PID\\s*PPID\\s*(COMMAND|ARGS)\\s*$")) { LOGGER.fine("Unrecognized first output line from 'ps' command invocation! Was: '" + line + "'"); if (getLog() != null) { getLog().println( "DEBUG: Unrecognized first output line from 'ps' command invocation! Was: '" + line + "'"); } return null; } PsBasedProcessTree ptree = new PsBasedUnixProcessTree(); while ((line = reader.readLine()) != null) { if (getLog() != null) getLog().println("DEBUG: '" + line + "'"); ptree.addProcess(line); } ptree.setLog(getLog()); return ptree; }
From source file:org.jumpmind.db.sql.JdbcSqlTransaction.java
public int addRow(Object marker, Object[] args, int[] argTypes) { int rowsUpdated = 0; try {//w ww. j av a 2 s. c o m if (log.isDebugEnabled()) { log.debug("Adding {} {}", ArrayUtils.toString(args), inBatchMode ? " in batch mode" : ""); } if (args != null) { jdbcSqlTemplate.setValues(pstmt, args, argTypes, jdbcSqlTemplate.getLobHandler().getDefaultHandler()); } if (inBatchMode) { if (marker == null) { marker = new Integer(markers.size() + 1); } markers.add(marker); pstmt.addBatch(); if (markers.size() >= jdbcSqlTemplate.getSettings().getBatchSize()) { rowsUpdated = flush(); } } else { pstmt.execute(); rowsUpdated = pstmt.getUpdateCount(); } } catch (SQLException ex) { throw jdbcSqlTemplate.translate(ex); } return rowsUpdated; }
From source file:org.jumpmind.metl.core.runtime.component.Execute.java
@Override public void handle(Message inputMessage, ISendMessageCallback callback, boolean unitOfWorkBoundaryReached) { if ((PER_UNIT_OF_WORK.equals(runWhen) && inputMessage instanceof ControlMessage) || (!PER_UNIT_OF_WORK.equals(runWhen) && !(inputMessage instanceof ControlMessage))) { try {/*from w w w. j av a 2 s.c o m*/ ByteArrayOutputStream os = getByteArrayOutputStream(); PumpStreamHandler outputHandler = new PumpStreamHandler(os); org.apache.tools.ant.taskdefs.Execute antTask = getAntTask(outputHandler); antTask.setCommandline(commands); info("About to execute: %s", ArrayUtils.toString(commands)); int code = antTask.execute(); String output = new String(os.toByteArray()); if (successCode == code || continueOnError) { if (successCode == code) { info("Returned an code of %d", code); } else { warn("Returned an code of %d", code); } info("The output of the command was: %s", output); ArrayList<String> payload = new ArrayList<String>(); payload.add(output); callback.sendTextMessage(null, payload); } else { info("The output of the command was: %s", output); throw new IoException("%s failed with an error code of %d", ArrayUtils.toString(commands), code); } } catch (IOException e) { throw new IoException(e); } } }
From source file:org.jumpmind.symmetric.AbstractCommandLauncher.java
public void execute(String args[]) { PosixParser parser = new PosixParser(); Options options = new Options(); buildOptions(options);//from w w w . j a v a2 s .c o m try { CommandLine line = parser.parse(options, args); if (line.hasOption(HELP) || (line.getArgList().contains(HELP)) || ((args == null || args.length == 0) && line.getOptions().length == 0 && printHelpIfNoOptionsAreProvided())) { printHelp(line, options); System.exit(2); } configureLogging(line); configurePropertiesFile(line); if (line.getOptions() != null) { for (Option option : line.getOptions()) { log.info("Option: name={}, value={}", new Object[] { option.getLongOpt() != null ? option.getLongOpt() : option.getOpt(), ArrayUtils.toString(option.getValues()) }); } } executeWithOptions(line); } catch (ParseException e) { System.err.println(e.getMessage()); printUsage(options); System.exit(4); } catch (Exception e) { System.err.println("-------------------------------------------------------------------------------"); System.err.println("An exception occurred. Please see the following for details:"); System.err.println("-------------------------------------------------------------------------------"); ExceptionUtils.printRootCauseStackTrace(e, System.err); System.err.println("-------------------------------------------------------------------------------"); System.exit(1); } }