use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.
the class CubeInputMeta method getFields.
public void getFields(RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore) throws KettleStepException {
GZIPInputStream fis = null;
DataInputStream dis = null;
try {
InputStream is = KettleVFS.getInputStream(space.environmentSubstitute(filename), space);
fis = new GZIPInputStream(is);
dis = new DataInputStream(fis);
RowMetaInterface add = new RowMeta(dis);
for (int i = 0; i < add.size(); i++) {
add.getValueMeta(i).setOrigin(name);
}
r.mergeRowMeta(add);
} catch (KettleFileException kfe) {
throw new KettleStepException(BaseMessages.getString(PKG, "CubeInputMeta.Exception.UnableToReadMetaData"), kfe);
} catch (IOException e) {
throw new KettleStepException(BaseMessages.getString(PKG, "CubeInputMeta.Exception.ErrorOpeningOrReadingCubeFile"), e);
} finally {
try {
if (fis != null) {
fis.close();
}
if (dis != null) {
dis.close();
}
} catch (IOException ioe) {
throw new KettleStepException(BaseMessages.getString(PKG, "CubeInputMeta.Exception.UnableToCloseCubeFile"), ioe);
}
}
}
use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.
the class GroupBy method getRowFromBuffer.
private Object[] getRowFromBuffer() throws KettleFileException {
if (data.rowsOnFile > 0) {
if (data.firstRead) {
// Open the inputstream first...
try {
data.fisToTmpFile = new FileInputStream(data.tempFile);
data.disToTmpFile = new DataInputStream(data.fisToTmpFile);
data.firstRead = false;
} catch (IOException e) {
throw new KettleFileException(BaseMessages.getString(PKG, "GroupBy.Exception.UnableToReadBackRowFromTemporaryFile"), e);
}
}
// Read one row from the file!
Object[] row;
try {
row = data.inputRowMeta.readData(data.disToTmpFile);
} catch (SocketTimeoutException e) {
// Shouldn't happen on files
throw new KettleFileException(e);
}
data.rowsOnFile--;
return row;
} else {
if (data.bufferList.size() > 0) {
Object[] row = data.bufferList.get(0);
data.bufferList.remove(0);
return row;
} else {
// Nothing left!
return null;
}
}
}
use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.
the class GroupBy method closeInput.
private void closeInput() throws KettleFileException {
try {
if (data.fisToTmpFile != null) {
data.fisToTmpFile.close();
data.fisToTmpFile = null;
}
if (data.disToTmpFile != null) {
data.disToTmpFile.close();
data.disToTmpFile = null;
}
} catch (IOException e) {
throw new KettleFileException(BaseMessages.getString(PKG, "GroupBy.Exception.UnableToCloseInputStream", data.tempFile.getPath()), e);
}
}
use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.
the class GroupBy method addToBuffer.
// Method is defined as package-protected in order to be accessible by unit tests
void addToBuffer(Object[] row) throws KettleFileException {
data.bufferList.add(row);
if (data.bufferList.size() > 5000 && data.rowsOnFile == 0) {
String pathToTmp = environmentSubstitute(getMeta().getDirectory());
try {
File ioFile = new File(pathToTmp);
if (!ioFile.exists()) {
// try to resolve as Apache VFS file
pathToTmp = retrieveVfsPath(pathToTmp);
}
data.tempFile = File.createTempFile(getMeta().getPrefix(), ".tmp", new File(pathToTmp));
data.fosToTempFile = new FileOutputStream(data.tempFile);
data.dosToTempFile = new DataOutputStream(data.fosToTempFile);
data.firstRead = true;
} catch (IOException e) {
throw new KettleFileException(BaseMessages.getString(PKG, "GroupBy.Exception.UnableToCreateTemporaryFile"), e);
}
// OK, save the oldest rows to disk!
Object[] oldest = data.bufferList.get(0);
data.inputRowMeta.writeData(data.dosToTempFile, oldest);
data.bufferList.remove(0);
data.rowsOnFile++;
}
}
use of org.pentaho.di.core.exception.KettleFileException in project pentaho-kettle by pentaho.
the class GroupBy method closeOutput.
private void closeOutput() throws KettleFileException {
try {
if (data.dosToTempFile != null) {
data.dosToTempFile.close();
data.dosToTempFile = null;
}
if (data.fosToTempFile != null) {
data.fosToTempFile.close();
data.fosToTempFile = null;
}
data.firstRead = true;
} catch (IOException e) {
throw new KettleFileException(BaseMessages.getString(PKG, "GroupBy.Exception.UnableToCloseInputStream", data.tempFile.getPath()), e);
}
}
Aggregations