![JAR search and dependency download from the Maven repository](/logo.png)
com.codetaco.funnel.provider.VariableLengthProvider Maven / Gradle / Ivy
package com.codetaco.funnel.provider;
import java.io.IOException;
import java.text.ParseException;
import com.codetaco.funnel.parameters.FunnelContext;
/**
* Read a file of ascii strings one line at a time
*
* @author Chris DeGreef [email protected]
*/
public class VariableLengthProvider extends AbstractProvider
{
private static final int MAX_VARIABLE_LENGTH_RECORD_SIZE = 1 << 13;
/**
*
* Constructor for VariableLengthProvider.
*
*
* @param _context a {@link com.codetaco.funnel.parameters.FunnelContext}
* object.
* @throws java.io.IOException if any.
* @throws java.text.ParseException if any.
*/
public VariableLengthProvider(final FunnelContext _context) throws IOException, ParseException
{
super(_context);
}
/** {@inheritDoc} */
@Override
public long actualNumberOfRows()
{
return getContinuousRecordNumber();
}
void assignReaderInstance() throws IOException, ParseException
{
if (context.isSysin())
reader = new VariableLengthSysinReader(context);
else if (context.isCacheInput())
reader = new VariableLengthCacheReader(context);
else
reader = new VariableLengthFileReader(context);
}
@Override
void initialize() throws IOException, ParseException
{
row = new byte[MAX_VARIABLE_LENGTH_RECORD_SIZE];
logger.debug(row.length + " byte array size for rows. This is an arbitrary upper limit.");
int optimalFunnelDepth = 2;
long pow2 = context.getMaximumNumberOfRows();
while (true)
{
if (pow2 < 2)
break;
pow2 /= 2;
optimalFunnelDepth++;
}
if (context.getDepth() > optimalFunnelDepth)
{
logger.debug("overriding power from " + context.getDepth() + " to " + optimalFunnelDepth);
context.setDepth(optimalFunnelDepth);
}
setThisFileRecordNumber(unselectedCount = 0);
assignReaderInstance();
}
/** {@inheritDoc} */
@Override
public long maximumNumberOfRows()
{
return context.getMaximumNumberOfRows();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy