@@ -38,26 +38,34 @@ public class BinaryLogFileReader implements Closeable {
38
38
39
39
private final ByteArrayInputStream inputStream ;
40
40
private final EventDeserializer eventDeserializer ;
41
+ private final String filename ;
42
+ private long offset ;
41
43
42
44
public BinaryLogFileReader (File file ) throws IOException {
43
45
this (file , new EventDeserializer ());
44
46
}
45
47
46
48
public BinaryLogFileReader (File file , EventDeserializer eventDeserializer ) throws IOException {
47
- this (file != null ? new BufferedInputStream (new FileInputStream (file )) : null , eventDeserializer );
49
+ this (file != null ? file .getName () : null ,
50
+ file != null ? new BufferedInputStream (new FileInputStream (file )) : null ,
51
+ eventDeserializer );
48
52
}
49
53
50
- public BinaryLogFileReader (InputStream inputStream ) throws IOException {
51
- this (inputStream , new EventDeserializer ());
54
+ public BinaryLogFileReader (String filename , InputStream inputStream ) throws IOException {
55
+ this (filename , inputStream , new EventDeserializer ());
52
56
}
53
57
54
- public BinaryLogFileReader (InputStream inputStream , EventDeserializer eventDeserializer ) throws IOException {
58
+ public BinaryLogFileReader (String filename , InputStream inputStream , EventDeserializer eventDeserializer ) throws IOException {
59
+ if (filename == null ) {
60
+ throw new IllegalArgumentException ("File name cannot be NULL" );
61
+ }
55
62
if (inputStream == null ) {
56
63
throw new IllegalArgumentException ("Input stream cannot be NULL" );
57
64
}
58
65
if (eventDeserializer == null ) {
59
66
throw new IllegalArgumentException ("Event deserializer cannot be NULL" );
60
67
}
68
+ this .filename = filename ;
61
69
this .inputStream = new ByteArrayInputStream (inputStream );
62
70
try {
63
71
byte [] magicHeader = this .inputStream .read (MAGIC_HEADER .length );
@@ -79,7 +87,7 @@ public BinaryLogFileReader(InputStream inputStream, EventDeserializer eventDeser
79
87
* @return deserialized event or null in case of end-of-stream
80
88
*/
81
89
public Event readEvent () throws IOException {
82
- return eventDeserializer .nextEvent (inputStream );
90
+ return eventDeserializer .nextEvent (inputStream , filename , offset ++ );
83
91
}
84
92
85
93
@ Override
0 commit comments