Search in sources :

Example 1 with SmbFileOutputStream

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);
    }
}
Also used : ResourceOutputStream(lucee.commons.io.res.util.ResourceOutputStream) OutputStream(java.io.OutputStream) ResourceOutputStream(lucee.commons.io.res.util.ResourceOutputStream) SmbFileOutputStream(jcifs.smb.SmbFileOutputStream) IOException(java.io.IOException) SmbFileOutputStream(jcifs.smb.SmbFileOutputStream) SmbFile(jcifs.smb.SmbFile)

Example 2 with SmbFileOutputStream

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>");
}
Also used : SmbFileInputStream(jcifs.smb.SmbFileInputStream) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Message(nl.nn.adapterframework.stream.Message) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) SmbFileInputStream(jcifs.smb.SmbFileInputStream) InputStream(java.io.InputStream) ParameterException(nl.nn.adapterframework.core.ParameterException) IOException(java.io.IOException) SenderException(nl.nn.adapterframework.core.SenderException) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) SmbFileOutputStream(jcifs.smb.SmbFileOutputStream) SmbException(jcifs.smb.SmbException) TimeoutException(nl.nn.adapterframework.core.TimeoutException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) SenderException(nl.nn.adapterframework.core.SenderException) ParameterException(nl.nn.adapterframework.core.ParameterException) SmbFile(jcifs.smb.SmbFile)

Aggregations

IOException (java.io.IOException)2 SmbFile (jcifs.smb.SmbFile)2 SmbFileOutputStream (jcifs.smb.SmbFileOutputStream)2 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 MalformedURLException (java.net.MalformedURLException)1 SmbException (jcifs.smb.SmbException)1 SmbFileInputStream (jcifs.smb.SmbFileInputStream)1 ResourceOutputStream (lucee.commons.io.res.util.ResourceOutputStream)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 ParameterException (nl.nn.adapterframework.core.ParameterException)1 SenderException (nl.nn.adapterframework.core.SenderException)1 TimeoutException (nl.nn.adapterframework.core.TimeoutException)1 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)1 Message (nl.nn.adapterframework.stream.Message)1 Base64InputStream (org.apache.commons.codec.binary.Base64InputStream)1