Example usage for org.apache.commons.lang ArrayUtils toString

List of usage examples for org.apache.commons.lang ArrayUtils toString

Introduction

In this page you can find the example usage for org.apache.commons.lang ArrayUtils toString.

Prototype

public static String toString(Object array) 

Source Link

Document

Outputs an array as a String, treating null as an empty array.

Usage

From source file:it.grid.storm.namespace.util.userinfo.UserInfoCommand.java

/**
 * /*from  w w  w .j a  v a  2 s .  c  o  m*/
 * @param command
 *          String[]
 * @return String
 */
private String getOutput(String[] command) throws UserInfoException {

    String result = "";
    try {
        Process child = Runtime.getRuntime().exec(command);
        log.debug("Command executed: " + ArrayUtils.toString(command));
        BufferedReader stdInput = null;
        BufferedReader stdError = null;
        // Get the input stream and read from it
        if (child != null) {
            stdInput = new BufferedReader(new InputStreamReader(child.getInputStream()));
            stdError = new BufferedReader(new InputStreamReader(child.getErrorStream()));
        }

        if (stdInput != null) {

            // process the Command Output (Input for StoRM ;) )
            String line;
            int row = 0;
            log.trace("UserInfo Command Output :");
            while ((line = stdInput.readLine()) != null) {
                log.trace(row + ": " + line);
                boolean lineOk = processOutput(row, line);
                if (lineOk) {
                    result = result + line + "\n";
                }
                row++;
            }

            // process the Errors
            String errLine;
            if (stdError != null) {
                while ((errLine = stdError.readLine()) != null) {
                    log.warn("User Info Command Output contains an ERROR message " + errLine);
                    throw new UserInfoException(errLine);
                }
            }
        }
    } catch (IOException ex) {
        log.error("getUserInfo (id) I/O Exception: " + ex);
        throw new UserInfoException(ex);
    }
    return result;
}

From source file:de.thorstenberger.taskmodel.complex.complextaskhandling.subtasklets.impl.SubTasklet_MCBuilder.java

/**
 * Return the first <code>numToChoose</code> values from <code>values</code> as indexed by <code>indices</code><br/>
 * Example: selectFirst({10,20,30,40},{2,0,1,3},2) ==> {30,10}
 *
 * @param values/*  w ww  . j  a  v  a  2 s . c o  m*/
 * @param indices
 * @param numToChoose
 * @return
 */
private int[] selectFirst(int[] values, int[] indices, int numToChoose) {
    if (values.length != indices.length || indices.length < numToChoose)
        throw new IllegalArgumentException(String.format(
                "Internal implementation error, can't choose the first %d values of %s indexed by %s!",
                numToChoose, ArrayUtils.toString(values), ArrayUtils.toString(indices)));

    int[] result = new int[numToChoose];
    for (int i = 0; i < numToChoose; i++) {
        result[i] = values[indices[i]];
    }
    return result;
}

From source file:edu.duke.cabig.c3pr.service.StudyXMLImporterTestCase.java

private Errors getErrorsMock() {
    return new Errors() {

        public void setNestedPath(String nestedPath) {
            // TODO Auto-generated method stub

        }/*  w  w w  . j a v a  2 s  . c  o m*/

        public void rejectValue(String field, String errorCode, Object[] errorArgs, String defaultMessage) {
            // TODO Auto-generated method stub

        }

        public void rejectValue(String field, String errorCode, String defaultMessage) {
            // TODO Auto-generated method stub

        }

        public void rejectValue(String field, String errorCode) {
            // TODO Auto-generated method stub

        }

        public void reject(String errorCode, Object[] errorArgs, String defaultMessage) {
            log.error("Reject called: " + errorCode + ", " + ArrayUtils.toString(errorArgs) + ", "
                    + defaultMessage);

        }

        public void reject(String errorCode, String defaultMessage) {
            log.error("Reject called: " + errorCode + ", " + defaultMessage);

        }

        public void reject(String errorCode) {
            log.error("Reject called: " + errorCode);

        }

        public void pushNestedPath(String subPath) {
            // TODO Auto-generated method stub

        }

        public void popNestedPath() throws IllegalStateException {
            // TODO Auto-generated method stub

        }

        public boolean hasGlobalErrors() {
            // TODO Auto-generated method stub
            return false;
        }

        public boolean hasFieldErrors(String field) {
            // TODO Auto-generated method stub
            return false;
        }

        public boolean hasFieldErrors() {
            // TODO Auto-generated method stub
            return false;
        }

        public boolean hasErrors() {
            // TODO Auto-generated method stub
            return false;
        }

        public String getObjectName() {
            // TODO Auto-generated method stub
            return null;
        }

        public String getNestedPath() {
            // TODO Auto-generated method stub
            return null;
        }

        public List getGlobalErrors() {
            // TODO Auto-generated method stub
            return null;
        }

        public int getGlobalErrorCount() {
            // TODO Auto-generated method stub
            return 0;
        }

        public ObjectError getGlobalError() {
            // TODO Auto-generated method stub
            return null;
        }

        public Object getFieldValue(String field) {
            // TODO Auto-generated method stub
            return null;
        }

        public Class getFieldType(String field) {
            // TODO Auto-generated method stub
            return null;
        }

        public List getFieldErrors(String field) {
            // TODO Auto-generated method stub
            return null;
        }

        public List getFieldErrors() {
            // TODO Auto-generated method stub
            return null;
        }

        public int getFieldErrorCount(String field) {
            // TODO Auto-generated method stub
            return 0;
        }

        public int getFieldErrorCount() {
            // TODO Auto-generated method stub
            return 0;
        }

        public FieldError getFieldError(String field) {
            // TODO Auto-generated method stub
            return null;
        }

        public FieldError getFieldError() {
            // TODO Auto-generated method stub
            return null;
        }

        public int getErrorCount() {
            // TODO Auto-generated method stub
            return 0;
        }

        public List getAllErrors() {
            // TODO Auto-generated method stub
            return null;
        }

        public void addAllErrors(Errors errors) {
            // TODO Auto-generated method stub

        }
    };
}

From source file:com.thoughtworks.go.server.security.LdapAuthenticationTest.java

@Test
public void commonLdapUserShouldOnlyHaveAuthorityOfUserAndNotAdmin() throws Exception {
    ldapServer.addUser(employeesOrgUnit, "foleys", "some-password", "Shilpa Foley", "foleys@somecompany.com");

    CONFIG_HELPER.initializeConfigFile();
    CONFIG_HELPER.addLdapSecurityWithAdmin(LDAP_URL, MANAGER_DN, MANAGER_PASSWORD, SEARCH_BASE, SEARCH_FILTER,
            "another_admin");

    Authentication authentication = new UsernamePasswordAuthenticationToken("foleys", "some-password");
    Authentication result = ldapAuthenticationProvider.authenticate(authentication);
    assertThat(result.isAuthenticated(), is(true));

    GrantedAuthority[] authorities = result.getAuthorities();
    assertThat("foleys should have only user authority. Found: " + ArrayUtils.toString(authorities),
            authorities.length, is(1));//  w  w  w  .  ja v a 2 s. c  o m
    assertThat(authorities[0].getAuthority(), is("ROLE_USER"));
}

From source file:com.qualogy.qafe.bind.io.Reader.java

public Object read(InputStream in, List<URI> fileNames, String root, boolean recursiveScan) {

    if ((fileNames == null || fileNames.size() == 0) && in == null)
        throw new IllegalArgumentException(
                "Both fileNames array parameter and inputstream cannot be null or empty for reading the files");

    //1. filter from files list
    List<Document> documents = new ArrayList<Document>();
    if (fileNames != null && fileNames.size() > 0) {
        documents = DocumentLister.filter(documentLoader, Mapping.getRootNode(expectedResultType), documents,
                fileNames, recursiveScan, validating);
        if (documents.isEmpty())
            throw new NoFilesFoundException("No files found with content starting with element "
                    + Mapping.getRootNode(expectedResultType) + " at location(s) ["
                    + ArrayUtils.toString(fileNames)
                    + "]\nPossible reasons: No files present at location given, or files present do not meet the requirements (starting with root element ["
                    + Mapping.getRootNode(expectedResultType) + "] or having file extension [xml/qaml])");

        logger.info("The following files are found for processing [" + documents + "]");
    }/*w ww  . j a  v  a 2s.c om*/

    //2. add documents from stream
    documents = addDocumentsFromStream(documents, in);
    if (documents == null || documents.isEmpty())
        throw new NullPointerException("docs is null or empty");

    //3. add defaults
    documents = addDefaults(documents);

    //4. merge documents
    Document doc = DocumentMerger.merge(expectedResultType, documents);

    //6. nasty hack to get the root
    if (root == null && fileNames != null && fileNames.size() > 0)
        root = getApplicationRoot(fileNames.get(0));

    //7. bind and return
    return ORMBinder.bind(doc, root, expectedResultType, readInDebugMode);
}

From source file:edu.cornell.med.icb.goby.alignments.TestAlignmentReader.java

/**
 * Validate that the method//from w  w  w  .  j a va2  s .  co m
 * {@link AlignmentReaderImpl#getBasenames(String[])}
 * produces the proper results.
 */
@Test
public void basenames() {
    assertTrue("Basename array should be empty", ArrayUtils.isEmpty(AlignmentReaderImpl.getBasenames()));

    final String[] nullArray = { null };
    assertArrayEquals("Basename array should contain a single null element", nullArray,
            AlignmentReaderImpl.getBasenames((String) null));

    final String[] emptyStringArray = { "" };
    assertArrayEquals("Basename array should contain a single empty string element", emptyStringArray,
            AlignmentReaderImpl.getBasenames(""));

    final String[] foobarArray = { "foobar" };
    assertArrayEquals("Basenames should be unchanged", foobarArray, AlignmentReaderImpl.getBasenames("foobar"));

    final String[] foobarTxtArray = { "foobar.txt" };
    assertArrayEquals("Basenames should be unchanged", foobarTxtArray,
            AlignmentReaderImpl.getBasenames("foobar.txt"));

    assertArrayEquals("Basenames should be unchanged", ArrayUtils.addAll(foobarArray, foobarTxtArray),
            AlignmentReaderImpl.getBasenames("foobar", "foobar.txt"));

    final String basename = "mybasename";
    final String[] basenameArray = { basename };
    final String[] filenames = new String[FileExtensionHelper.COMPACT_ALIGNMENT_FILE_EXTS.length];
    for (int i = 0; i < FileExtensionHelper.COMPACT_ALIGNMENT_FILE_EXTS.length; i++) {
        filenames[i] = basename + FileExtensionHelper.COMPACT_ALIGNMENT_FILE_EXTS[i];

    }
    assertArrayEquals("Basename not stripped properly from " + ArrayUtils.toString(filenames), basenameArray,
            AlignmentReaderImpl.getBasenames(filenames));
}

From source file:edu.cornell.med.icb.learning.tools.svmlight.EvaluationMeasure.java

public double getPerformanceValueAverage(final String measureName) {
    double sum = 0;
    final DoubleList values = name2Values.get(measureName.intern());
    if (values == null) {

        return Double.NaN;
    }//from w w  w .  j  a  v a2 s.co m
    for (final double value : values) {
        sum += value;
    }

    final double value = sum / values.size();
    if (LOG.isTraceEnabled()) {
        LOG.trace(String.format(
                "returning average value %f for measure %s, " + "averaged over %d distinct values: %s.", value,
                measureName, values.size(), ArrayUtils.toString(values)));

    }

    return value;

}

From source file:edu.cornell.med.icb.clustering.MCLClusterer.java

/**
 * Groups instances into clusters. Returns the indices of the instances that belong to a cluster
 * as an int array in the list result.//from  w ww  .  j a  va  2s.co  m
 *
 * @param calculator The {@link SimilarityDistanceCalculator}
 * that should be used when clustering
 * @param qualityThreshold The QT clustering algorithm quality threshold (d)
 * @return The list of clusters.
 */
public List<int[]> cluster(final SimilarityDistanceCalculator calculator, final double qualityThreshold) {
    if (mclCommand == null) {
        throw new IllegalStateException("mcl command not set!");
    }

    // reset cluster results
    clusterCount = 0;
    for (int i = 0; i < instanceCount; i++) {
        clusters[i].clear();
    }

    BufferedReader br = null;
    try {
        final File mclInputFile = File.createTempFile("mcl-input", ".txt");
        writeMCLInputFile(mclInputFile, calculator, qualityThreshold);

        final File mclOutputFile = File.createTempFile("mcl-output", ".txt");
        final String[] command = { mclCommand, mclInputFile.getAbsolutePath(), "--abc", "-o",
                mclOutputFile.getAbsolutePath() };

        LOGGER.info("Executing: " + ArrayUtils.toString(command));

        final ProcessBuilder builder = new ProcessBuilder(command);
        builder.redirectErrorStream(true);
        final Process process = builder.start();
        final InputStream is = process.getInputStream();
        final InputStreamReader isr = new InputStreamReader(is);
        br = new BufferedReader(isr);
        String line;
        while ((line = br.readLine()) != null) {
            LOGGER.info(line);
        }
        process.waitFor();

        LOGGER.info("Program terminated!");

        readMCLOutputFile(mclOutputFile);
    } catch (IOException e) {
        LOGGER.error("Counldn't create MCL file", e);
        throw new ClusteringException("Counldn't create MCL file", e);
    } catch (InterruptedException e) {
        LOGGER.error("Interrupted!", e);
        Thread.currentThread().interrupt();
    } finally {
        IOUtils.closeQuietly(br);
    }

    return getClusters();
}

From source file:com.asakusafw.cleaner.log.LogMessageManager.java

/**
 * ???/*from  w  w w .  j av  a 2 s .c  om*/
 *
 * @param messageArgs 
 * @return ??
 */
private Object[] toStringMessageArgs(Object[] messageArgs) {
    if (messageArgs == null) {
        return messageArgs;
    }
    Object[] messageArgsConverted = new Object[messageArgs.length];
    for (int i = 0; i < messageArgs.length; i++) {
        Object obj = messageArgs[i];
        if (obj == null) {
            messageArgsConverted[i] = null;
        } else if (obj.getClass().isArray()) {
            messageArgsConverted[i] = ArrayUtils.toString(obj);
        } else if (obj instanceof Long || obj instanceof Integer || obj instanceof BigDecimal) {
            messageArgsConverted[i] = ObjectUtils.toString(obj, "null");
        } else {
            messageArgsConverted[i] = messageArgs[i];
        }
    }
    return messageArgsConverted;
}

From source file:net.sf.firemox.tools.MToolKit.java

/**
 * read a string from inputStream ending with \0. The maximum size of this
 * string is 200 chars.//w  w  w .  j  av a 2  s. co  m
 * 
 * @param inputStream
 *          is the input stream
 * @return the read string
 * @throws IOException
 *           If some other I/O error occurs
 */
public synchronized static String readString(InputStream inputStream) throws IOException {
    int count = 0;
    try {
        while ((mBuffer[count] = (byte) inputStream.read()) != 0) {
            count++;
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        throw new IOException("The given data exceed the expected size '" + mBuffer.length
                + "' reading string '" + new String(mBuffer, 0, count, CHARSET) + "'\n\tdump : '"
                + ArrayUtils.toString(mBuffer));
    } catch (Exception e) {
        throw new IOException("Exception '" + e + "' reading string '" + new String(mBuffer, 0, count, CHARSET)
                + "'\n\tdump : '" + ArrayUtils.toString(mBuffer));
    }

    // Return the text from the stream against a specific charset.
    return new String(mBuffer, 0, count, CHARSET);
}