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