Java Code Examples for org.apache.commons.lang3.SystemUtils#LINE_SEPARATOR
The following examples show how to use
org.apache.commons.lang3.SystemUtils#LINE_SEPARATOR .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExceptionUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * <p>Produces a <code>List</code> of stack frames - the message * is not included. Only the trace of the specified exception is * returned, any caused by trace is stripped.</p> * * <p>This works in most cases - it will only fail if the exception * message contains a line that starts with: * <code>" at".</code></p> * * @param t is any throwable * @return List of stack frames */ static List<String> getStackFrameList(Throwable t) { String stackTrace = getStackTrace(t); String linebreak = SystemUtils.LINE_SEPARATOR; StringTokenizer frames = new StringTokenizer(stackTrace, linebreak); List<String> list = new ArrayList<String>(); boolean traceStarted = false; while (frames.hasMoreTokens()) { String token = frames.nextToken(); // Determine if the line starts with <whitespace>at int at = token.indexOf("at"); if (at != -1 && token.substring(0, at).trim().length() == 0) { traceStarted = true; list.add(token); } else if (traceStarted) { break; } } return list; }
Example 2
Source File: ExceptionUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * <p>Produces a <code>List</code> of stack frames - the message * is not included. Only the trace of the specified exception is * returned, any caused by trace is stripped.</p> * * <p>This works in most cases - it will only fail if the exception * message contains a line that starts with: * <code>" at".</code></p> * * @param t is any throwable * @return List of stack frames */ static List<String> getStackFrameList(Throwable t) { String stackTrace = getStackTrace(t); String linebreak = SystemUtils.LINE_SEPARATOR; StringTokenizer frames = new StringTokenizer(stackTrace, linebreak); List<String> list = new ArrayList<String>(); boolean traceStarted = false; while (frames.hasMoreTokens()) { String token = frames.nextToken(); // Determine if the line starts with <whitespace>at int at = token.indexOf("at"); if (at != -1 && token.substring(0, at).trim().isEmpty()) { traceStarted = true; list.add(token); } else if (traceStarted) { break; } } return list; }
Example 3
Source File: ExceptionUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * <p>Produces a <code>List</code> of stack frames - the message * is not included. Only the trace of the specified exception is * returned, any caused by trace is stripped.</p> * * <p>This works in most cases - it will only fail if the exception * message contains a line that starts with: * <code>" at".</code></p> * * @param t is any throwable * @return List of stack frames */ static List<String> getStackFrameList(Throwable t) { String stackTrace = getStackTrace(t); String linebreak = SystemUtils.LINE_SEPARATOR; StringTokenizer frames = new StringTokenizer(stackTrace, linebreak); List<String> list = new ArrayList<String>(); boolean traceStarted = false; while (frames.hasMoreTokens()) { String token = frames.nextToken(); // Determine if the line starts with <whitespace>at int at = token.indexOf("at"); if (at != -1 && token.substring(0, at).trim().length() == 0) { traceStarted = true; list.add(token); } else if (traceStarted) { break; } } return list; }
Example 4
Source File: ExceptionUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * <p>Produces a <code>List</code> of stack frames - the message * is not included. Only the trace of the specified exception is * returned, any caused by trace is stripped.</p> * * <p>This works in most cases - it will only fail if the exception * message contains a line that starts with: * <code>" at".</code></p> * * @param t is any throwable * @return List of stack frames */ static List<String> getStackFrameList(final Throwable t) { final String stackTrace = getStackTrace(t); final String linebreak = SystemUtils.LINE_SEPARATOR; final StringTokenizer frames = new StringTokenizer(stackTrace, linebreak); final List<String> list = new ArrayList<String>(); boolean traceStarted = false; while (frames.hasMoreTokens()) { final String token = frames.nextToken(); // Determine if the line starts with <whitespace>at final int at = token.indexOf("at"); if (at != -1 && token.substring(0, at).trim().isEmpty()) { traceStarted = true; list.add(token); } else if (traceStarted) { break; } } return list; }
Example 5
Source File: ExceptionUtils.java From astor with GNU General Public License v2.0 | 6 votes |
/** * <p>Produces a <code>List</code> of stack frames - the message * is not included. Only the trace of the specified exception is * returned, any caused by trace is stripped.</p> * * <p>This works in most cases - it will only fail if the exception * message contains a line that starts with: * <code>" at".</code></p> * * @param t is any throwable * @return List of stack frames */ static List<String> getStackFrameList(Throwable t) { String stackTrace = getStackTrace(t); String linebreak = SystemUtils.LINE_SEPARATOR; StringTokenizer frames = new StringTokenizer(stackTrace, linebreak); List<String> list = new ArrayList<String>(); boolean traceStarted = false; while (frames.hasMoreTokens()) { String token = frames.nextToken(); // Determine if the line starts with <whitespace>at int at = token.indexOf("at"); if (at != -1 && token.substring(0, at).trim().isEmpty()) { traceStarted = true; list.add(token); } else if (traceStarted) { break; } } return list; }
Example 6
Source File: ChangelogStatementConsumer.java From morf with Apache License 2.0 | 5 votes |
/** * Writes one or more lines of text, applying line wrapping. */ private void writeWrapped(final String text) { // Handle the case of multiple lines if (text.contains(SystemUtils.LINE_SEPARATOR)) { for (String line : text.split(SystemUtils.LINE_SEPARATOR)) { writeWrapped(line); } return; } // Write anything below the wrapping limit if (text.length() < LINE_LENGTH) { outputStream.println(text); return; } // Measure the indent to use on the split lines int indent = 0; while (indent < text.length() && text.charAt(indent) == ' ') { indent++; } indent += 2; // Split the line, preserving the indent on new lines final String firstLineIndent = text.substring(0, indent); final String lineSeparator = SystemUtils.LINE_SEPARATOR + StringUtils.repeat(" ", indent); outputStream.println(firstLineIndent + WordUtils.wrap(text.substring(indent), LINE_LENGTH - indent, lineSeparator, false)); }
Example 7
Source File: ExprGetSysProp.java From skUtilities with GNU General Public License v3.0 | 5 votes |
@Override @Nullable protected String[] get(Event e) { switch (ty) { case 0: return new String[]{SystemUtils.OS_ARCH}; case 1: return new String[]{SystemUtils.OS_NAME}; case 2: return new String[]{SystemUtils.OS_VERSION}; case 3: return new String[]{SystemUtils.getJavaHome().toString()}; case 4: return new String[]{SystemUtils.getUserDir().toString()}; case 5: return new String[]{SystemUtils.getUserHome().toString()}; case 6: return new String[]{SystemUtils.USER_NAME}; case 7: return new String[]{SystemUtils.USER_LANGUAGE}; case 8: return new String[]{SystemUtils.USER_TIMEZONE}; case 9: return new String[]{SystemUtils.LINE_SEPARATOR}; case 10: return new String[]{SystemUtils.FILE_SEPARATOR}; case 11: return new String[]{SystemUtils.PATH_SEPARATOR}; case 12: return new String[]{SystemUtils.FILE_ENCODING}; } return null; }
Example 8
Source File: ExceptionUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * <p>Returns an array where each element is a line from the argument.</p> * * <p>The end of line is determined by the value of {@link SystemUtils#LINE_SEPARATOR}.</p> * * @param stackTrace a stack trace String * @return an array where each element is a line from the argument */ static String[] getStackFrames(String stackTrace) { String linebreak = SystemUtils.LINE_SEPARATOR; StringTokenizer frames = new StringTokenizer(stackTrace, linebreak); List<String> list = new ArrayList<String>(); while (frames.hasMoreTokens()) { list.add(frames.nextToken()); } return list.toArray(new String[list.size()]); }
Example 9
Source File: ExceptionUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * <p>Returns an array where each element is a line from the argument.</p> * * <p>The end of line is determined by the value of {@link SystemUtils#LINE_SEPARATOR}.</p> * * @param stackTrace a stack trace String * @return an array where each element is a line from the argument */ static String[] getStackFrames(String stackTrace) { String linebreak = SystemUtils.LINE_SEPARATOR; StringTokenizer frames = new StringTokenizer(stackTrace, linebreak); List<String> list = new ArrayList<String>(); while (frames.hasMoreTokens()) { list.add(frames.nextToken()); } return list.toArray(new String[list.size()]); }
Example 10
Source File: ExceptionUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * <p>Returns an array where each element is a line from the argument.</p> * * <p>The end of line is determined by the value of {@link SystemUtils#LINE_SEPARATOR}.</p> * * @param stackTrace a stack trace String * @return an array where each element is a line from the argument */ static String[] getStackFrames(String stackTrace) { String linebreak = SystemUtils.LINE_SEPARATOR; StringTokenizer frames = new StringTokenizer(stackTrace, linebreak); List<String> list = new ArrayList<String>(); while (frames.hasMoreTokens()) { list.add(frames.nextToken()); } return toArray(list); }
Example 11
Source File: ExceptionUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * <p>Returns an array where each element is a line from the argument.</p> * * <p>The end of line is determined by the value of {@link SystemUtils#LINE_SEPARATOR}.</p> * * @param stackTrace a stack trace String * @return an array where each element is a line from the argument */ static String[] getStackFrames(final String stackTrace) { final String linebreak = SystemUtils.LINE_SEPARATOR; final StringTokenizer frames = new StringTokenizer(stackTrace, linebreak); final List<String> list = new ArrayList<String>(); while (frames.hasMoreTokens()) { list.add(frames.nextToken()); } return list.toArray(new String[list.size()]); }
Example 12
Source File: ExceptionUtils.java From astor with GNU General Public License v2.0 | 5 votes |
/** * <p>Returns an array where each element is a line from the argument.</p> * * <p>The end of line is determined by the value of {@link SystemUtils#LINE_SEPARATOR}.</p> * * @param stackTrace a stack trace String * @return an array where each element is a line from the argument */ static String[] getStackFrames(String stackTrace) { String linebreak = SystemUtils.LINE_SEPARATOR; StringTokenizer frames = new StringTokenizer(stackTrace, linebreak); List<String> list = new ArrayList<String>(); while (frames.hasMoreTokens()) { list.add(frames.nextToken()); } return list.toArray(new String[list.size()]); }
Example 13
Source File: WordUtils.java From astor with GNU General Public License v2.0 | 4 votes |
/** * <p>Wraps a single line of text, identifying words by <code>' '</code>.</p> * * <p>Leading spaces on a new line are stripped. * Trailing spaces are not stripped.</p> * * <pre> * WordUtils.wrap(null, *, *, *) = null * WordUtils.wrap("", *, *, *) = "" * </pre> * * @param str the String to be word wrapped, may be null * @param wrapLength the column to wrap the words at, less than 1 is treated as 1 * @param newLineStr the string to insert for a new line, * <code>null</code> uses the system property line separator * @param wrapLongWords true if long words (such as URLs) should be wrapped * @return a line with newlines inserted, <code>null</code> if null input */ public static String wrap(String str, int wrapLength, String newLineStr, boolean wrapLongWords) { if (str == null) { return null; } if (newLineStr == null) { newLineStr = SystemUtils.LINE_SEPARATOR; } if (wrapLength < 1) { wrapLength = 1; } int inputLineLength = str.length(); int offset = 0; StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32); while ((inputLineLength - offset) > wrapLength) { if (str.charAt(offset) == ' ') { offset++; continue; } int spaceToWrapAt = str.lastIndexOf(' ', wrapLength + offset); if (spaceToWrapAt >= offset) { // normal case wrappedLine.append(str.substring(offset, spaceToWrapAt)); wrappedLine.append(newLineStr); offset = spaceToWrapAt + 1; } else { // really long word or URL if (wrapLongWords) { // wrap really long word one line at a time wrappedLine.append(str.substring(offset, wrapLength + offset)); wrappedLine.append(newLineStr); offset += wrapLength; } else { // do not wrap really long word, just extend beyond limit spaceToWrapAt = str.indexOf(' ', wrapLength + offset); if (spaceToWrapAt >= 0) { wrappedLine.append(str.substring(offset, spaceToWrapAt)); wrappedLine.append(newLineStr); offset = spaceToWrapAt + 1; } else { wrappedLine.append(str.substring(offset)); offset = inputLineLength; } } } } // Whatever is left in line is short enough to just pass through wrappedLine.append(str.substring(offset)); return wrappedLine.toString(); }
Example 14
Source File: WordUtils.java From astor with GNU General Public License v2.0 | 4 votes |
/** * <p>Wraps a single line of text, identifying words by <code>' '</code>.</p> * * <p>Leading spaces on a new line are stripped. * Trailing spaces are not stripped.</p> * * <pre> * WordUtils.wrap(null, *, *, *) = null * WordUtils.wrap("", *, *, *) = "" * </pre> * * @param str the String to be word wrapped, may be null * @param wrapLength the column to wrap the words at, less than 1 is treated as 1 * @param newLineStr the string to insert for a new line, * <code>null</code> uses the system property line separator * @param wrapLongWords true if long words (such as URLs) should be wrapped * @return a line with newlines inserted, <code>null</code> if null input */ public static String wrap(String str, int wrapLength, String newLineStr, boolean wrapLongWords) { if (str == null) { return null; } if (newLineStr == null) { newLineStr = SystemUtils.LINE_SEPARATOR; } if (wrapLength < 1) { wrapLength = 1; } int inputLineLength = str.length(); int offset = 0; StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32); while (inputLineLength - offset > wrapLength) { if (str.charAt(offset) == ' ') { offset++; continue; } int spaceToWrapAt = str.lastIndexOf(' ', wrapLength + offset); if (spaceToWrapAt >= offset) { // normal case wrappedLine.append(str.substring(offset, spaceToWrapAt)); wrappedLine.append(newLineStr); offset = spaceToWrapAt + 1; } else { // really long word or URL if (wrapLongWords) { // wrap really long word one line at a time wrappedLine.append(str.substring(offset, wrapLength + offset)); wrappedLine.append(newLineStr); offset += wrapLength; } else { // do not wrap really long word, just extend beyond limit spaceToWrapAt = str.indexOf(' ', wrapLength + offset); if (spaceToWrapAt >= 0) { wrappedLine.append(str.substring(offset, spaceToWrapAt)); wrappedLine.append(newLineStr); offset = spaceToWrapAt + 1; } else { wrappedLine.append(str.substring(offset)); offset = inputLineLength; } } } } // Whatever is left in line is short enough to just pass through wrappedLine.append(str.substring(offset)); return wrappedLine.toString(); }
Example 15
Source File: WordUtils.java From astor with GNU General Public License v2.0 | 4 votes |
/** * <p>Wraps a single line of text, identifying words by <code>' '</code>.</p> * * <p>Leading spaces on a new line are stripped. * Trailing spaces are not stripped.</p> * * <pre> * WordUtils.wrap(null, *, *, *) = null * WordUtils.wrap("", *, *, *) = "" * </pre> * * @param str the String to be word wrapped, may be null * @param wrapLength the column to wrap the words at, less than 1 is treated as 1 * @param newLineStr the string to insert for a new line, * <code>null</code> uses the system property line separator * @param wrapLongWords true if long words (such as URLs) should be wrapped * @return a line with newlines inserted, <code>null</code> if null input */ public static String wrap(final String str, int wrapLength, String newLineStr, final boolean wrapLongWords) { if (str == null) { return null; } if (newLineStr == null) { newLineStr = SystemUtils.LINE_SEPARATOR; } if (wrapLength < 1) { wrapLength = 1; } final int inputLineLength = str.length(); int offset = 0; final StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32); while (inputLineLength - offset > wrapLength) { if (str.charAt(offset) == ' ') { offset++; continue; } int spaceToWrapAt = str.lastIndexOf(' ', wrapLength + offset); if (spaceToWrapAt >= offset) { // normal case wrappedLine.append(str.substring(offset, spaceToWrapAt)); wrappedLine.append(newLineStr); offset = spaceToWrapAt + 1; } else { // really long word or URL if (wrapLongWords) { // wrap really long word one line at a time wrappedLine.append(str.substring(offset, wrapLength + offset)); wrappedLine.append(newLineStr); offset += wrapLength; } else { // do not wrap really long word, just extend beyond limit spaceToWrapAt = str.indexOf(' ', wrapLength + offset); if (spaceToWrapAt >= 0) { wrappedLine.append(str.substring(offset, spaceToWrapAt)); wrappedLine.append(newLineStr); offset = spaceToWrapAt + 1; } else { wrappedLine.append(str.substring(offset)); offset = inputLineLength; } } } } // Whatever is left in line is short enough to just pass through wrappedLine.append(str.substring(offset)); return wrappedLine.toString(); }
Example 16
Source File: WordUtils.java From astor with GNU General Public License v2.0 | 4 votes |
/** * <p>Wraps a single line of text, identifying words by <code>' '</code>.</p> * * <p>Leading spaces on a new line are stripped. * Trailing spaces are not stripped.</p> * * <pre> * WordUtils.wrap(null, *, *, *) = null * WordUtils.wrap("", *, *, *) = "" * </pre> * * @param str the String to be word wrapped, may be null * @param wrapLength the column to wrap the words at, less than 1 is treated as 1 * @param newLineStr the string to insert for a new line, * <code>null</code> uses the system property line separator * @param wrapLongWords true if long words (such as URLs) should be wrapped * @return a line with newlines inserted, <code>null</code> if null input */ public static String wrap(String str, int wrapLength, String newLineStr, boolean wrapLongWords) { if (str == null) { return null; } if (newLineStr == null) { newLineStr = SystemUtils.LINE_SEPARATOR; } if (wrapLength < 1) { wrapLength = 1; } int inputLineLength = str.length(); int offset = 0; StringBuilder wrappedLine = new StringBuilder(inputLineLength + 32); while (inputLineLength - offset > wrapLength) { if (str.charAt(offset) == ' ') { offset++; continue; } int spaceToWrapAt = str.lastIndexOf(' ', wrapLength + offset); if (spaceToWrapAt >= offset) { // normal case wrappedLine.append(str.substring(offset, spaceToWrapAt)); wrappedLine.append(newLineStr); offset = spaceToWrapAt + 1; } else { // really long word or URL if (wrapLongWords) { // wrap really long word one line at a time wrappedLine.append(str.substring(offset, wrapLength + offset)); wrappedLine.append(newLineStr); offset += wrapLength; } else { // do not wrap really long word, just extend beyond limit spaceToWrapAt = str.indexOf(' ', wrapLength + offset); if (spaceToWrapAt >= 0) { wrappedLine.append(str.substring(offset, spaceToWrapAt)); wrappedLine.append(newLineStr); offset = spaceToWrapAt + 1; } else { wrappedLine.append(str.substring(offset)); offset = inputLineLength; } } } } // Whatever is left in line is short enough to just pass through wrappedLine.append(str.substring(offset)); return wrappedLine.toString(); }