0
BOM (Byte Order Mark)을 포함하거나 포함하지 않고 파일을 구문 분석하고 있습니다.Java 출력이 NetBeans와 콘솔간에 다릅니다.
CharBuffer buffer = allocateBuffer();
reader.read(buffer);
buffer.flip();
나중에을 초기화하기 다음과 같은 방법
private void init() {
char first;
if (buffer.hasRemaining()) {
first = buffer.get();
if (!isByteOrderMark(first)) {
buffer.rewind();
}
}
}
아니라 BOM을 무시 호출, 그것은이 있고, 콘솔에
Parsing file "common\name_lists\AI.txt"...
[FILL] file_size=6878, total_line=140
[PARSE] parent=null, state=0
[NEXT] line=1, next="AI"
cache=2 [=, {]
[NEXT] line=1, next="="
cache=1 [{]
[NEXT] line=1, next="{"
cache=0 []
그러나 넷빈즈에서 잘 작동 밝혀졌다 다음 출력 :
Parsing file "common/name_lists/AI.txt"...
[FILL] file_size=6879, total_line=140
[PARSE] parent=null, state=0
[NEXT] line=1, next="�?"
cache=2 [AI, =]
[NEXT] line=1, next="AI"
cache=1 [=]
[NEXT] line=1, next="="
cache=0 []
[NEXT] line=2, next="{"
cache=2 [selectable, =]
Exception in thread "main" com.stellaris.TokenException: {
at com.stellaris.ScriptFile.handlePlainList(ScriptFile.java:269)
at com.stellaris.ScriptFile.analyze(ScriptFile.java:109)
at com.stellaris.ScriptFile.analyze(ScriptFile.java:57)
at com.stellaris.ScriptFile.<init>(ScriptFile.java:50)
at com.stellaris.ScriptFile.<init>(ScriptFile.java:45)
at com.stellaris.ScriptFile.newInstance(ScriptFile.java:38)
at com.stellaris.ScriptFile.main(ScriptFile.java:280)
그때 내가 클래스 파일을 디 컴파일, 그것은 방법의
Compiled from "ScriptParser.java"
public final class com.stellaris.ScriptParser {
public com.stellaris.ScriptParser(java.io.Reader);
private void init();
private static boolean isByteOrderMark(char);
private static java.nio.CharBuffer allocateBuffer();
}
바이트 코드 초기화 초기화 생성자 ScriptParser (리더 리더)에 호출
private void init();
Code:
0: aload_0
1: getfield #12 // Field buffer:Ljava/nio/CharBuffer;
4: invokevirtual #13 // Method java/nio/CharBuffer.hasRemaining:()Z
7: ifeq 33
10: aload_0
11: getfield #12 // Field buffer:Ljava/nio/CharBuffer;
14: invokevirtual #14 // Method java/nio/CharBuffer.get:()C
17: istore_1
18: iload_1
19: invokestatic #15 // Method isByteOrderMark:(C)Z
22: ifne 33
25: aload_0
26: getfield #12 // Field buffer:Ljava/nio/CharBuffer;
29: invokevirtual #16 // Method java/nio/CharBuffer.rewind:()Ljava/nio/Buffer;
32: pop
33: return
방법
잘 보인다public com.stellaris.ScriptParser(java.io.Reader);
Code:
0: aload_0
1: invokespecial #2 // Method java/lang/Object."<init>":()V
4: aload_0
5: new #3 // class java/io/BufferedReader
8: dup
9: aload_1
10: invokespecial #4 // Method java/io/BufferedReader."<init>":(Ljava/io/Reader;)V
13: putfield #5 // Field reader:Ljava/io/BufferedReader;
16: aload_0
17: new #6 // class java/util/LinkedList
20: dup
21: invokespecial #7 // Method java/util/LinkedList."<init>":()V
24: putfield #8 // Field deque:Ljava/util/LinkedList;
27: aload_0
28: invokespecial #9 // Method fill:()V
31: aload_0
32: iconst_0
33: putfield #10 // Field lineCounter:I
36: aload_0
37: invokespecial #11 // Method init:()V
40: return
.8 : 도시 된 바와 같이 10
는을 초기화하기 방법 는
제 4 자 (16 진수, 넷빈즈)
chars=feff 23 23 23
제 4 자 (16 진수, 콘솔)
chars=9518 fffd 23 23
javac의 버전을 호출 .0_73
자바 버전 : 1.8.0_73
파일 크기는 다릅니다. 어쩌면 인코딩 문제일까요? – Zhedar
java.io.FileReader로 연 파일이 같고 버퍼 크기가 65,536이므로 왜 크기가 다른지 알 수 없습니다 –
방금 FileReader로 읽은 동일한 파일이 NetBeans의 다른 헤더 문자와 콘솔에 있음을 알게되었습니다 –