/** * Creates a new instance of this class. * * @param inputDir * The File object for the input directory. * @param recordReceiver * The receiver handling the records. * @param ignoreUnknownRecordTypes * select only records of this type; null selects all */ public FSDirectoryReader(final File inputDir, final IMonitoringRecordReceiver recordReceiver, final boolean ignoreUnknownRecordTypes) { if ((inputDir == null) || !inputDir.isDirectory()) { throw new IllegalArgumentException("Invalid or empty inputDir"); } this.inputDir = inputDir; this.recordReceiver = recordReceiver; this.ignoreUnknownRecordTypes = ignoreUnknownRecordTypes; this.textFileStreamProcessor = new TextFileStreamProcessor(ignoreUnknownRecordTypes, this.stringRegistry, recordReceiver); this.binaryFileStreamProcessor = new BinaryFileStreamProcessor(this.stringRegistry, recordReceiver); }
/** * Reads the records contained in the given binary file and passes them to the registered {@link #recordReceiver}. * * @param inputFile * The input file which should be processed. * @param decompressionFilter * Whether the input file is compressed. */ private final void processBinaryInputFile(final File inputFile, final AbstractDecompressionFilter decompressionFilter) { DataInputStream in = null; try { in = new DataInputStream(decompressionFilter.chainInputStream(new FileInputStream(inputFile))); this.binaryFileStreamProcessor.createRecordsFromBinaryFile(in); } catch (final Exception ex) { // NOPMD NOCS (catch Exception) LOGGER.error("Error reading {}", inputFile, ex); } finally { if (in != null) { try { in.close(); } catch (final IOException ex) { LOGGER.error("Exception while closing input stream for processing input file", ex); } } } } }
private void processBuffer(final IValueDeserializer deserializer) throws IOException { this.buffer.flip(); try { /** Needs at least an record id. */ while ((this.buffer.position() + 4) <= this.buffer.limit()) { this.buffer.mark(); final IMonitoringRecord record = this.deserializeRecord(deserializer); if (record == null) { return; } else { this.recordReceiver.newMonitoringRecord(record); } } this.buffer.mark(); this.buffer.compact(); } catch (final BufferUnderflowException ex) { LOGGER.warn("Unexpected buffer underflow. Resetting and compacting buffer.", ex); this.buffer.reset(); this.buffer.compact(); throw ex; } }
this.processBuffer(deserializer);
/** * Creates a new instance of this class. * * @param zipFile * The File object for the zip file. * @param recordReceiver * The receiver handling the records. * @param ignoreUnknownRecordTypes * select only records of this type; null selects all */ public FSZipReader(final File zipFile, final IMonitoringRecordReceiver recordReceiver, final boolean ignoreUnknownRecordTypes) { if ((zipFile == null) || !zipFile.isFile() || !zipFile.getName().endsWith(FSUtil.ZIP_FILE_EXTENSION)) { throw new IllegalArgumentException("Invalid zip file"); } this.zipFile = zipFile; this.recordReceiver = recordReceiver; this.ignoreUnknownRecordTypes = ignoreUnknownRecordTypes; this.binaryFileStreamProcessor = new BinaryFileStreamProcessor(this.stringRegistry, recordReceiver); this.textFileStreamProcessor = new TextFileStreamProcessor(ignoreUnknownRecordTypes, this.stringRegistry, recordReceiver); }
/** * Reads the records contained in the given binary file and passes them to the registered {@link #recordReceiver}. * * @param inputFile * The input file which should be processed. * @param decompressionFilter * Whether the input file is compressed. */ private final void processBinaryInputFile(final File inputFile, final AbstractDecompressionFilter decompressionFilter) { DataInputStream in = null; try { in = new DataInputStream(decompressionFilter.chainInputStream(new FileInputStream(inputFile))); this.binaryFileStreamProcessor.createRecordsFromBinaryFile(in); } catch (final Exception ex) { // NOPMD NOCS (catch Exception) LOGGER.error("Error reading {}", inputFile, ex); } finally { if (in != null) { try { in.close(); } catch (final IOException ex) { LOGGER.error("Exception while closing input stream for processing input file", ex); } } } } }
/** * Creates a new instance of this class. * * @param zipFile * The File object for the zip file. * @param recordReceiver * The receiver handling the records. * @param ignoreUnknownRecordTypes * select only records of this type; null selects all */ public FSZipReader(final File zipFile, final IMonitoringRecordReceiver recordReceiver, final boolean ignoreUnknownRecordTypes) { if ((zipFile == null) || !zipFile.isFile() || !zipFile.getName().endsWith(FSUtil.ZIP_FILE_EXTENSION)) { throw new IllegalArgumentException("Invalid zip file"); } this.zipFile = zipFile; this.recordReceiver = recordReceiver; this.ignoreUnknownRecordTypes = ignoreUnknownRecordTypes; this.binaryFileStreamProcessor = new BinaryFileStreamProcessor(this.stringRegistry, recordReceiver); this.textFileStreamProcessor = new TextFileStreamProcessor(ignoreUnknownRecordTypes, this.stringRegistry, recordReceiver); }
this.binaryFileStreamProcessor.createRecordsFromBinaryFile(input); } catch (IOException | MonitoringRecordException e) { LOGGER.error("Cannot deserialize binary record {}", e);
/** * Creates a new instance of this class. * * @param inputDir * The File object for the input directory. * @param recordReceiver * The receiver handling the records. * @param ignoreUnknownRecordTypes * select only records of this type; null selects all */ public FSDirectoryReader(final File inputDir, final IMonitoringRecordReceiver recordReceiver, final boolean ignoreUnknownRecordTypes) { if ((inputDir == null) || !inputDir.isDirectory()) { throw new IllegalArgumentException("Invalid or empty inputDir"); } this.inputDir = inputDir; this.recordReceiver = recordReceiver; this.ignoreUnknownRecordTypes = ignoreUnknownRecordTypes; this.textFileStreamProcessor = new TextFileStreamProcessor(ignoreUnknownRecordTypes, this.stringRegistry, recordReceiver); this.binaryFileStreamProcessor = new BinaryFileStreamProcessor(this.stringRegistry, recordReceiver); }
this.binaryFileStreamProcessor.createRecordsFromBinaryFile(input); } catch (IOException | MonitoringRecordException e) { LOGGER.error("Cannot deserialize binary record {}", e);