mirror of
https://github.com/Febbweiss/logstash-forwarder-java.git
synced 2026-03-04 22:25:39 +00:00
Implemented FileState serialization/deserialization.
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
||||
/target/
|
||||
/bin/
|
||||
/testFileReader1.txt
|
||||
/state2.json
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -124,7 +124,7 @@
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<version>2.1.5</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
|
||||
@@ -21,21 +21,36 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.RandomAccessFile;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
public class FileState {
|
||||
@JsonIgnore
|
||||
private File file;
|
||||
private String directory;
|
||||
private String fileName;
|
||||
@JsonIgnore
|
||||
private long lastModified;
|
||||
@JsonIgnore
|
||||
private long size;
|
||||
@JsonIgnore
|
||||
private boolean deleted = false;
|
||||
private long signature;
|
||||
private int signatureLength;
|
||||
@JsonIgnore
|
||||
private boolean changed = false;
|
||||
@JsonIgnore
|
||||
private RandomAccessFile randomAccessFile;
|
||||
private long pointer = 0;
|
||||
@JsonIgnore
|
||||
private FileState oldFileState;
|
||||
private String fileName;
|
||||
@JsonIgnore
|
||||
private Event fields;
|
||||
|
||||
public FileState() {
|
||||
}
|
||||
|
||||
public FileState(File file) throws IOException {
|
||||
this.file = file;
|
||||
directory = file.getCanonicalFile().getParent();
|
||||
@@ -44,6 +59,10 @@ public class FileState {
|
||||
lastModified = file.lastModified();
|
||||
size = file.length();
|
||||
}
|
||||
|
||||
private void setFileFromDirectoryAndName() {
|
||||
this.file = new File(directory + File.pathSeparator + fileName);
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
@@ -61,6 +80,24 @@ public class FileState {
|
||||
return directory;
|
||||
}
|
||||
|
||||
public void setDirectory(String directory) {
|
||||
this.directory = directory;
|
||||
if(fileName != null && directory != null) {
|
||||
setFileFromDirectoryAndName();
|
||||
}
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
if(fileName != null && directory != null) {
|
||||
setFileFromDirectoryAndName();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
@@ -113,10 +150,6 @@ public class FileState {
|
||||
this.oldFileState = oldFileState;
|
||||
}
|
||||
|
||||
public String getFileName() {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
public Event getFields() {
|
||||
return fields;
|
||||
}
|
||||
@@ -125,4 +158,15 @@ public class FileState {
|
||||
this.fields = fields;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this).
|
||||
append("fileName", fileName).
|
||||
append("directory", directory).
|
||||
append("pointer", pointer).
|
||||
append("signature", signature).
|
||||
append("signatureLength", signatureLength).
|
||||
toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,10 +16,8 @@ import org.apache.commons.cli.Option;
|
||||
import org.apache.commons.cli.OptionBuilder;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.apache.log4j.Appender;
|
||||
import org.apache.log4j.BasicConfigurator;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.log4j.spi.RootLogger;
|
||||
|
||||
/*
|
||||
|
||||
4
src/test/resources/state1.json
Normal file
4
src/test/resources/state1.json
Normal file
@@ -0,0 +1,4 @@
|
||||
[
|
||||
{"fileName":"file1","directory":"/directory1","pointer":12345,"signature":654321,"signatureLength":135},
|
||||
{"fileName":"file2","directory":"/directory2","pointer":23456,"signature":7654,"signatureLength":246}
|
||||
]
|
||||
Reference in New Issue
Block a user