Search in sources :

Example 1 with KettleFileNotFoundException

use of org.pentaho.di.core.exception.KettleFileNotFoundException in project pentaho-kettle by pentaho.

the class ValueDataUtil method checksumAdler32.

/**
 * @param metaA
 *   The ValueMetaInterface
 * @param dataA
 *   Filename
 * @param failIfNoFile
 *   Indicates if the transformation should fail if no file is found
 * @return File's Adler32 checksum
 * @throws KettleFileNotFoundException
 */
public static Long checksumAdler32(ValueMetaInterface metaA, Object dataA, boolean failIfNoFile) throws KettleFileNotFoundException {
    long checksum = 0;
    if (dataA == null) {
        return checksum;
    }
    FileObject file = null;
    CheckedInputStream cis = null;
    try {
        file = KettleVFS.getFileObject(dataA.toString());
        throwsErrorOnFileNotFound(file);
        cis = null;
        // Computer Adler-32 checksum
        cis = new CheckedInputStream(KettleVFS.getInputStream(file), new Adler32());
        byte[] buf = new byte[128];
        int readSize = 0;
        do {
            readSize = cis.read(buf);
        } while (readSize >= 0);
        checksum = cis.getChecksum().getValue();
    } catch (KettleFileNotFoundException e) {
        if (failIfNoFile) {
            throw e;
        }
        log.debug(e.getMessage());
    } catch (Exception e) {
        log.debug(e.getMessage());
    } finally {
        IOUtils.closeQuietly(file);
        IOUtils.closeQuietly(cis);
    }
    return checksum;
}
Also used : KettleFileNotFoundException(org.pentaho.di.core.exception.KettleFileNotFoundException) FileObject(org.apache.commons.vfs2.FileObject) CheckedInputStream(java.util.zip.CheckedInputStream) Adler32(java.util.zip.Adler32) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleFileNotFoundException(org.pentaho.di.core.exception.KettleFileNotFoundException)

Example 2 with KettleFileNotFoundException

use of org.pentaho.di.core.exception.KettleFileNotFoundException in project pentaho-kettle by pentaho.

the class ValueDataUtil method loadFileContentInBinary.

/**
 * @param metaA
 *   The ValueMetaInterface
 * @param dataA
 *   Filename
 * @param failIfNoFile
 *   Indicates if the transformation should fail if no file is found
 * @return File's content in binary
 * @throws KettleValueException
 * @throws KettleFileNotFoundException
 */
public static byte[] loadFileContentInBinary(ValueMetaInterface metaA, Object dataA, boolean failIfNoFile) throws KettleValueException, KettleFileNotFoundException {
    if (dataA == null) {
        return null;
    }
    byte[] content = null;
    FileObject file = null;
    InputStream is = null;
    try {
        file = KettleVFS.getFileObject(dataA.toString());
        throwsErrorOnFileNotFound(file);
        is = KettleVFS.getInputStream(file);
        int fileSize = (int) file.getContent().getSize();
        content = Const.createByteArray(fileSize);
        is.read(content, 0, fileSize);
    } catch (KettleFileNotFoundException e) {
        if (failIfNoFile) {
            throw e;
        }
        log.debug(e.getMessage());
    } catch (Exception e) {
        throw new KettleValueException(e);
    } finally {
        IOUtils.closeQuietly(file);
        IOUtils.closeQuietly(is);
    }
    return content;
}
Also used : KettleFileNotFoundException(org.pentaho.di.core.exception.KettleFileNotFoundException) CheckedInputStream(java.util.zip.CheckedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) FileObject(org.apache.commons.vfs2.FileObject) KettleValueException(org.pentaho.di.core.exception.KettleValueException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleFileNotFoundException(org.pentaho.di.core.exception.KettleFileNotFoundException)

Example 3 with KettleFileNotFoundException

use of org.pentaho.di.core.exception.KettleFileNotFoundException in project pentaho-kettle by pentaho.

the class ValueDataUtil method getFileEncoding.

/**
 * Get file encoding.
 *
 * @param metaA
 *          The ValueMetaInterface
 * @param dataA
 *          The value (filename)
 * @param failIfNoFile
 *          Indicates if the transformation should fail if no file is found
 * @return file encoding.
 * @throws KettleFileNotFoundException
 * @throws KettleValueException
 */
public static String getFileEncoding(ValueMetaInterface metaA, Object dataA, boolean failIfNoFile) throws KettleValueException, KettleFileNotFoundException {
    if (dataA == null) {
        return null;
    }
    String encoding = null;
    FileObject file = null;
    try {
        file = KettleVFS.getFileObject(metaA.getString(dataA));
        throwsErrorOnFileNotFound(file);
        encoding = CharsetToolkit.guessEncodingName(file);
    } catch (KettleFileNotFoundException e) {
        if (failIfNoFile) {
            throw e;
        }
        log.debug(e.getMessage());
    } catch (Exception e) {
        throw new KettleValueException(e);
    } finally {
        IOUtils.closeQuietly(file);
    }
    return encoding;
}
Also used : KettleFileNotFoundException(org.pentaho.di.core.exception.KettleFileNotFoundException) FileObject(org.apache.commons.vfs2.FileObject) KettleValueException(org.pentaho.di.core.exception.KettleValueException) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleFileNotFoundException(org.pentaho.di.core.exception.KettleFileNotFoundException)

Example 4 with KettleFileNotFoundException

use of org.pentaho.di.core.exception.KettleFileNotFoundException in project pentaho-kettle by pentaho.

the class ValueDataUtil method checksumCRC32.

/**
 * @param metaA
 *   The ValueMetaInterface
 * @param dataA
 *   Filename
 * @param failIfNoFile
 *   Indicates if the transformation should fail if no file is found
 * @return File's CRC32 checksum
 * @throws KettleFileNotFoundException
 */
public static Long checksumCRC32(ValueMetaInterface metaA, Object dataA, boolean failIfNoFile) throws KettleFileNotFoundException {
    long checksum = 0;
    if (dataA == null) {
        return checksum;
    }
    FileObject file = null;
    CheckedInputStream cis = null;
    try {
        file = KettleVFS.getFileObject(dataA.toString());
        throwsErrorOnFileNotFound(file);
        cis = null;
        // Computer CRC32 checksum
        cis = new CheckedInputStream(KettleVFS.getInputStream(file), new CRC32());
        byte[] buf = new byte[128];
        int readSize = 0;
        do {
            readSize = cis.read(buf);
        } while (readSize >= 0);
        checksum = cis.getChecksum().getValue();
    } catch (KettleFileNotFoundException e) {
        if (failIfNoFile) {
            throw e;
        }
        log.debug(e.getMessage());
    } catch (Exception e) {
        log.debug(e.getMessage());
    } finally {
        IOUtils.closeQuietly(file);
        IOUtils.closeQuietly(cis);
    }
    return checksum;
}
Also used : KettleFileNotFoundException(org.pentaho.di.core.exception.KettleFileNotFoundException) CRC32(java.util.zip.CRC32) FileObject(org.apache.commons.vfs2.FileObject) CheckedInputStream(java.util.zip.CheckedInputStream) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleFileNotFoundException(org.pentaho.di.core.exception.KettleFileNotFoundException)

Example 5 with KettleFileNotFoundException

use of org.pentaho.di.core.exception.KettleFileNotFoundException in project pentaho-kettle by pentaho.

the class ValueDataUtil method isXMLFileWellFormed.

/**
 * Checks an xml file is well formed.
 *
 * @param metaA
 *          The ValueMetaInterface
 * @param dataA
 *          The value (filename)
 * @param failIfNoFile
 *          Indicates if the transformation should fail if no file is found
 * @return true if the file is well formed.
 * @throws KettleFileNotFoundException
 */
public static boolean isXMLFileWellFormed(ValueMetaInterface metaA, Object dataA, boolean failIfNoFile) throws KettleFileNotFoundException {
    if (dataA == null) {
        return false;
    }
    String filename = dataA.toString();
    FileObject file = null;
    try {
        file = KettleVFS.getFileObject(filename);
        throwsErrorOnFileNotFound(file);
        return XMLCheck.isXMLFileWellFormed(file);
    } catch (KettleFileNotFoundException e) {
        if (failIfNoFile) {
            throw e;
        }
        log.debug(e.getMessage());
    } catch (Exception e) {
        log.debug(e.getMessage());
    } finally {
        IOUtils.closeQuietly(file);
    }
    return false;
}
Also used : KettleFileNotFoundException(org.pentaho.di.core.exception.KettleFileNotFoundException) FileObject(org.apache.commons.vfs2.FileObject) FileSystemException(org.apache.commons.vfs2.FileSystemException) KettleValueException(org.pentaho.di.core.exception.KettleValueException) KettleFileNotFoundException(org.pentaho.di.core.exception.KettleFileNotFoundException)

Aggregations

KettleFileNotFoundException (org.pentaho.di.core.exception.KettleFileNotFoundException)8 KettleValueException (org.pentaho.di.core.exception.KettleValueException)7 FileObject (org.apache.commons.vfs2.FileObject)6 FileSystemException (org.apache.commons.vfs2.FileSystemException)6 CheckedInputStream (java.util.zip.CheckedInputStream)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleStepException (org.pentaho.di.core.exception.KettleStepException)2 ArrayList (java.util.ArrayList)1 Adler32 (java.util.zip.Adler32)1 CRC32 (java.util.zip.CRC32)1 ValueMetaInterface (org.pentaho.di.core.row.ValueMetaInterface)1