本文整理了Java中java.lang.System.lineSeparator()
方法的一些代码示例,展示了System.lineSeparator()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。System.lineSeparator()
方法的具体详情如下:
包路径:java.lang.System
类名称:System
方法名:lineSeparator
[英]Returns the system's line separator. On Android, this is "\n". The value comes from the value of the line.separator system property when the VM starts. Later changes to the property will not affect the value returned by this method.
[中]返回系统的行分隔符。在Android上,这是“\n”。该值来自该行的值。VM启动时的分隔符系统属性。以后对属性的更改不会影响此方法返回的值。
代码示例来源:origin: stackoverflow.com
try(BufferedReader br = new BufferedReader(new FileReader("file.txt"))) {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
String everything = sb.toString();
}
代码示例来源:origin: stackoverflow.com
BufferedReader br = new BufferedReader(new FileReader("file.txt"));
try {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
String everything = sb.toString();
} finally {
br.close();
}
代码示例来源:origin: ctripcorp/apollo
public static String fileToString(InputStream inputStream) {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
return bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));
}
}
代码示例来源:origin: eugenp/tutorials
private String bodyToString(InputStream body) throws IOException {
StringBuilder builder = new StringBuilder();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(body, StandardCharsets.UTF_8));
String line = bufferedReader.readLine();
while (line != null) {
builder.append(line).append(System.lineSeparator());
line = bufferedReader.readLine();
}
bufferedReader.close();
return builder.toString();
}
}
代码示例来源:origin: apache/incubator-dubbo
private String filterEmptyLine(String content) {
final StringBuilder sb = new StringBuilder();
try (Scanner scanner = new Scanner(content)) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line != null) {
// remove extra space at line's end
line = StringUtils.stripEnd(line, " ");
if (line.isEmpty()) {
line = " ";
}
}
sb.append(line).append(System.lineSeparator());
}
}
return sb.toString();
}
}
代码示例来源:origin: apache/incubator-dubbo
private String filterEmptyLine(String content) {
final StringBuilder sb = new StringBuilder();
try (Scanner scanner = new Scanner(content)) {
while (scanner.hasNextLine()) {
String line = scanner.nextLine();
if (line != null) {
// remove extra space at line's end
line = StringUtils.stripEnd(line, " ");
if (line.isEmpty()) {
line = " ";
}
}
sb.append(line).append(System.lineSeparator());
}
}
return sb.toString();
}
}
代码示例来源:origin: apache/flink
static FlinkException createAndLogException(PyException pe, Logger log) {
StringWriter sw = new StringWriter();
try (PrintWriter pw = new PrintWriter(sw)) {
pe.printStackTrace(pw);
}
String pythonStackTrace = sw.toString().trim();
log.error("Python function failed: " + System.lineSeparator() + pythonStackTrace);
return new FlinkException("Python function failed: " + pythonStackTrace);
}
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* <p>Constructor.</p>
*
* <p>Use the static constant rather than instantiating.</p>
*/
MultiLineToStringStyle() {
super();
this.setContentStart("[");
this.setFieldSeparator(System.lineSeparator() + " ");
this.setFieldSeparatorAtStart(true);
this.setContentEnd(System.lineSeparator() + "]");
}
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Resets the fields responsible for the line breaks and indenting.
* Must be invoked after changing the {@link #spaces} value.
*/
private void resetIndent() {
setArrayStart("{" + System.lineSeparator() + spacer(spaces));
setArraySeparator("," + System.lineSeparator() + spacer(spaces));
setArrayEnd(System.lineSeparator() + spacer(spaces - INDENT) + "}");
setContentStart("[" + System.lineSeparator() + spacer(spaces));
setFieldSeparator("," + System.lineSeparator() + spacer(spaces));
setContentEnd(System.lineSeparator() + spacer(spaces - INDENT) + "]");
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testLong() {
assertEquals(baseStr + "[" + System.lineSeparator() + " 3" + System.lineSeparator() + "]", new ToStringBuilder(base).append(3L).toString());
assertEquals(baseStr + "[" + System.lineSeparator() + " a=3" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", 3L).toString());
assertEquals(baseStr + "[" + System.lineSeparator() + " a=3" + System.lineSeparator() + " b=4" + System.lineSeparator() + "]", new ToStringBuilder(base).append("a", 3L).append("b", 4L).toString());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testAppendSuper() {
assertEquals(baseStr + "[" + System.lineSeparator() + "]", new ToStringBuilder(base).appendSuper("Integer@8888[" + System.lineSeparator() + "]").toString());
assertEquals(baseStr + "[" + System.lineSeparator() + " <null>" + System.lineSeparator() + "]", new ToStringBuilder(base).appendSuper("Integer@8888[" + System.lineSeparator() + " <null>" + System.lineSeparator() + "]").toString());
assertEquals(baseStr + "[" + System.lineSeparator() + " a=hello" + System.lineSeparator() + "]", new ToStringBuilder(base).appendSuper("Integer@8888[" + System.lineSeparator() + "]").append("a", "hello").toString());
assertEquals(baseStr + "[" + System.lineSeparator() + " <null>" + System.lineSeparator() + " a=hello" + System.lineSeparator() + "]", new ToStringBuilder(base).appendSuper("Integer@8888[" + System.lineSeparator() + " <null>" + System.lineSeparator() + "]").append("a", "hello").toString());
assertEquals(baseStr + "[" + System.lineSeparator() + " a=hello" + System.lineSeparator() + "]", new ToStringBuilder(base).appendSuper(null).append("a", "hello").toString());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testLongArrayArray() {
long[][] array = new long[][] {{1, 2}, null, {5}};
assertEquals(baseStr + "[" + System.lineSeparator() + " {{1,2},<null>,{5}}" + System.lineSeparator() + "]", new ToStringBuilder(base).append(array).toString());
assertEquals(baseStr + "[" + System.lineSeparator() + " {{1,2},<null>,{5}}" + System.lineSeparator() + "]", new ToStringBuilder(base).append((Object) array).toString());
array = null;
assertEquals(baseStr + "[" + System.lineSeparator() + " <null>" + System.lineSeparator() + "]", new ToStringBuilder(base).append(array).toString());
assertEquals(baseStr + "[" + System.lineSeparator() + " <null>" + System.lineSeparator() + "]", new ToStringBuilder(base).append((Object) array).toString());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testLongArray() {
long[] array = new long[] {1, 2, -3, 4};
assertEquals(baseStr + "[" + System.lineSeparator() + " {1,2,-3,4}" + System.lineSeparator() + "]", new ToStringBuilder(base).append(array).toString());
assertEquals(baseStr + "[" + System.lineSeparator() + " {1,2,-3,4}" + System.lineSeparator() + "]", new ToStringBuilder(base).append((Object) array).toString());
array = null;
assertEquals(baseStr + "[" + System.lineSeparator() + " <null>" + System.lineSeparator() + "]", new ToStringBuilder(base).append(array).toString());
assertEquals(baseStr + "[" + System.lineSeparator() + " <null>" + System.lineSeparator() + "]", new ToStringBuilder(base).append((Object) array).toString());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testObjectArray() {
Object[] array = new Object[] {null, base, new int[] {3, 6}};
assertEquals(baseStr + "[" + System.lineSeparator() + " {<null>,5,{3,6}}" + System.lineSeparator() + "]", new ToStringBuilder(base).append(array).toString());
assertEquals(baseStr + "[" + System.lineSeparator() + " {<null>,5,{3,6}}" + System.lineSeparator() + "]", new ToStringBuilder(base).append((Object) array).toString());
array = null;
assertEquals(baseStr + "[" + System.lineSeparator() + " <null>" + System.lineSeparator() + "]", new ToStringBuilder(base).append(array).toString());
assertEquals(baseStr + "[" + System.lineSeparator() + " <null>" + System.lineSeparator() + "]", new ToStringBuilder(base).append((Object) array).toString());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testPerson() {
final Person p = new Person();
p.name = "Jane Doe";
p.age = 25;
p.smoker = true;
final String pBaseStr = p.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(p));
assertEquals(pBaseStr + "[" + System.lineSeparator() + " name=Jane Doe" + System.lineSeparator() + " age=25" + System.lineSeparator() + " smoker=true" + System.lineSeparator() + "]", new ToStringBuilder(p).append("name", p.name).append("age", p.age).append("smoker", p.smoker).toString());
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testBlank() {
assertEquals(baseStr + "[" + System.lineSeparator() + "]", new ToStringBuilder(base).toString());
}
代码示例来源:origin: apache/incubator-dubbo
public String listProvider() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("As Provider side:" + System.lineSeparator());
Collection<ProviderModel> ProviderModelList = ApplicationModel.allProviderModels();
TTable tTable = new TTable(new TTable.ColumnDefine[]{
new TTable.ColumnDefine(TTable.Align.MIDDLE),
new TTable.ColumnDefine(TTable.Align.MIDDLE)
});
//Header
tTable.addRow("Provider Service Name", "PUB");
//Content
for (ProviderModel providerModel : ProviderModelList) {
tTable.addRow(providerModel.getServiceName(), isRegistered(providerModel.getServiceName()) ? "Y" : "N");
}
stringBuilder.append(tTable.rendering());
return stringBuilder.toString();
}
代码示例来源:origin: apache/incubator-dubbo
public String listProvider() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("As Provider side:" + System.lineSeparator());
Collection<ProviderModel> ProviderModelList = ApplicationModel.allProviderModels();
TTable tTable = new TTable(new TTable.ColumnDefine[]{
new TTable.ColumnDefine(TTable.Align.MIDDLE),
new TTable.ColumnDefine(TTable.Align.MIDDLE)
});
//Header
tTable.addRow("Provider Service Name", "PUB");
//Content
for (ProviderModel providerModel : ProviderModelList) {
tTable.addRow(providerModel.getServiceName(), isRegistered(providerModel.getServiceName()) ? "Y" : "N");
}
stringBuilder.append(tTable.rendering());
return stringBuilder.toString();
}
代码示例来源:origin: apache/incubator-dubbo
public String listConsumer() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("As Consumer side:" + System.lineSeparator());
Collection<ConsumerModel> consumerModelList = ApplicationModel.allConsumerModels();
TTable tTable = new TTable(new TTable.ColumnDefine[]{
new TTable.ColumnDefine(TTable.Align.MIDDLE),
new TTable.ColumnDefine(TTable.Align.MIDDLE)
});
//Header
tTable.addRow("Consumer Service Name", "NUM");
//Content
//TODO to calculate consumerAddressNum
for (ConsumerModel consumerModel : consumerModelList) {
tTable.addRow(consumerModel.getServiceName(), getConsumerAddressNum(consumerModel.getServiceName()));
}
stringBuilder.append(tTable.rendering());
return stringBuilder.toString();
}
}
代码示例来源:origin: apache/incubator-dubbo
public String listConsumer() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("As Consumer side:" + System.lineSeparator());
Collection<ConsumerModel> consumerModelList = ApplicationModel.allConsumerModels();
TTable tTable = new TTable(new TTable.ColumnDefine[]{
new TTable.ColumnDefine(TTable.Align.MIDDLE),
new TTable.ColumnDefine(TTable.Align.MIDDLE)
});
//Header
tTable.addRow("Consumer Service Name", "NUM");
//Content
//TODO to calculate consumerAddressNum
for (ConsumerModel consumerModel : consumerModelList) {
tTable.addRow(consumerModel.getServiceName(), getConsumerAddressNum(consumerModel.getServiceName()));
}
stringBuilder.append(tTable.rendering());
return stringBuilder.toString();
}
}
内容来源于网络,如有侵权,请联系作者删除!