Download Free Trial

Javadoc for flexmonster compressor


Is there any javadoc (or any documentation at all) for the flexmonster CSVCompressor API.  There are only a few examples in your documentation and I cannot find any in the forums.  I am interested in using the compressor, but need some addition information to try and figure out how to integrate it with our Java application that currently extracting the data from MongoDB, transforming the data to csv format and streaming it out one record at a time to the Response object’s PrintWiter (text-stream)

9 answers

Tanya Gryshko Flexmonster August 10, 2017

Hi Dennis,

Unfortunately, we don’t have a detailed description of CSVCompressor API, but it doesn’t have a complicated structure.
Please find all supported method below:

Compression for CSV files

InputStream compressFile(String fileName, char delimiter)
InputStream compressFile(String fileName)

Compression for strings in CSV format

InputStream compressString(String string, char delimiter)
InputStream compressString(String string)

Compression for streams

InputStream compressStream(InputStream inputStream, char delimiter)
InputStream compressStream(InputStream inputStream)

Compression for Databases

InputStream compressDb(ResultSet resultSet)


import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.flexmonster.compressor.Compressor;
public class CompressorServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
  try {
    Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/foodmart", "root", "password");
    String query = "SELECT * FROM customer";
    Statement statement = connection.createStatement();
    ResultSet resultSet = statement.executeQuery(query);

    InputStream inputStream = Compressor.compressDb(resultSet);
     //InputStream inputStream = Compressor.compressFile(this.getServletContext().getRealPath("/WEB-INF/data.csv"));

    OutputStream outputStream = response.getOutputStream();
     byte[] buffer = new byte[10240];
    int length = 0;
    while ((length = > 0) {
      outputStream.write(buffer, 0, length);
   } catch (Exception e) {


Dennis Urech August 10, 2017

I am using MongDB, am performing a query and when the resultset is returned, I am processing each record, converting it to csv format and writing it to the HttpServletResponse outstream via ‘out.println(csvData);’  So I would assume I would use the Compressors for strings
InputStream compressString(String string) to compress the csvData and then use the standard out.write(); out.flush() loop as you have documented.  However, wouldn’t I need to change the response.setContentType to “application/octet-stream”

Tanya Gryshko Flexmonster August 11, 2017

Hi Dennis,

I think in your case it would be enough to set content-type as "text/plain".
Please ask me if you need more help.


Dennis Urech August 18, 2017

when I call…

InputStream in = Compresor.compressString(columnNames); 

where columnNames is a string of comma separated CSV column names (e.g. “ID,Name,Date,Time,Source,Severity,Category,Favorite”), I get an UnsupportedEncodingException:uft8
Note the “UFT8”.  I think you have a typo in your code.  You probably meant “UTF8”. Assuming this is issue and since you have not provided the source, I am unable to to use the Compressor until this code is corrected. 
By the way, it would be nice to document an example of using the “compressString()” method.  The only examples I can find are compressDB and compressFile.

Dmytro Zvazhii Flexmonster August 22, 2017

Please find the answer to the question in the following thread:

SImba January 29, 2018

Hello ~
I try to use mybatis Access database use this java compressor API and the parameters of this method【Compressor.compressDb(resultSet)】 is ResultSet type.
But the type returned by mybatis is List , so failed.
After , I use the 【Compressor.compressString(input) 】 method, foreach the list and append all string, it’s work!
but this is too slow,Is there any better way?

Dmytro Zvazhii Flexmonster January 29, 2018

Hello Simba, 
Thank you for writing. Yes, you are right, compressing string data is no a very efficient solution. However, we recommend using the ResultSet since it should provide much better performance. As we can see it, the MyBatis is a framework which works over the JDBC level, therefore the ResultSet should be available there. The idea is to path non-mapped data to the compressor. Seems it can be done the following way –
Please let us know if the suggested approach solves the case.

SImba January 30, 2018

Thank you for your reply. 
【The idea is to path non-mapped data to the compressor】,what non-mapped data mean?
Mybatis put executive sql and returntype in xml,like this:

  1.     <select id=“selectUser” resultType=“Integer”>  
  2.         SELECT user_id FROM sys_user 
  3.     </select>  

and I try set this resultType=Resultset ,it is doesn’t work .
Looking forward to your reply .

Dmytro Zvazhii Flexmonster January 30, 2018

Hello Simba,
Getting non-mapped data means that you should get the object which contains metadata and query result. The possible solution is to write the necessary query using JDBC connector. You can find the tutorial in our documentation – The other approach is to get ResultSet when using MyBatis. Please find the possible solution here – You need to implement TypeHandlerCallback interface and then call from ResultGetter object getResultSet() method – After that you can pass ResultSet object to the compressor.

Please login or Register to Submit Answer