mirror of
https://github.com/java-decompiler/jd-gui.git
synced 2025-03-03 01:56:36 +00:00
Fixes #17, Option for Line Endings
This commit is contained in:
parent
c27f9345de
commit
587ed2d9b5
@ -17,6 +17,7 @@ import jd.gui.api.model.Indexes
|
||||
import jd.gui.util.decompiler.ClassFileSourcePrinter
|
||||
import jd.gui.util.decompiler.ContainerLoader
|
||||
import jd.gui.util.decompiler.GuiPreferences
|
||||
import jd.gui.util.io.NewlineOutputStream
|
||||
import org.fife.ui.rsyntaxtextarea.DocumentRange
|
||||
import org.fife.ui.rsyntaxtextarea.SyntaxConstants
|
||||
|
||||
@ -156,7 +157,7 @@ class ClassFilePage
|
||||
}
|
||||
|
||||
void save(API api, OutputStream os) {
|
||||
os.withWriter('UTF-8') {
|
||||
new NewlineOutputStream(os).withWriter('UTF-8') {
|
||||
it.write(textArea.text)
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ import jd.gui.util.decompiler.ContainerLoader;
|
||||
import jd.gui.util.decompiler.GuiPreferences;
|
||||
import jd.gui.spi.SourceSaver;
|
||||
import jd.gui.util.decompiler.PlainTextPrinter;
|
||||
import jd.gui.util.io.NewlineOutputStream;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
@ -111,7 +112,7 @@ public class ClassFileSourceSaverProvider implements SourceSaver {
|
||||
ps.print("\n */");
|
||||
}
|
||||
|
||||
try (OutputStream os = Files.newOutputStream(path)) {
|
||||
try (OutputStream os = new NewlineOutputStream(Files.newOutputStream(path))) {
|
||||
baos.writeTo(os);
|
||||
} catch (IOException ignore) {
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user