bcv-vf/src/main/java/the/bytecode/club/bytecodeviewer/gui/components/JTextAreaOutputStream.java

72 lines
2.2 KiB
Java
Raw Normal View History

package the.bytecode.club.bytecodeviewer.gui.components;
2021-06-22 00:46:57 +00:00
2021-07-25 16:54:08 +00:00
import java.io.Closeable;
2021-06-22 00:46:57 +00:00
import java.io.OutputStream;
2021-07-07 04:21:06 +00:00
import java.io.PrintStream;
import javax.swing.JTextArea;
2021-06-22 00:46:57 +00:00
2021-06-26 03:33:06 +00:00
/***************************************************************************
* Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite *
* Copyright (C) 2014 Kalen 'Konloch' Kinloch - http://bytecodeviewer.com *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
***************************************************************************/
2021-06-22 00:46:57 +00:00
/**
* @author Konloch
* @since 6/21/2021
*/
2021-07-25 16:54:08 +00:00
public class JTextAreaOutputStream extends OutputStream implements Closeable
2021-06-22 00:46:57 +00:00
{
2021-07-07 23:49:06 +00:00
private StringBuilder sb = new StringBuilder();
2021-06-22 00:46:57 +00:00
private final JTextArea textArea;
2021-07-07 04:21:06 +00:00
private final PrintStream og;
2021-06-22 00:46:57 +00:00
2021-07-07 04:21:06 +00:00
public JTextAreaOutputStream(JTextArea textArea, PrintStream og)
2021-06-22 00:46:57 +00:00
{
this.textArea = textArea;
2021-07-07 04:21:06 +00:00
this.og = og;
2021-06-22 00:46:57 +00:00
}
2021-07-07 23:49:06 +00:00
public boolean noUpdateRequired()
{
return sb.length() <= 0;
}
2021-06-22 00:46:57 +00:00
public void update()
{
textArea.append(sb.toString());
2021-07-07 23:49:06 +00:00
sb = new StringBuilder();
2021-06-22 00:46:57 +00:00
}
@Override
2021-07-07 23:49:06 +00:00
public void write(int b)
2021-06-22 00:46:57 +00:00
{
sb.append((char) b);
2021-07-12 12:18:22 +00:00
if(og != null)
og.write(b);
2021-06-22 00:46:57 +00:00
}
2021-07-11 16:41:33 +00:00
public StringBuilder getBuffer()
{
return sb;
}
2021-07-25 16:54:08 +00:00
@Override
2021-12-19 23:24:17 +00:00
public void close() {
2021-07-25 16:54:08 +00:00
if (og != null)
og.close();
}
2021-06-22 00:46:57 +00:00
}