Example usage for org.apache.commons.lang SystemUtils LINE_SEPARATOR

List of usage examples for org.apache.commons.lang SystemUtils LINE_SEPARATOR

Introduction

In this page you can find the example usage for org.apache.commons.lang SystemUtils LINE_SEPARATOR.

Prototype

String LINE_SEPARATOR

To view the source code for org.apache.commons.lang SystemUtils LINE_SEPARATOR.

Click Source Link

Document

The line.separator System Property.

Usage

From source file:com.dc.tes.License.java

private static String Lisence(Core core, String license) {
    // ??//ww w  .  jav a  2s  . c  o  m
    boolean[] adapterFlag = new boolean[C_ADAPTER_LIST_SIZE];
    // ?
    Date[] adapterDate = new Date[C_ADAPTER_LIST_SIZE];
    // 
    Date tesDate;
    // ??
    int adapterNum;

    try {
        // ?License
        //String license = RuntimeUtils.ReadResource("license.dat", RuntimeUtils.utf8);
        byte[] _enData = new BASE64Decoder().decodeBuffer(license);

        byte[] _buffer = new byte[_enData.length - 8];
        System.arraycopy(_enData, 0, _buffer, 0, _enData.length - 8);

        license = new String(decrypt(_buffer, "nuclearg".getBytes()));

        String[] segments = StringUtils.split(license, "\r");
        for (int i = 0; i < C_ADAPTER_LIST_SIZE; i++)
            adapterFlag[i] = segments[0].charAt(i) == '1';

        String[] _adapterDate = segments[1].split("\\|");
        for (int i = 0; i < C_ADAPTER_LIST_SIZE; i++)
            if (adapterFlag[i])
                adapterDate[i] = _adapterDate[i + 1].equals("00000000") ? null
                        : new SimpleDateFormat("yyyyMMdd").parse(_adapterDate[i + 1]);

        tesDate = segments[2].equals("00000000") ? null : new SimpleDateFormat("yyyyMMdd").parse(segments[2]);

        adapterNum = Integer.parseInt(segments[3]);
    } catch (Exception ex) {
        throw new LicenseException("?License", ex);
    }

    if (tesDate != null && new Date().after(tesDate))
        throw new LicenseException("");

    int count = 0;
    StringBuffer buffer = new StringBuffer();

    List<String> disabledChannelNames = new ArrayList<String>();
    for (String name : core.channels.getChannelNames())
        if (core.channels.getChannel(name) instanceof IAdapterChannel) {
            count++;
            Class<? extends IChannel> cls = core.channels.getChannel(name).getClass();

            String pName = core.channels.getChannel(name).getClass().getPackage().getName();
            pName = pName.substring(pName.lastIndexOf('.') + 1);
            int id = pName.hashCode() & 0x7fffffff % 64;
            if (ArrayUtils.contains(cls.getInterfaces(), IListenerChannel.class))
                id += 64;

            if (!adapterFlag[id] || (adapterDate[id] != null && new Date().after(adapterDate[id])))
                disabledChannelNames.add(name);
        }

    if (adapterNum > 0 && count > adapterNum)
        throw new LicenseException("??license?");

    for (String disabledChannel : disabledChannelNames) {
        buffer.append("License?" + disabledChannel + "??")
                .append(SystemUtils.LINE_SEPARATOR);
        core.channels.getChannelNames().remove(disabledChannel);
    }

    return buffer.toString();
}

From source file:au.com.dw.testing.AssertUtil.java

/**
 * Version of assertEqualsAny() for comparing strings with the new line formatting
 * removed.//from   w  ww.  j  a  v a  2  s  .  c o m
 * 
 * This should make the comparison of generated logs more robust since don't have to
 * worry about changes in new line formatting.
 * 
 * @param expected
 * @param actual
 */
public static void assertEqualsAnyWithoutFormatting(String message, Collection<String> expected,
        String actual) {
    Collection<String> expectedWithoutFormatting = new ArrayList<String>();
    String actualWithoutFormatting = null;

    if (expected != null) {
        for (String expectedElement : expected) {
            expectedWithoutFormatting.add(expectedElement.replaceAll(SystemUtils.LINE_SEPARATOR, ""));
        }
    }
    if (actual != null) {
        actualWithoutFormatting = actual.replaceAll(SystemUtils.LINE_SEPARATOR, "");
    }
    assertEqualsAny(message, expectedWithoutFormatting, actualWithoutFormatting);
}

From source file:io.mycat.server.packet.util.CharsetUtil.java

/**
 * <pre>//from w  w  w .  j a v a  2s  . c o m
 * ? dataHosts mysqld? charset  collation 
 * mysql> SELECT ID,CHARACTER_SET_NAME,COLLATION_NAME,IS_DEFAULT FROM INFORMATION_SCHEMA.COLLATIONS;
* +-----+--------------------+--------------------------+------------+
* | ID  | CHARACTER_SET_NAME | COLLATION_NAME           | IS_DEFAULT |
* +-----+--------------------+--------------------------+------------+
* |   1 | big5               | big5_chinese_ci          | Yes        |
* |  84 | big5               | big5_bin                 |            |
* |   3 | dec8               | dec8_swedish_ci          | Yes        |
* |  69 | dec8               | dec8_bin                 |            |
*</pre>
 */
private static void initCharsetAndCollation(Map<String, PhysicalDBPool> dataHosts) {
    if (COLLATION_TO_CHARSETCOLLATION.size() > 0) { // ??
        logger.debug(" charset and collation has already init ...");
        return;
    }

    // mycat.xml?  heartbeat(?)??CharsetCollation??????
    // ???mycat.xml? dataHost?CharsetCollation;
    DBHostConfig dBHostconfig = getConfigByDataHostName(dataHosts, "jdbchost");
    if (dBHostconfig != null) {
        if (getCharsetCollationFromMysql(dBHostconfig)) {
            logger.debug(" init charset and collation success...");
            return;
        }
    }

    // ?? ? mycat.xml  dataHost ??mysqld? charset  collation ?
    for (String key : dataHosts.keySet()) {
        PhysicalDBPool pool = dataHosts.get(key);
        if (pool != null && pool.getSource() != null) {
            PhysicalDatasource ds = pool.getSource();
            if (ds != null && ds.getConfig() != null && "mysql".equalsIgnoreCase(ds.getConfig().getDbType())) {
                DBHostConfig config = ds.getConfig();
                if (getCharsetCollationFromMysql(config)) {
                    logger.debug(" init charset and collation success...");
                    return; // ? for 
                }
            }
        }
    }
    logger.error(" init charset and collation from mysqld failed, please check datahost in mycat.xml."
            + SystemUtils.LINE_SEPARATOR
            + " if your backend database is not mysqld, please ignore this message.");

    // Mycat-server?mycat.xml?mysqld????sqlserveroracle
    // mysqld?????
    // ???mysqld???
    getCharsetInfoFromFile();
    logger.info(" backend database is not mysqld, read charset info from file.");
}

From source file:au.com.dw.testdatacapturej.reflection.TestGenNullTest.java

/**
 * Test for Array field with null elements.
 *//*  w  ww.  j  a  va2  s .c o  m*/
@Test
public void nullArrayElementTest() {
    try {
        logger.logObject(builder, handler.handle(new NullArrayElementHolder()));
        String result = builder.getLog();

        String expected = SystemUtils.LINE_SEPARATOR
                + "au.com.dw.testdatacapturej.mock.dataholder.NullArrayElementHolder nullArrayElementHolder0 = new au.com.dw.testdatacapturej.mock.dataholder.NullArrayElementHolder();"
                + SystemUtils.LINE_SEPARATOR + SystemUtils.LINE_SEPARATOR
                + "java.lang.Object[] objectArray0 = new java.lang.Object[2];" + SystemUtils.LINE_SEPARATOR
                + "objectArray0[0] = null;" + SystemUtils.LINE_SEPARATOR + "objectArray0[1] = null;"
                + SystemUtils.LINE_SEPARATOR + SystemUtils.LINE_SEPARATOR
                + "nullArrayElementHolder0.setNullField(objectArray0);" + SystemUtils.LINE_SEPARATOR;

        System.out.println(result);
        assertEquals(expected, result);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}

From source file:mitm.common.security.crl.CRLStoreUpdaterImpl.java

private void addURIsFromExtension(X509Extension extension, Set<URI> uris)
        throws NoSuchProviderException, CRLException {
    try {/* www .ja  v a  2  s  . c om*/
        CRLDistPoint crlDistPoint = X509ExtensionInspector.getCRLDistibutionPoints(extension);

        addURIsFromCRLDistPoint(extension, crlDistPoint, uris);
    } catch (IOException e) {
        logger.error("Error getting CRL Distibution Points for:" + SystemUtils.LINE_SEPARATOR + extension, e);
    }

    try {
        CRLDistPoint crlDistPoint = X509ExtensionInspector.getFreshestCRL(extension);

        addURIsFromCRLDistPoint(extension, crlDistPoint, uris);
    } catch (IOException e) {
        logger.error(
                "Error getting Freshest CRL distibution Points for:" + SystemUtils.LINE_SEPARATOR + extension,
                e);
    }
}

From source file:de.tudarmstadt.ukp.csniper.webapp.evaluation.MlPipeline.java

public void classify(File aModelDir, List<EvaluationResult> aToPredictList) throws IOException, UIMAException {
    TKSVMlightSequenceClassifierBuilder builder = new TKSVMlightSequenceClassifierBuilder();
    TKSVMlightSequenceClassifier classifier = builder.loadClassifierFromTrainingDirectory(aModelDir);
    File cFile = File.createTempFile("tkclassify", ".txt");

    BufferedWriter bw = null;/*from  w  w w  .  j a va  2  s. c  o m*/
    try {
        bw = new BufferedWriter(new FileWriter(cFile));

        // predict unclassified
        CAS cas = CasCreationUtils.createCas(createTypeSystemDescription(), null, null);
        ProgressMeter progress = new ProgressMeter(aToPredictList.size());
        for (EvaluationResult result : aToPredictList) {
            cas.setDocumentText(result.getItem().getCoveredText());
            cas.setDocumentLanguage(language);

            // dummy sentence split
            sent.process(cas);

            // tokenize
            tok.process(cas);

            // get parse from db, or parse now
            String pennTree = parse(result, cas);

            // write tree to file
            Feature tree = new Feature("TK_tree", StringUtils.normalizeSpace(pennTree));
            TreeFeatureVector tfv = classifier.getFeaturesEncoder().encodeAll(Arrays.asList(tree));
            try {
                bw.write("0");
                bw.write(TKSVMlightDataWriter.createString(tfv));
                bw.write(SystemUtils.LINE_SEPARATOR);
            } catch (IOException e) {
                throw new AnalysisEngineProcessException(e);
            }
            cas.reset();
            progress.next();
            LOG.info(progress);
            if (task != null) {
                task.increment();
                task.checkCanceled();
            }
        }
    } finally {
        IOUtils.closeQuietly(bw);
    }

    // classify all
    List<Double> predictions = classifier.tkSvmLightPredict2(cFile);

    if (predictions.size() != aToPredictList.size()) {
        // TODO throw different exception instead
        throw new IOException("there are [" + predictions.size() + "] predictions, but ["
                + aToPredictList.size() + "] were expected.");
    }

    for (int i = 0; i < aToPredictList.size(); i++) {
        Mark m = (predictions.get(i) > THRESHOLD) ? Mark.PRED_CORRECT : Mark.PRED_WRONG;
        aToPredictList.get(i).setResult(m.getTitle());
    }
}

From source file:au.com.dw.testdatacapturej.reflection.TestGenNullTest.java

/**
 * Test for Map field with null elements in the key and/or value.
 *//*from  ww w.  j av a  2 s  .  c  om*/
@Test
public void nullMapEntryTest() {
    try {
        logger.logObject(builder, handler.handle(new NullMapEntryHolder()));
        String result = builder.getLog();

        String expected = SystemUtils.LINE_SEPARATOR
                + "au.com.dw.testdatacapturej.mock.dataholder.NullMapEntryHolder nullMapEntryHolder0 = new au.com.dw.testdatacapturej.mock.dataholder.NullMapEntryHolder();"
                + SystemUtils.LINE_SEPARATOR + SystemUtils.LINE_SEPARATOR
                + "java.util.HashMap hashMap0 = new java.util.HashMap();" + SystemUtils.LINE_SEPARATOR
                + "hashMap0.put(null, \"value\");" + SystemUtils.LINE_SEPARATOR + "hashMap0.put(\"key\", null);"
                + SystemUtils.LINE_SEPARATOR + SystemUtils.LINE_SEPARATOR
                + "nullMapEntryHolder0.setNullField(hashMap0);" + SystemUtils.LINE_SEPARATOR
                + SystemUtils.LINE_SEPARATOR + "java.util.HashMap hashMap1 = new java.util.HashMap();"
                + SystemUtils.LINE_SEPARATOR + "hashMap1.put(null, null);" + SystemUtils.LINE_SEPARATOR
                + SystemUtils.LINE_SEPARATOR + "nullMapEntryHolder0.setImplNullField(hashMap1);"
                + SystemUtils.LINE_SEPARATOR;

        System.out.println(result);
        assertEquals(expected, result);
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}

From source file:au.com.dw.testdatacapturej.reflection.TestGenFieldTest.java

@Test
public void testObjectHolder() {
    FieldObjectHolder holder = new FieldObjectHolder();
    holder.setByteField(createByteObject());
    holder.setIntField(createInteger());
    holder.setLongField(createLongObject());
    holder.setFloatField(createFloatObject());
    holder.setDoubleField(createDoubleObject());
    holder.setCharField(createCharacter());
    holder.setBooleanField(createBooleanObject());
    holder.setStringField(createString());

    try {/*from  www.ja  v  a 2s. c  om*/
        logger.logObject(builder, handler.handle(holder));
        String result = builder.getLog();

        String expected = SystemUtils.LINE_SEPARATOR
                + "au.com.dw.testdatacapturej.mock.dataholder.FieldObjectHolder fieldObjectHolder0 = new au.com.dw.testdatacapturej.mock.dataholder.FieldObjectHolder();"
                + SystemUtils.LINE_SEPARATOR + "fieldObjectHolder0.setByteField(5);"
                + SystemUtils.LINE_SEPARATOR + "fieldObjectHolder0.setIntField(6);" + SystemUtils.LINE_SEPARATOR
                + "fieldObjectHolder0.setLongField(7L);" + SystemUtils.LINE_SEPARATOR
                + "fieldObjectHolder0.setFloatField(50.1f);" + SystemUtils.LINE_SEPARATOR
                + "fieldObjectHolder0.setDoubleField(60.1d);" + SystemUtils.LINE_SEPARATOR
                + "fieldObjectHolder0.setCharField('b');" + SystemUtils.LINE_SEPARATOR
                + "fieldObjectHolder0.setBooleanField(false);" + SystemUtils.LINE_SEPARATOR
                + "fieldObjectHolder0.setStringField(\"test\");" + SystemUtils.LINE_SEPARATOR;

        System.out.println(result);
        assertEquals(expected, result);
    } catch (Exception e) {
        e.printStackTrace();
        fail("testObjectHolder");
    }
}

From source file:de.erdesignerng.dialect.sql92.SQL92SQLGenerator.java

@Override
public StatementList createAddTableStatement(Table aTable) {
    StatementList theResult = new StatementList();
    StringBuilder theStatement = new StringBuilder();

    theStatement.append("CREATE ");
    addAdditionalInformationToPreCreateTableStatement(aTable, theStatement);

    theStatement.append("TABLE ");
    theStatement.append(createUniqueTableName(aTable));
    theStatement.append(" (");
    theStatement.append(SystemUtils.LINE_SEPARATOR);

    for (int i = 0; i < aTable.getAttributes().size(); i++) {
        Attribute<Table> theAttribute = aTable.getAttributes().get(i);

        theStatement.append(TAB);//from  w w  w .jav a2 s .c o  m
        theStatement.append(createCompleteAttributeDefinition(theAttribute));

        if (i < aTable.getAttributes().size() - 1) {
            theStatement.append(",");
        }

        theStatement.append(SystemUtils.LINE_SEPARATOR);
    }
    theStatement.append(")");
    theStatement.append(createCreateTableSuffix(aTable));
    theResult.add(new Statement(theStatement.toString()));

    for (Index theIndex : aTable.getIndexes()) {
        if (IndexType.PRIMARYKEY == theIndex.getIndexType()) {
            theResult.addAll(createAddPrimaryKeyToTable(aTable, theIndex));
        } else {
            theResult.addAll(createAddIndexToTableStatement(aTable, theIndex));
        }
    }

    return theResult;
}

From source file:ddf.content.endpoint.rest.ContentEndpoint.java

protected Response doCreate(InputStream stream, String contentType, String directive, String filename,
        String contentUri, UriInfo uriInfo) throws ContentEndpointException {
    logger.trace("ENTERING: doCreate");

    if (stream == null) {
        throw new ContentEndpointException("Cannot create content. InputStream is null.",
                Response.Status.BAD_REQUEST);
    }/*from  w w  w  .  j a  v a 2  s .c o m*/

    if (contentType == null) {
        throw new ContentEndpointException("Cannot create content. Content-Type is null.",
                Response.Status.BAD_REQUEST);
    }

    if (StringUtils.isEmpty(directive)) {
        directive = DEFAULT_DIRECTIVE;
    } else {
        // Ensure directive has no extraneous whitespace or newlines - this tends to occur
        // on the values assigned in multipart/form-data.
        // (Was seeing this when testing with Google Chrome Advanced REST Client)
        directive = directive.trim().replace(SystemUtils.LINE_SEPARATOR, "");
    }

    Request.Directive requestDirective = Request.Directive.valueOf(directive);

    String createdContentId = "";
    Response response = null;

    try {
        logger.debug("Preparing content item for contentType = " + contentType);

        ContentItem newItem = new IncomingContentItem(stream, contentType, filename); // DDF-1856
        newItem.setUri(contentUri);
        logger.debug("Creating content item.");

        CreateRequest createRequest = new CreateRequestImpl(newItem, null);
        CreateResponse createResponse = contentFramework.create(createRequest, requestDirective);
        ContentItem contentItem = createResponse.getCreatedContentItem();

        if (contentItem != null) {
            createdContentId = contentItem.getId();
        }

        Response.ResponseBuilder responseBuilder = Response.ok();

        // If content was stored in content repository, i.e., STORE or STORE_AND_PROCESS,
        // then set location URI in HTTP header. However, the location URI is not the
        // physical location in the content repository as ths is hidden from the client.
        if (requestDirective != Request.Directive.PROCESS) {
            responseBuilder.status(Response.Status.CREATED);
            // responseBuilder.location( new URI( "/" + createdContentId ) );
            UriBuilder uriBuilder = UriBuilder.fromUri(uriInfo.getBaseUri());
            uriBuilder = uriBuilder.path("/" + createdContentId);
            responseBuilder.location(uriBuilder.build());
            responseBuilder.header(CONTENT_ID_HTTP_HEADER, createdContentId);
            logger.debug("Content-URI = " + contentItem.getUri());
            responseBuilder.header(CONTENT_URI_HTTP_HEADER, contentItem.getUri());
        }

        addHttpHeaders(createResponse, responseBuilder);

        response = responseBuilder.build();
    } catch (Exception e) {
        logger.warn("Exception caught during create", e);
        Response.ResponseBuilder responseBuilder = Response.ok(e.getMessage());
        responseBuilder.status(Response.Status.BAD_REQUEST);
        response = responseBuilder.build();
    }

    logger.debug("createdContentId = [" + createdContentId + "]");

    logger.trace("EXITING: doCreate");

    return response;
}