Hello
I finally imported the commons-compress-1.12.jar and created a java service
here is the code I used :
The inputs are inputStream (the document in bytes) and tarFileName (the name of the file IN the tar.gz)
return a bytes array which is the compressed content.
package xxxxx;
import com.wm.data.*;
import com.wm.util.Values;
import com.wm.app.b2b.server.Service;
import com.wm.app.b2b.server.ServiceException;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.zip.GZIPOutputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.io.IOUtils;
public final class Compression_SVC
{
/**
* The primary method for the Java service
*
* @param pipeline
* The IData pipeline
* @throws ServiceException
*/
public static final void Compression(IData pipeline) throws ServiceException {
IDataCursor pipelineCursor = pipeline.getCursor();
byte[] inputStream = null;
if ( pipelineCursor.first ( "inputStream" ) ) {
inputStream = (byte[])pipelineCursor.getValue();
} else {
throw new ServiceException("Missing required parameter 'inputStream'");
}
String tarFileName = (String)IDataUtil.get( pipelineCursor, "tarFileName" );
// tar.gz file creation
ByteArrayOutputStream bos = new ByteArrayOutputStream();
TarArchiveOutputStream taos = new TarArchiveOutputStream(bos);
taos.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR);
taos.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
try {
// tar.gz content creation
TarArchiveEntry entry = new TarArchiveEntry(tarFileName);
entry.setSize(inputStream.length);
taos.putArchiveEntry(entry);
// put content in the file
taos.write(inputStream);
// close compressed file
taos.closeArchiveEntry();
IDataCursor pipelineCursor_1 = pipeline.getCursor();
pipelineCursor_1.insertAfter("zippedContent", bos.toByteArray());
pipelineCursor_1.destroy();
} catch (Exception e) {
throw new ServiceException(e);
} finally{
try {
taos.finish();
taos.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// --- <<IS-BEGIN-SHARED-SOURCE-AREA>> ---
// --- <<IS-END-SHARED-SOURCE-AREA>> ---
final static Compression_SVC _instance = new Compression_SVC();
static Compression_SVC _newInstance() { return new Compression_SVC(); }
static Compression_SVC _cast(Object o) { return (Compression_SVC)o; }
}
#webMethods#Integration-Server-and-ESB#webMethods-General