Search in sources :

Example 26 with IoException

use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.

the class StagingDataWriter method print.

@Override
protected void print(Batch batch, String data) {
    if (log.isDebugEnabled() && data != null) {
        log.debug("Writing staging data: {}", FormatUtils.abbreviateForLogging(data));
    }
    IStagedResource resource = getStagedResource(batch);
    BufferedWriter writer = resource.getWriter(memoryThresholdInBytes);
    try {
        int size = data.length();
        for (int i = 0; i < size; i = i + 1024) {
            int end = i + 1024;
            writer.append(data, i, end < size ? end : size);
        }
    } catch (IOException ex) {
        throw new IoException(ex);
    }
}
Also used : IoException(org.jumpmind.exception.IoException) IStagedResource(org.jumpmind.symmetric.io.stage.IStagedResource) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter)

Example 27 with IoException

use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.

the class StagedResource method getOutputStream.

public OutputStream getOutputStream() {
    try {
        if (outputStream == null) {
            if (file != null && file.exists()) {
                log.warn("We had to delete {} because it already existed", file.getAbsolutePath());
                file.delete();
            }
            file.getParentFile().mkdirs();
            outputStream = new BufferedOutputStream(new FileOutputStream(file));
        }
        return outputStream;
    } catch (FileNotFoundException e) {
        throw new IoException(e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) IoException(org.jumpmind.exception.IoException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 28 with IoException

use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.

the class AppUtils method unzip.

public static void unzip(InputStream in, File toDir) {
    try {
        ZipInputStream is = new ZipInputStream(in);
        ZipEntry entry = null;
        do {
            entry = is.getNextEntry();
            if (entry != null) {
                if (entry.isDirectory()) {
                    File dir = new File(toDir, entry.getName());
                    dir.mkdirs();
                    dir.setLastModified(entry.getTime());
                } else {
                    File file = new File(toDir, entry.getName());
                    if (!file.getParentFile().exists()) {
                        file.getParentFile().mkdirs();
                        file.getParentFile().setLastModified(entry.getTime());
                    }
                    FileOutputStream fos = new FileOutputStream(file);
                    try {
                        IOUtils.copy(is, fos);
                        file.setLastModified(entry.getTime());
                    } finally {
                        IOUtils.closeQuietly(fos);
                    }
                }
            }
        } while (entry != null);
    } catch (IOException e) {
        throw new IoException(e);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) FileOutputStream(java.io.FileOutputStream) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) File(java.io.File)

Example 29 with IoException

use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.

the class FtpDataWriter method sendFiles.

protected void sendFiles() {
    if (fileInfoByTable.size() > 0) {
        try {
            String sftpUri = buildUri();
            FileSystemOptions opts = new FileSystemOptions();
            FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
            SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
            SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 60000);
            Collection<FileInfo> fileInfos = fileInfoByTable.values();
            for (FileInfo fileInfo : fileInfos) {
                FileObject fileObject = manager.resolveFile(sftpUri + "/" + fileInfo.outputFile.getName(), opts);
                FileObject localFileObject = manager.resolveFile(fileInfo.outputFile.getAbsolutePath());
                fileObject.copyFrom(localFileObject, Selectors.SELECT_SELF);
                fileObject.close();
            }
        } catch (FileSystemException e) {
            logger.warn("If you have not configured your ftp connection it should be configured in conf/ftp-extensions.xml");
            throw new IoException(e);
        } catch (Exception e) {
            throw new IoException(e);
        } finally {
            manager.close();
        }
    }
}
Also used : FileSystemException(org.apache.commons.vfs.FileSystemException) IoException(org.jumpmind.exception.IoException) FileObject(org.apache.commons.vfs.FileObject) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) FileSystemException(org.apache.commons.vfs.FileSystemException) FileSystemOptions(org.apache.commons.vfs.FileSystemOptions)

Example 30 with IoException

use of org.jumpmind.exception.IoException in project symmetric-ds by JumpMind.

the class SymmetricPushClient method close.

public BatchAck close() {
    try {
        writer.end(batch, false);
        BufferedReader reader = transport.readResponse();
        String ackString = reader.readLine();
        String ackExtendedString = reader.readLine();
        log.debug("Reading ack: {}", ackString);
        log.debug("Reading extend ack: {}", ackExtendedString);
        List<BatchAck> batchAcks = new HttpTransportManager().readAcknowledgement(ackString, ackExtendedString);
        if (batchAcks.size() > 0) {
            return batchAcks.get(0);
        } else {
            return null;
        }
    } catch (IOException ex) {
        throw new IoException(ex);
    } finally {
        transport.close();
    }
}
Also used : BatchAck(org.jumpmind.symmetric.model.BatchAck) BufferedReader(java.io.BufferedReader) IoException(org.jumpmind.exception.IoException) IOException(java.io.IOException) HttpTransportManager(org.jumpmind.symmetric.transport.http.HttpTransportManager)

Aggregations

IoException (org.jumpmind.exception.IoException)48 IOException (java.io.IOException)41 File (java.io.File)8 Table (org.jumpmind.db.model.Table)8 BufferedReader (java.io.BufferedReader)6 Column (org.jumpmind.db.model.Column)6 BufferedWriter (java.io.BufferedWriter)5 FileInputStream (java.io.FileInputStream)5 FileOutputStream (java.io.FileOutputStream)4 FileWriter (java.io.FileWriter)4 OutputStreamWriter (java.io.OutputStreamWriter)4 IncomingBatch (org.jumpmind.symmetric.model.IncomingBatch)4 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)4 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 SymmetricException (org.jumpmind.symmetric.SymmetricException)3 ProcessInfo (org.jumpmind.symmetric.model.ProcessInfo)3 ProcessInfoKey (org.jumpmind.symmetric.model.ProcessInfoKey)3 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)2 BufferedInputStream (java.io.BufferedInputStream)2