System.in InputStream처럼 작동하지만 프로그래밍 방식으로 추가 할 수있는 InputStream 클래스를 만들려고합니다 (동적으로 추가 할 수있는 끝이없는 InputStream)System.in처럼 작동하는 InputStream을 만드는 방법
당신은 문제가 무슨 뜻인지 이해 한 경우, 여기에 내가 쓴과
public class QueuedInputStream extends InputStream {
private LinkedList<Character> list;
public QueuedInputStream() {
list = new LinkedList<Character>();
}
@Override
public int read() throws IOException {
while (list.isEmpty()) {
try {
Thread.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
int value = (byte)list.get(0).charValue();
list.remove();
return value;
}
public void queue(String s) {
char[] chars = s.toCharArray();
for(int i = 0; i < chars.length; i++) {
list.add(chars[i]);
}
}
}
내가 바른 길에 있나요 시도이야? 아니면이 일을 완전히 잘못 했나요? 당신이 좀 더 설명하려면,
PipedInputStream 및 ByteArrayInputStream을 살펴보십시오. – ignis