SubList and Serialization

I was trying to send message to Apache Kafka from a java program. There is a limit on the number of bytes that are being processed by Kafka.

The Java Program that sends the message to Kafka reads from an Excel file and I have problems when reading large files where the total no of bytes exceeded the kafka byte limit. So I decided to chunk the ArrayList by splitting it into equal chunks using the following code



List <> partionList = new LinkedList<<>>();
for(int i =0; i< origList.size(); i += chunkSize) {
      partionList.add(origList.subList(i,i+Math.min(chunkSize, origList.size.size() - i)));
}
for(List<> dataRows: partionList) { KeyedMessage message = new KeyedMessage<>( KAFKA_TOPIC, (key).getBytes(), SerializationUtils .serialize(convertToJsonLogData(dataRows))); kafkaProducer.send(message); }

I got the following error 
org.apache.commons.lang3.SerializationException: java.io.NotSerializableException: java.util.ArrayList$SubList
 at org.apache.commons.lang3.SerializationUtils.serialize(SerializationUtils.java:139)
 at org.apache.commons.lang3.SerializationUtils.serialize(SerializationUtils.java:161)
I got that corrected by changing the below in the first for loop.
I
List -obj-list = new ArrayList -obj-(logDataRows.subList(i, i + Math.min(chunkSize, origList.size.size() - i))); partionList.add(list);

How to add jars in Play Framework

How to add jars in Play Framework

Play framework make use of a build tool known as sbt.

You can list out your dependencies in build.sbt

Declaring a dependency looks like this (defining groupartifact and revision):
"net.sf.opencsv" % "opencsv" % "2.3",

If you use groupID %% artifactID % revision instead of groupID % artifactID % revision (the difference is the double %% after the groupID), sbt will add your project’s Scala version to the artifact name. 

To make sure that the libraries are available in eclipse, you need to execute the eclipse command in the play shell.

For more info refer

https://www.playframework.com/documentation/2.2.x/SBTDependencies



Change Eclipse to use spaces instead of tabs?

By default Eclipse uses Tabs for indentation.


  1. Click Window » Preferences
  2. Expand Java » Code Style
  3. Click Formatter
  4. Click the Edit button
  5. Click the Indentation tab
  6. Under General Settings, set Tab policy to: Spaces only
  7. Click OK to apply the changes.



Hope this helps..

Common JPA explanations

**This is just for reference only, most of the source of these infor is taken from stackoverflow.  When to use eager loading In "one si...

Popular in last 30 days