use of org.apache.hop.core.exception.HopFileException in project hop by apache.
the class AbstractFileErrorHandler method getWriter.
/**
* returns the OutputWiter if exists. Otherwhise it will create a new one.
*
* @return
* @throws HopException
*/
Writer getWriter(Object source) throws HopException {
try {
Writer outputStreamWriter = writers.get(source);
if (outputStreamWriter != null) {
return outputStreamWriter;
}
FileObject file = getReplayFilename(destinationDirectory, processingFilename, dateString, fileExtension, source);
ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, file, baseTransform.getPipelineMeta().getName(), baseTransform.getTransformName());
baseTransform.addResultFile(resultFile);
try {
if (encoding == null) {
outputStreamWriter = new OutputStreamWriter(HopVfs.getOutputStream(file, false));
} else {
outputStreamWriter = new OutputStreamWriter(HopVfs.getOutputStream(file, false), encoding);
}
} catch (Exception e) {
throw new HopException(BaseMessages.getString(PKG, "AbstractFileErrorHandler.Exception.CouldNotCreateFileErrorHandlerForFile") + file.getName().getURI(), e);
}
writers.put(source, outputStreamWriter);
return outputStreamWriter;
} catch (HopFileException e) {
throw new HopException(BaseMessages.getString(PKG, "AbstractFileErrorHandler.Exception.CouldNotCreateFileErrorHandlerForFile"), e);
}
}
use of org.apache.hop.core.exception.HopFileException in project hop by apache.
the class ActionFoldersCompare method equalFileContents.
/**
* Check whether 2 files have the same contents.
*
* @param file1 first file to compare
* @param file2 second file to compare
* @return true if files are equal, false if they are not
* @throws IOException upon IO problems
*/
protected boolean equalFileContents(FileObject file1, FileObject file2) throws HopFileException {
// Really read the contents and do comparisons
DataInputStream in1 = null;
DataInputStream in2 = null;
try {
// Really read the contents and do comparisons
in1 = new DataInputStream(new BufferedInputStream(HopVfs.getInputStream(HopVfs.getFilename(file1))));
in2 = new DataInputStream(new BufferedInputStream(HopVfs.getInputStream(HopVfs.getFilename(file2))));
char ch1;
char ch2;
while (in1.available() != 0 && in2.available() != 0) {
ch1 = (char) in1.readByte();
ch2 = (char) in2.readByte();
if (ch1 != ch2) {
return false;
}
}
if (in1.available() != in2.available()) {
return false;
} else {
return true;
}
} catch (IOException e) {
throw new HopFileException(e);
} finally {
if (in1 != null) {
try {
in1.close();
} catch (IOException ignored) {
// Nothing to see here...
}
}
if (in2 != null) {
try {
in2.close();
} catch (Exception ignored) {
// We can't do anything else here...
}
}
}
}
use of org.apache.hop.core.exception.HopFileException in project hop by apache.
the class DbCache method saveCache.
public void saveCache() throws HopFileException {
try {
// Serialization support for the DB cache
//
String filename = getFilename();
File file = new File(filename);
if (!file.exists() || file.canWrite()) {
try (FileOutputStream fos = new FileOutputStream(file);
DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(fos, 10000))) {
int counter = 0;
Enumeration<DbCacheEntry> keys = cache.keys();
while (keys.hasMoreElements()) {
// Save the database cache entry
DbCacheEntry entry = keys.nextElement();
entry.write(dos);
// Save the corresponding row as well.
IRowMeta rowMeta = get(entry);
if (rowMeta != null) {
rowMeta.writeMeta(dos);
counter++;
} else {
throw new HopFileException("The database cache contains an empty row. We can't save this!");
}
}
log.logDetailed("We wrote " + counter + " cached rows to the database cache!");
} catch (Exception e) {
throw new Exception(e);
}
} else {
throw new HopFileException("We can't write to the cache file: " + filename);
}
} catch (Exception e) {
throw new HopFileException("Couldn't write to the database cache", e);
}
}
use of org.apache.hop.core.exception.HopFileException in project hop by apache.
the class HopImportBase method setValidateInputFolder.
@Override
public void setValidateInputFolder(String inputFolderName) throws HopException {
try {
inputFolder = HopVfs.getFileObject(inputFolderName);
if (!inputFolder.exists() || !inputFolder.isFolder()) {
throw new HopException("input folder '" + inputFolderName + "' doesn't exist or is not a folder.");
}
this.inputFolderName = inputFolder.getName().getURI();
} catch (Exception e) {
throw new HopFileException("Error verifying input folder " + inputFolderName, e);
}
}
use of org.apache.hop.core.exception.HopFileException in project hop by apache.
the class CubeInput method init.
@Override
public boolean init() {
if (super.init()) {
try {
String filename = resolve(meta.getFilename());
// Add filename to result filenames ?
if (meta.isAddResultFile()) {
ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, HopVfs.getFileObject(filename), getPipelineMeta().getName(), toString());
resultFile.setComment("File was read by a Cube Input transform");
addResultFile(resultFile);
}
data.fis = HopVfs.getInputStream(filename);
data.zip = new GZIPInputStream(data.fis);
data.dis = new DataInputStream(data.zip);
try {
data.meta = new RowMeta(data.dis);
return true;
} catch (HopFileException kfe) {
logError(BaseMessages.getString(PKG, "CubeInput.Log.UnableToReadMetadata"), kfe);
return false;
}
} catch (Exception e) {
logError(BaseMessages.getString(PKG, "CubeInput.Log.ErrorReadingFromDataCube"), e);
}
}
return false;
}
Aggregations