Search in sources :

Example 21 with KettleFileException

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);
        }
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) KettleFileException(org.pentaho.di.core.exception.KettleFileException) KettleStepException(org.pentaho.di.core.exception.KettleStepException) RowMeta(org.pentaho.di.core.row.RowMeta) DataInputStream(java.io.DataInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream)

Example 22 with KettleFileException

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;
        }
    }
}
Also used : KettleFileException(org.pentaho.di.core.exception.KettleFileException) SocketTimeoutException(java.net.SocketTimeoutException) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream)

Example 23 with KettleFileException

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);
    }
}
Also used : KettleFileException(org.pentaho.di.core.exception.KettleFileException) IOException(java.io.IOException)

Example 24 with KettleFileException

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++;
    }
}
Also used : KettleFileException(org.pentaho.di.core.exception.KettleFileException) DataOutputStream(java.io.DataOutputStream) FileOutputStream(java.io.FileOutputStream) FileObject(org.apache.commons.vfs2.FileObject) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) IOException(java.io.IOException) File(java.io.File)

Example 25 with KettleFileException

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);
    }
}
Also used : KettleFileException(org.pentaho.di.core.exception.KettleFileException) IOException(java.io.IOException)

Aggregations

KettleFileException (org.pentaho.di.core.exception.KettleFileException)61 IOException (java.io.IOException)32 FileObject (org.apache.commons.vfs2.FileObject)30 KettleException (org.pentaho.di.core.exception.KettleException)25 FileSystemException (org.apache.commons.vfs2.FileSystemException)10 DataInputStream (java.io.DataInputStream)8 File (java.io.File)7 ResultFile (org.pentaho.di.core.ResultFile)7 SocketTimeoutException (java.net.SocketTimeoutException)6 FileInputStream (java.io.FileInputStream)5 InputStream (java.io.InputStream)5 KettleXMLException (org.pentaho.di.core.exception.KettleXMLException)5 BufferedInputStream (java.io.BufferedInputStream)4 InputStreamReader (java.io.InputStreamReader)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 KettleDatabaseException (org.pentaho.di.core.exception.KettleDatabaseException)4 KettleEOFException (org.pentaho.di.core.exception.KettleEOFException)4 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)4 DataOutputStream (java.io.DataOutputStream)3 FileNotFoundException (java.io.FileNotFoundException)3