All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.codetaco.funnel.publisher.VariableLengthFilePublisher Maven / Gradle / Ivy

There is a newer version: 3.0.5
Show newest version
package com.codetaco.funnel.publisher;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.text.ParseException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.codetaco.funnel.parameters.FunnelContext;

/**
 * 

* VariableLengthFilePublisher class. *

* * @author Chris DeGreef [email protected] */ public class VariableLengthFilePublisher extends VariableLengthPublisher { static final private Logger logger = LoggerFactory.getLogger(VariableLengthFilePublisher.class); File sortedTempFile; /** *

* Constructor for VariableLengthFilePublisher. *

* * @param _context a {@link com.codetaco.funnel.parameters.FunnelContext} * object. * @throws java.text.ParseException if any. * @throws java.io.IOException if any. */ public VariableLengthFilePublisher(final FunnelContext _context) throws ParseException, IOException { super(_context); logger.debug("variable length file publisher activated"); } /** {@inheritDoc} */ @Override public void close() throws Exception { super.close(); ((RandomAccessFile) writer).close(); if (context.getOutputFile().delete()) logger.trace("deleted {}", context.getOutputFile().getAbsolutePath()); if (!sortedTempFile.renameTo(context.getOutputFile())) throw new IOException("failed to rename " + sortedTempFile.getAbsolutePath() + " to " + context.getOutputFile().getAbsolutePath()); logger.trace("renamed {} to {}", sortedTempFile.getAbsolutePath(), context.getOutputFile().getAbsolutePath()); } /** * @param _context */ @Override void openOutput(final FunnelContext _context) throws IOException, FileNotFoundException { sortedTempFile = File .createTempFile("Sorted.", ".tmp", context.getOutputFile().getAbsoluteFile().getParentFile()); sortedTempFile.deleteOnExit(); writer = new RandomAccessFile(sortedTempFile, "rw"); logger.debug("writing {}", sortedTempFile.getAbsolutePath()); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy