Example usage for org.apache.commons.io IOUtils LINE_SEPARATOR

List of usage examples for org.apache.commons.io IOUtils LINE_SEPARATOR

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils LINE_SEPARATOR.

Prototype

String LINE_SEPARATOR

To view the source code for org.apache.commons.io IOUtils LINE_SEPARATOR.

Click Source Link

Document

The system line separator string.

Usage

From source file:com.perceptive.epm.perkolcentral.action.ImageNowLicenseAction.java

public String executeImageNowLicenseRequest() throws ExceptionWrapper {
    try {/*  w  w  w .  j a  v  a2  s .co  m*/
        rallyGroups = groupsBL.getAllRallyGroups();
        getSpecificGroupsThatRequireINLicense();
        //Check whether this person is part of perceptive kolkata
        if (ActionContext.getContext().getSession().get(Constants.logged_in_user) == null) {
            errorMessage = errorMessage
                    + "* You have to be a part of Perceptive Kolkata Group to request for ImageNow Development License."
                    + IOUtils.LINE_SEPARATOR;
            return ERROR;
        }
        if (!FilenameUtils.getExtension(sysfpFileFileName).equalsIgnoreCase("sysfp")) {
            errorMessage = errorMessage + "* Please upload a file of type sysfp." + IOUtils.LINE_SEPARATOR;
            return ERROR;
        }
        if (FileUtils.sizeOf(sysfpFile) > FileUtils.ONE_MB * 2) {
            errorMessage = errorMessage + "* Please upload a file of size less than 2 MB."
                    + IOUtils.LINE_SEPARATOR;
            return ERROR;
        }

        String employeeUID = ((EmployeeBO) ActionContext.getContext().getSession()
                .get(Constants.logged_in_user)).getEmployeeUid();
        //Get the logged in userId
        //rallyGroups = groupsBL.getAllRallyGroups();
        //getSpecificGroupsThatRequireINLicense();

        imagenowlicenses.setImageNowLicenseRequestId(UUID.randomUUID().toString());
        imagenowlicenses.setLicenseRequestedOn(Calendar.getInstance().getTime());
        imagenowlicenses.setFileName(sysfpFileFileName);

        imageNowLicenseBL.addImageNowLicenseRequest(imagenowlicenses, groupRequestedFor, employeeUID, sysfpFile,
                sysfpFileFileName);
        imagenowlicensesArrayList = imageNowLicenseBL.getLicensesRequestedByMe(employeeUID);

    } catch (Exception ex) {
        throw new ExceptionWrapper(ex);
    }
    return SUCCESS;
}

From source file:de.awtools.config.AbstractGlueConfig.java

public String debugOutput() {
    StringBuilder sb = new StringBuilder();
    for (Iterator<String> i = getKeyIterator(); i.hasNext();) {
        String key = i.next();/*from  w ww . j ava  2  s  .c  o  m*/
        Object value = getProperty(key);
        sb.append(key).append(" = ").append(value).append(IOUtils.LINE_SEPARATOR);
    }
    return sb.toString();
}

From source file:net.mikaboshi.intra_mart.tools.log_stats.parser.ExceptionLogParserV7Test.java

    () throws ParseException {

   String logText = StringUtils.join(new String[] {
            "log.generating.time=Sun Nov 13 15:55:39 KST 2011",
            "log.level=ERROR",
            "log.logger.name=jp.co.intra_mart.system.javascript.imapi.ResinDataSourceConfiguraterObject",
            "log.id=5i0slu795nope",
            "log.thread.id=http-APP:localhost:8088-8088-0$312771783",
            "log.thread.group=main",
            "log.message=1",
            "2",//from   ww  w  .  j av  a 2s  . com
            "3",
            "",
            "jp.co.intra_mart.foundation.database.exception.DataSourceConfigurationException: 1",
            "2",
            "3",
            "\tat jp.co.intra_mart.foundation.database.ResinDataSourceConfigurater.bind(ResinDataSourceConfigurater.java:111)",
            "\tat jp.co.intra_mart.system.javascript.imapi.ResinDataSourceConfiguraterObject.jsFunction_bind(ResinDataSourceConfiguraterObject.java:152)"
         }, IOUtils.LINE_SEPARATOR);

   ExceptionLogParser exceptionLogParser = new ExceptionLogParserV7(new ParserParameter());

   ExceptionLog log = exceptionLogParser.parse(logText);

   assertEquals(
         new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.ENGLISH).parse("Sun Nov 13 15:55:39 KST 2011"),
         log.date);

   assertEquals(Level.ERROR, log.level);
   assertEquals("jp.co.intra_mart.system.javascript.imapi.ResinDataSourceConfiguraterObject", log.logger);
   assertEquals("5i0slu795nope", log.logId);
   assertEquals("http-APP:localhost:8088-8088-0$312771783", log.thread);
   assertEquals("main", log.logThreadGroup);
   assertEquals("1" + IOUtils.LINE_SEPARATOR + "2" + IOUtils.LINE_SEPARATOR + "3", log.message);
   assertEquals("jp.co.intra_mart.foundation.database.exception.DataSourceConfigurationException: 1", log.getFirstLineOfStackTrace());
}

From source file:com.ss.language.model.gibblda.Dictionary.java

/**
 * ??//w ww .j ava  2  s . c o m
 * 
 * @param wordMapFile
 * @return
 */
public boolean writeWordMap(String wordMapFile) {
    try {
        BufferedWriter writer = new BufferedWriter(
                new OutputStreamWriter(new FileOutputStream(wordMapFile), "UTF-8"));
        // write number of words
        writer.write(wordSize() + IOUtils.LINE_SEPARATOR);
        // write word to id
        BufferedReader br = new BufferedReader(new FileReader(getWordIdsFile()));
        for (String key = br.readLine(); key != null; key = br.readLine()) {
            key = LDADataset.removeBomIfNessecery(key);
            String value = LuceneDataAccess.findValueByKey(dicName + key);
            writer.write(key + " " + value + IOUtils.LINE_SEPARATOR);
        }
        writer.close();
        br.close();
        return true;
    } catch (Exception e) {
        System.out.println("Error while writing word map " + e.getMessage());
        e.printStackTrace();
        return false;
    }

}

From source file:com.theminequest.MineQuest.SQLExecutor.java

/**
 * Check for initialization. What this does is take the build number
 * and uses a fast forward mechanism from the previous build to see
 * if any changes should be merged.<br>
 * It acts similarly to SVN.//from w ww  .  jav  a  2  s.c o m
 */
private void checkInitialization() {
    if (!datafolder.exists()) {
        datafolder.mkdir();
    }
    File versionfile = new File(datafolder + File.separator + "version");
    Scanner s = null;
    String lastv = null;
    try {
        s = new Scanner(versionfile);
        if (s.hasNextLine()) {
            String dbtype = s.nextLine();
            if (dbtype.equalsIgnoreCase(databasetype.name())) {
                if (s.hasNextLine())
                    lastv = s.nextLine();
            }
        }
    } catch (FileNotFoundException e) {
        try {
            versionfile.createNewFile();
        } catch (IOException e1) {
            throw new RuntimeException(e1);
        }
    }
    if (lastv == null || lastv.compareTo(MineQuest.getVersion()) != 0) {
        if (lastv == null || lastv.equals("unofficialDev")) {
            if (lastv == null)
                MineQuest.log(Level.WARNING, "[SQL] No existing DBVERSION file; initializing DB as new.");
            else
                MineQuest.log(Level.WARNING,
                        "[SQL] I don't know what your previous build was; attempting to reinitialize.");
            lastv = "initial";
        }

        if (lastv != null && !lastv.equals("unofficialDev") && !lastv.equals("initial")) {
            int last = Integer.parseInt(lastv);
            MineQuest.log(Level.INFO, "[SQL] Fast forwarding through builds...");
            while (last < Integer.parseInt(MineQuest.getVersion())) {
                try {
                    MineQuest.log("[SQL] Fast forwarding from build " + last + " to " + (last + 1) + "...");
                    querySQL("update/" + last, "");
                    MineQuest.log("[SQL] Applied patch for build " + last + " to " + (last + 1) + "!");
                } catch (NoSuchElementException e) {
                    //MineQuest.log(Level.WARNING,"[SQL] No update path from build " + last + " to " + (last+1) + " build; Probably normal.");
                }
                last++;
            }
        } else {
            try {
                querySQL("update/" + lastv, "");
            } catch (NoSuchElementException e) {
                MineQuest.log(Level.WARNING,
                        "[SQL] No update path from build " + lastv + " to this build; Probably normal.");
            }
        }

        Writer out;
        try {
            out = new OutputStreamWriter(new FileOutputStream(versionfile));
            out.write(databasetype.name() + IOUtils.LINE_SEPARATOR + MineQuest.getVersion());
            out.close();
        } catch (FileNotFoundException e) {
            MineQuest.log(Level.SEVERE, "[SQL] Failed to commit DBVERSION: " + e.getMessage());
            throw new RuntimeException(e);
        } catch (IOException e) {
            MineQuest.log(Level.SEVERE, "[SQL] Failed to commit DBVERSION: " + e.getMessage());
            throw new RuntimeException(e);
        }
    }

}

From source file:de.awtools.config.PropertyHolder.java

/**
 * Schreibt Debug-Informationen./*from  w  w  w  . j av  a  2s . c  o m*/
 *
 * @param configName Der Name der Konfiguration.
 * @param config Eine Konfiguration.
 */
private void writeDebugInfos(final String configName, final GlueConfig config) {

    StringBuilder sb = new StringBuilder(configName);
    sb.append(IOUtils.LINE_SEPARATOR).append(config.debugOutput());
    log.debug(sb.toString());
}

From source file:com.googlecode.fascinator.portal.process.EmailNotifier.java

public String getCollectionValues(JsonSimple emailConfig, JsonSimple tfPackage, String varField) {
    String formattedCollectionValues = "";
    JSONArray subKeys = emailConfig.getArray("collections", varField, "subKeys");
    String tfPackageField = emailConfig.getString("", "collections", varField, "payloadKey");
    if (StringUtils.isNotBlank(tfPackageField) && subKeys instanceof JSONArray) {
        List<JsonObject> jsonList = new StorageDataUtil().getJavaList(tfPackage, tfPackageField);
        log.debug("Collating collection values for email template...");
        JSONArray fieldSeparators = emailConfig.getArray("collections", varField, "fieldSeparators");
        String recordSeparator = emailConfig.getString(IOUtils.LINE_SEPARATOR, "collections", varField,
                "recordSeparator");
        String nextDelimiter = " ";

        for (JsonObject collectionRow : jsonList) {
            if (fieldSeparators instanceof JSONArray && fieldSeparators.size() > 0) {
                // if no more delimiters, continue to use the last one specified
                Object nextFieldSeparator = fieldSeparators.remove(0);
                if (nextFieldSeparator instanceof String) {
                    nextDelimiter = (String) nextFieldSeparator;
                } else {
                    log.warn("Unable to retrieve String value from fieldSeparator: "
                            + fieldSeparators.toString());
                }//from   w  w  w .java2  s  .c  om
            }
            List<String> collectionValuesList = new ArrayList<String>();
            for (Object requiredKey : subKeys) {
                Object rawKeyValue = collectionRow.get(requiredKey);
                if (rawKeyValue instanceof String) {
                    String keyValue = StringUtils.trim((String) rawKeyValue);
                    if (StringUtils.isNotBlank(keyValue)) {
                        collectionValuesList.add(keyValue);
                    } else if (!isVariableNameHiddenIfEmpty) {
                        collectionValuesList.add("$" + requiredKey);
                    } else {
                        log.info("blank variable name will be hidden: " + keyValue);
                    }
                } else {
                    log.warn("No string value returned from: " + requiredKey);
                }
            }
            formattedCollectionValues += StringUtils.join(collectionValuesList, nextDelimiter)
                    + recordSeparator;
        }
        formattedCollectionValues = StringUtils.chomp(formattedCollectionValues, recordSeparator);
        log.debug("email formatted collection values: " + formattedCollectionValues);
    }
    return formattedCollectionValues;
}

From source file:com.ss.language.model.gibblda.LDADataset.java

private static void readFromDatabase(int total, LDADataset data) throws IOException {
    // ?id/*from  w  w  w .  j  av a  2s . co m*/
    File docIdxFile = new File(LDACmdOption.curOption.get().dir, LDACmdOption.curOption.get().docIdFile);
    if (docIdxFile.isFile()) {
        FileUtils.forceDelete(docIdxFile);
    }
    if (!docIdxFile.getParentFile().isDirectory()) {
        FileUtils.forceMkdir(docIdxFile.getParentFile());
    }
    docIdxFile.createNewFile();
    BufferedWriter br = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(docIdxFile),
            LDACmdOption.curOption.get().fileEncoding));
    int perPage = 100;
    int totalPage = (total / perPage) + (total % perPage == 0 ? 0 : 1);
    int index = -1;
    for (int curPage = 0; curPage < totalPage; ++curPage) {
        // ?
        String titleSql = "select document_title,document_content from " + tableName
                + " order by rec_id asc limit " + (curPage * perPage) + "," + perPage;
        List<Map<String, Object>> result = DatabaseConfig.query(titleSql);
        if (result == null || result.isEmpty()) {
            break;
        }
        for (Map<String, Object> record : result) {
            String title = (String) record.get("document_title");
            String content = (String) record.get("document_content");
            if (content == null || content.trim().isEmpty()) {
                continue;
            }
            ++index;
            System.out.println("??" + (curPage + 1) + "" + (index + 1)
                    + "?/" + total + "?");
            data.setDoc(content, index);
            br.write(title + IOUtils.LINE_SEPARATOR);
        }
    }
    br.flush();
    br.close();
}

From source file:com.theminequest.MineQuest.SQLExecutor.java

/**
 * Query an SQL and return a {@link java.sql.ResultSet} of the result.
 * If the SQL file contains {@code %s} in the query, the parameters
 * specified will replace {@code %s} in the query. Remember that if the query
 * is not a {@code SELECT, EXPLAIN, CALL, SCRIPT, SHOW, HELP} query, this will ALWAYS return null.<br>
 * In the event that the queries are different per database, prefix
 * <code>S:</code> at the beginning of the query followed by the database type and another
 * colon./*  ww  w . j av  a 2  s  . c  o m*/
 * @param queryfilename sql filename to use
 * @param params parameters for sql file
 * @return ResultSet of SQL query (or null... if there really is nothing good.)
 */
public ResultSet querySQL(String queryfilename, String... params) {
    InputStream i = MineQuest.activePlugin.getResource("sql/" + queryfilename + ".sql");
    if (i == null)
        throw new NoSuchElementException("No such resource: " + queryfilename + ".sql");
    String[] filecontents = convertStreamToString(i).split(IOUtils.LINE_SEPARATOR);
    for (String line : filecontents) {
        // ignore comments
        if (!line.startsWith("#") && !line.equals("")) {
            if (line.startsWith("S:")) {
                String[] split = line.split(":");
                if (split[1].equalsIgnoreCase(databasetype.name()))
                    line = split[2];
                else
                    continue;
            }
            if (params != null && params.length != 0) {
                int paramsposition = 0;
                while (paramsposition < params.length && line.contains("%s")) {
                    line = line.replaceFirst("%s", params[paramsposition]);
                    paramsposition++;
                }
            }
            ResultSet result = db.query(line);
            if (result != null)
                return result;
        }
    }
    return null;
}

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

/**
 * Writes instance pairs that are within the distance threshold to a file
 * in the proper format for mcl to read.
 *
 * @param file The file to write the instances to be clustered
 * @param calculator The {@link SimilarityDistanceCalculator}
 * that should be used when clustering/*from   w w w .ja  v a 2  s . c om*/
 * @param qualityThreshold The QT clustering algorithm quality threshold (d)
 * @throws java.io.IOException if the file cannot be written to
 */
private void writeMCLInputFile(final File file, final SimilarityDistanceCalculator calculator,
        final double qualityThreshold) throws IOException {
    LOGGER.debug("Writing mcl file to: " + file.getName());
    PrintWriter writer = null;
    try {
        writer = new PrintWriter(file);
        for (int i = 0; i < instanceCount; i++) {
            // note that we don't need to start from 0 here otherwise there will be duplicates
            for (int j = i; j < instanceCount; j++) {
                final double distance = calculator.distance(i, j);
                // if the distance is within the threshold, add this pair
                // we also want to explicitly include each instance with itself
                if (distance <= qualityThreshold || i == j) {
                    writer.printf("%d\t%d\t%f" + IOUtils.LINE_SEPARATOR, i, j, 1.0);
                }
            }
        }
    } finally {
        IOUtils.closeQuietly(writer);
    }
}