mirror of
https://github.com/Febbweiss/logstash-forwarder-java.git
synced 2026-03-05 14:45:40 +00:00
Created InputReader.
This commit is contained in:
68
src/main/java/info/fetter/logstashforwarder/Reader.java
Normal file
68
src/main/java/info/fetter/logstashforwarder/Reader.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package info.fetter.logstashforwarder;
|
||||
|
||||
|
||||
/*
|
||||
* Copyright 2015 Didier Fetter
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public abstract class Reader {
|
||||
protected ProtocolAdapter adapter;
|
||||
protected int spoolSize = 0;
|
||||
protected List<Event> eventList;
|
||||
protected final int STRINGBUILDER_INITIAL_CAPACITY = 1000;
|
||||
protected StringBuilder stringBuilder;
|
||||
private String hostname;
|
||||
{
|
||||
try {
|
||||
hostname = InetAddress.getLocalHost().getHostName();
|
||||
} catch (UnknownHostException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected Reader(int spoolSize) {
|
||||
this.spoolSize = spoolSize;
|
||||
eventList = new ArrayList<Event>(spoolSize);
|
||||
}
|
||||
|
||||
protected void addEvent(FileState state, long pos, String line) throws IOException {
|
||||
addEvent(state.getFile().getCanonicalPath(), state.getFields(), pos, line);
|
||||
}
|
||||
|
||||
protected void addEvent(String fileName, Event fields, long pos, String line) throws IOException {
|
||||
Event event = new Event(fields);
|
||||
event.addField("file", fileName)
|
||||
.addField("offset", pos)
|
||||
.addField("line", line)
|
||||
.addField("host", hostname);
|
||||
eventList.add(event);
|
||||
}
|
||||
|
||||
public ProtocolAdapter getAdapter() {
|
||||
return adapter;
|
||||
}
|
||||
|
||||
public void setAdapter(ProtocolAdapter adapter) {
|
||||
this.adapter = adapter;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user