Menu
Download Free Trial

Error Calling Compressor.compressString(string)

when I cal the Compressor as follows…

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 the 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.

4 answers

Public
Dmytro Zvazhii Flexmonster August 21, 2017

Hello Dennis,
Thank you for writing. The answers are below: 
1. When using compressString() method, you should pass the entire CSV data string not only column names. 
2. Thank you for reporting the issue. We will add the necessary fix in the nearest minor release ETA Aug28. Please note that the method should work fine when passing the entire data string as the argument.
3. Thank you for your recommendation. We will add the compressString() method example to our documentation.
Please let us know if it works for you.
Best regards,
Dmytro.

Public
Dennis Urech August 21, 2017

When you say entire data string what do you mean?  I cannot pass it the entire content of the data since I am pulling it from the database dynamically

Our code streams each row of CSV data (starting with the header row) one row at a time.  If I continue to try to compress the individual rows of data, I get the same exception. 

Public
Ian Sadovy Flexmonster August 23, 2017

Hello Dennis,
 
Thank you for providing the details.
If you cannot pass the entire content, you should use a different approach by implementing custom reader.
Please take a look at the following sample code:

public class CustomReader extends CSVReader {
private String[] data = {
"Category,Size,Color,Destination,Business Type,Country,Price,Quantity,Discount",
"Accessories,262 oz,red,Australia,Specialty Bike Shop,Australia,174,225,23",
"Accessories,214 oz,yellow,Canada,Specialty Bike Shop,Canada,502,90,17",
"Accessories,147 oz,white,France,Specialty Bike Shop,France,242,855,37",
"Accessories,112 oz,yellow,Germany,Specialty Bike Shop,Germany,102,897,42"
};
private int index = 0;

public CustomReader() {
...
}

@Override
public String readLine() {
if (index < data.length) {
String rowStr = data[index++];
return ProcessRow(rowStr);
}
return null;
}
}

 
As you can see, `readLine()` method is responsible for pulling lines in CSV format. Therefore, you can compress and stream the output as follows:

CustomReader reader = new CustomReader();
InputStream inputStream = new OCSVStream(reader);
...

Full Java sample is available for download.
Please let me know if it works for you.
 
Regards,
Ian

Public
Ian Sadovy Flexmonster August 24, 2017

Hello Dennis,

 
Thank you for providing the code sample.
Actually, an array with data was provided only for demonstration purposes.
Instead of getting data from array, you can use your callback inside the readLine() method.
Does it work?
 
Regards,
Ian

Please login or Register to Submit Answer