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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations