Search in sources :

Example 1 with Base64InputStream

use of org.apache.commons.codec.binary.Base64InputStream in project tdi-studio-se by Talend.

the class JavaProcessor method generateWSDL.

private void generateWSDL(IFolder wsdlsPackageFolder, INode node) throws CoreException, IOException {
    // retrieve WSDL content (compressed-n-encoded) -> zip-content.-> wsdls.(first named main.wsdl)
    String wsdlContent = node.getElementParameter("WSDL_CONTENT").getValue().toString();
    // String wsdlContent = (String) node.getPropertyValue("WSDL_CONTENT"); //$NON-NLS-1$
    String uniqueName = node.getUniqueName();
    if (null != uniqueName && null != wsdlContent && !wsdlContent.trim().isEmpty()) {
        // configure decoding and uncompressing
        InputStream wsdlStream = new BufferedInputStream(new InflaterInputStream(new Base64InputStream(new ByteArrayInputStream(wsdlContent.getBytes()))));
        if (!wsdlsPackageFolder.exists()) {
            wsdlsPackageFolder.create(true, true, null);
        }
        // generate WSDL file
        if (checkIsZipStream(wsdlStream)) {
            ZipInputStream zipIn = new ZipInputStream(wsdlStream);
            ZipEntry zipEntry = null;
            while ((zipEntry = zipIn.getNextEntry()) != null) {
                String outputName = zipEntry.getName();
                if ("main.wsdl".equals(outputName)) {
                    //$NON-NLS-1$
                    //$NON-NLS-1$
                    outputName = uniqueName + ".wsdl";
                }
                IFile wsdlFile = wsdlsPackageFolder.getFile(outputName);
                if (!wsdlFile.exists()) {
                    // cause create file will do a close. add a warp to ignore close.
                    InputStream unCloseIn = new FilterInputStream(zipIn) {

                        @Override
                        public void close() throws IOException {
                        }

                        ;
                    };
                    wsdlFile.create(unCloseIn, true, null);
                }
                zipIn.closeEntry();
            }
            zipIn.close();
        } else {
            //$NON-NLS-1$
            IFile wsdlFile = wsdlsPackageFolder.getFile(uniqueName + ".wsdl");
            wsdlFile.create(wsdlStream, true, null);
        }
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) FilterInputStream(java.io.FilterInputStream) IFile(org.eclipse.core.resources.IFile) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) ZipInputStream(java.util.zip.ZipInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) FilterInputStream(java.io.FilterInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) ZipEntry(java.util.zip.ZipEntry) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream)

Aggregations

BufferedInputStream (java.io.BufferedInputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1 FilterInputStream (java.io.FilterInputStream)1 InputStream (java.io.InputStream)1 InflaterInputStream (java.util.zip.InflaterInputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 Base64InputStream (org.apache.commons.codec.binary.Base64InputStream)1 IFile (org.eclipse.core.resources.IFile)1