forked from java-decompiler/jd-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes java-decompiler#17, Option for Line Endings
- Loading branch information
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
services/src/main/java/jd/gui/util/io/NewlineOutputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2008-2015 Emmanuel Dupuy | ||
* This program is made available under the terms of the GPLv3 License. | ||
*/ | ||
|
||
package jd.gui.util.io; | ||
|
||
import java.io.FilterOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.charset.Charset; | ||
|
||
public class NewlineOutputStream extends FilterOutputStream { | ||
private static byte[] lineSeparator; | ||
|
||
public NewlineOutputStream(OutputStream os) { | ||
super(os); | ||
|
||
if (lineSeparator == null) { | ||
String s = System.getProperty("line.separator"); | ||
|
||
if ((s == null) || (s.length() <= 0)) | ||
s = "\n"; | ||
|
||
lineSeparator = s.getBytes(Charset.forName("UTF-8")); | ||
} | ||
} | ||
|
||
public void write(int b) throws IOException { | ||
if (b == '\n') { | ||
out.write(lineSeparator); | ||
} else { | ||
out.write(b); | ||
} | ||
} | ||
|
||
public void write(byte b[]) throws IOException { | ||
write(b, 0, b.length); | ||
} | ||
|
||
public void write(byte b[], int off, int len) throws IOException { | ||
int i; | ||
|
||
for (i=off; i<len; i++) { | ||
if (b[i] == '\n') { | ||
out.write(b, off, i-off); | ||
out.write(lineSeparator); | ||
off = i+1; | ||
} | ||
} | ||
|
||
out.write(b, off, i-off); | ||
} | ||
} |