Search in sources :

Example 1 with HopFileException

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);
    }
}
Also used : HopFileException(org.apache.hop.core.exception.HopFileException) HopException(org.apache.hop.core.exception.HopException) OutputStreamWriter(java.io.OutputStreamWriter) FileObject(org.apache.commons.vfs2.FileObject) ResultFile(org.apache.hop.core.ResultFile) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) HopException(org.apache.hop.core.exception.HopException) IOException(java.io.IOException) HopFileException(org.apache.hop.core.exception.HopFileException)

Example 2 with HopFileException

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...
            }
        }
    }
}
Also used : HopFileException(org.apache.hop.core.exception.HopFileException) BufferedInputStream(java.io.BufferedInputStream) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) HopFileException(org.apache.hop.core.exception.HopFileException) HopXmlException(org.apache.hop.core.exception.HopXmlException) IOException(java.io.IOException)

Example 3 with HopFileException

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);
    }
}
Also used : HopFileException(org.apache.hop.core.exception.HopFileException) IRowMeta(org.apache.hop.core.row.IRowMeta) HopEofException(org.apache.hop.core.exception.HopEofException) HopFileException(org.apache.hop.core.exception.HopFileException)

Example 4 with HopFileException

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);
    }
}
Also used : HopFileException(org.apache.hop.core.exception.HopFileException) HopException(org.apache.hop.core.exception.HopException) HopException(org.apache.hop.core.exception.HopException) HopFileException(org.apache.hop.core.exception.HopFileException)

Example 5 with HopFileException

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;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) HopFileException(org.apache.hop.core.exception.HopFileException) RowMeta(org.apache.hop.core.row.RowMeta) ResultFile(org.apache.hop.core.ResultFile) DataInputStream(java.io.DataInputStream) HopEofException(org.apache.hop.core.exception.HopEofException) HopException(org.apache.hop.core.exception.HopException) IOException(java.io.IOException) SocketTimeoutException(java.net.SocketTimeoutException) HopFileException(org.apache.hop.core.exception.HopFileException)

Aggregations

HopFileException (org.apache.hop.core.exception.HopFileException)49 HopException (org.apache.hop.core.exception.HopException)21 IOException (java.io.IOException)16 FileObject (org.apache.commons.vfs2.FileObject)14 SocketTimeoutException (java.net.SocketTimeoutException)8 ResultFile (org.apache.hop.core.ResultFile)7 File (java.io.File)6 HopEofException (org.apache.hop.core.exception.HopEofException)6 DataInputStream (java.io.DataInputStream)4 EOFException (java.io.EOFException)4 GZIPInputStream (java.util.zip.GZIPInputStream)4 FileSystemException (org.apache.commons.vfs2.FileSystemException)4 LocalFile (org.apache.commons.vfs2.provider.local.LocalFile)4 HopTransformException (org.apache.hop.core.exception.HopTransformException)4 HopValueException (org.apache.hop.core.exception.HopValueException)4 IRowMeta (org.apache.hop.core.row.IRowMeta)4 IValueMeta (org.apache.hop.core.row.IValueMeta)4 RowMeta (org.apache.hop.core.row.RowMeta)4 InputStream (java.io.InputStream)3 JarFile (java.util.jar.JarFile)3