Hello,
I created a function that compresses a directory but I don't know how to manage the output stream in order to give the possibility to the user to download this directory! Isomorphic, have you any idea Please ?
here is my code :
I created a function that compresses a directory but I don't know how to manage the output stream in order to give the possibility to the user to download this directory! Isomorphic, have you any idea Please ?
here is my code :
Code:
public String performExport(javax.servlet.http.HttpServletRequest request,javax.servlet.http.HttpServletResponse response,
String p_sBook_ID, String p_sUser_ID, String p_sFormat) {
String sReturn = _Return_OK;
try {
writeServerDebug("performExport(req,resp,'" + p_sBook_ID + "'," + p_sUser_ID + "," + p_sFormat + "):start");
// ====================================================
// = Get the template directory
// ====================================================
FilerManager myFiler = new FilerManager();
String sInputPath = myFiler.getDirectory(
FilerManager.DirectoryKind_Users, true);
// ====================================================
// = Working variables JDBC objects.
// ====================================================
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
String SQL = "";
try {
writeServerDebug("performExport >> START");
// ---------------------------------------------------------
// - Establish the connection.
// ---------------------------------------------------------
con = get_RepositoryBridge().getSourceDataBaseConnection();
} catch (Exception ex) {
sReturn = Repository._Return_KO;
}
HashMap<String, Object> _hCacheBook = new HashMap<String, Object>();
try {
int iSrcCount = get_RepositoryBridge().cacheQueryData(
"SELECT TOP(1) * FROM " + Books.Table + " WHERE "
+ Books.Column_IDNum + "=" + p_sBook_ID,
_hCacheBook, "DataBase_Source");
int iColCount = (Integer) (_hCacheBook.get("SQL_ColumnCount"));
String sColDesc = (String) (_hCacheBook.get("SQL_ColumnDesc"));
String sColValues = (String) (_hCacheBook
.get("SQL_ColumnValues"));
writeServerDebug("performExport:iColCount=" + iColCount);
writeServerDebug("performExport:sColDesc=" + sColDesc);
writeServerDebug("performExport:sColValues=" + sColValues);
int nbrCol = (Integer) (_hCacheBook.get("SQL_ColumnCount"));
ZipOutputStream objx = this.CreatXml(nbrCol, 1, _hCacheBook);
response.setHeader("Content-disposition","attachment;filename=\testJS.zip\"");
String sContentType = "application/vnd.ms-objx";
response.setContentType(sContentType);
ServletOutputStream outStream = response.getOutputStream();
//the problem is here ! I must add a statement to send the compressed directory to the client!
sortie.close();
outStream.flush();
outStream.close();
}
catch (Exception ex) {
System.out.println("I AM IN THE EXCEPTION :");
ex.printStackTrace();
}
}
catch (Exception e) {
writeServerDebug("ERROR:" + e.getLocalizedMessage());
sReturn = Repository._Return_KO;
}
return sReturn;
}
Comment