use of jcifs.smb.SmbFileOutputStream in project Lucee by lucee.
the class SMBResource method getOutputStream.
@Override
public OutputStream getOutputStream(boolean append) throws IOException {
ResourceUtil.checkGetOutputStreamOK(this);
try {
provider.lock(this);
SmbFile file = _file();
OutputStream os = new SmbFileOutputStream(file, append);
return IOUtil.toBufferedOutputStream(new ResourceOutputStream(this, os));
} catch (IOException e) {
provider.unlock(this);
// just in case it is an SmbException too... for cfcatch type="java.io.IOException"
throw new IOException(e);
}
}
use of jcifs.smb.SmbFileOutputStream in project iaf by ibissource.
the class SambaSenderOld method sendMessage.
@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
ParameterValueList pvl = null;
try {
if (paramList != null) {
pvl = paramList.getValues(message, session);
}
} catch (ParameterException e) {
throw new SenderException(getLogPrefix() + "Sender [" + getName() + "] caught exception evaluating parameters", e);
}
SmbFile file;
try {
file = new SmbFile(smbContext, message.asString());
} catch (IOException e) {
throw new SenderException(getLogPrefix() + "unable to get SMB file", e);
}
try {
if (getAction().equalsIgnoreCase("download")) {
SmbFileInputStream is = new SmbFileInputStream(file);
InputStream base64 = new Base64InputStream(is, true);
return new Message(Misc.streamToString(base64));
} else if (getAction().equalsIgnoreCase("list")) {
return new Message(listFilesInDirectory(file));
} else if (getAction().equalsIgnoreCase("upload")) {
Message paramValue = pvl.getParameterValue("file").asMessage();
try (SmbFileOutputStream out = new SmbFileOutputStream(file)) {
out.write(paramValue.asByteArray());
}
return new Message(getFileAsXmlBuilder(new SmbFile(smbContext, message.asString())).toXML());
} else if (getAction().equalsIgnoreCase("delete")) {
if (!file.exists())
throw new SenderException("file not found");
if (file.isFile())
file.delete();
else
throw new SenderException("trying to remove a directory instead of a file");
} else if (getAction().equalsIgnoreCase("mkdir")) {
if (isForced())
file.mkdirs();
else
file.mkdir();
} else if (getAction().equalsIgnoreCase("rmdir")) {
if (!file.exists())
throw new SenderException("folder not found");
if (file.isDirectory())
file.delete();
else
throw new SenderException("trying to remove a file instead of a directory");
} else if (getAction().equalsIgnoreCase("rename")) {
String destination = pvl.getParameterValue("destination").asStringValue();
if (destination == null)
throw new SenderException("unknown destination[+destination+]");
SmbFile dest = new SmbFile(smbContext, destination);
if (isForced() && dest.exists())
dest.delete();
file.renameTo(dest);
}
} catch (Exception e) {
// Different types of SMB exceptions can be thrown, no exception means success.. Got to catch them all!
throw new SenderException(getLogPrefix() + "unable to process action for SmbFile [" + file.getCanonicalPath() + "]", e);
}
return new Message("<result>ok</result>");
}
Aggregations