아틴
Atin
아틴
전체 방문자
오늘
어제
  • 분류 전체보기 (460)
    • Devlopment (246)
      • 정리 글 (20)
      • MicroServices (0)
      • Reactive, Concurrenc.. (12)
      • Java (44)
      • Spring (20)
      • C,C++,Ruby,Python (52)
      • Mobile (39)
      • Web (35)
      • Tip & Info (14)
      • Unit Test (7)
    • Infra (44)
      • OS (21)
      • RDBMS (13)
      • NoSQL&Cache (5)
      • AWS (4)
    • Computer Science (11)
    • Etc (156)

블로그 메뉴

  • Home
  • Guestbook

공지사항

인기 글

태그

  • javascript
  • Java
  • C
  • TRPG
  • 전라도
  • Python
  • Ruby on Rails
  • Linux
  • 아이폰
  • 정읍
  • mysql
  • Android
  • Dungeons & Dragons
  • CSS
  • 던젼 앤 드래곤즈
  • 여행
  • jsp
  • 안드로이드
  • 해킨토시
  • 자바

최근 댓글

최근 글

티스토리

hELLO · Designed By 정상우.
아틴

Atin

Devlopment/Java

System.out.println의 재정의

2011. 5. 13. 11:39
반응형
System.out.println의 재정의
다른 블로그에서 참조하였다. 지금 출처를 잊음.

import java.io.IOException;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;
import java.io.PrintStream;
import javax.swing.JTextArea;
import javax.swing.text.BadLocationException;

public class SoutInterceptor {
private PipedInputStream pipedInputStream;
private PrintStream originalPrint;
public SoutInterceptor() {
originalPrint = System.out;
this.pipedInputStream = new PipedInputStream();
}
public String getMessages() throws IOException {
byte[] messages = new byte[pipedInputStream.available()];
pipedInputStream.read(messages, 0, messages.length);
return new String(messages);
}
public void active() throws IOException {
final PipedOutputStream pipedOutputStream = new PipedOutputStream(pipedInputStream);
PrintStream saveStream = new PrintStream(pipedOutputStream) {
@Override
public void print(String x) {
//super.print(x);
originalPrint.println("Override" + x);
}
};
System.setOut(saveStream);
}

public static void main(String args[]){
try {
new SoutInterceptor().active();
System.out.println("hi");
} catch (Exception e) {
e.printStackTrace();
}
}
}
반응형

'Devlopment > Java' 카테고리의 다른 글

Builder Pattern  (0) 2011.06.09
달팽이 & 피보나치 수열 구현  (0) 2011.06.01
JNI(Java Native Interface) - 객체  (0) 2011.06.01
두 개의 스택을 이용한 큐 구현  (0) 2011.05.31
JNI(Java Native Interface)  (0) 2011.05.31
[Linux, Window] JAVA로 로컬 IP 주소 얻어오는 방법  (0) 2011.05.09
자바 enum에서 내부 String  (0) 2011.04.08
자바 Exception의 printStackTrace 구현.  (0) 2011.04.07
자바 개발시 오버라이드 @Override를 꼭 사용하자  (0) 2010.08.27
이클립스의 자바 메모리 설정  (2) 2010.04.29
    'Devlopment/Java' 카테고리의 다른 글
    • 두 개의 스택을 이용한 큐 구현
    • JNI(Java Native Interface)
    • [Linux, Window] JAVA로 로컬 IP 주소 얻어오는 방법
    • 자바 enum에서 내부 String
    아틴
    아틴

    티스토리툴바