This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have David & Dawn Griffiths on-line!
See this thread for details.
Win a copy of Head First Android this week in the Android forum!

aadhar sharma

Ranch Hand
+ Follow
since Oct 09, 2006
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by aadhar sharma

I am loosing data when I try to convert a stream to a CharBuffer. The following can be verified from the output below.

I see the code perfectly fine and the following works 99% of the times when the file size is small how ever the data is truncated for huge files. (3,50,000 Lines approx or more)

The behaviour is consistent and the file is cut off every single time from a specific character.

Do the CharBuffer and ByteBuffer have a limitation on the size ? If yes is there a better way to re-write this code and return CharBuffer.

Any help appreciated.

InputStreamReader reader = null;
CharBuffer cbuf = null;
// get the blob to access its length
Blob blob = getBlob(attachment);
int capacity = (int)blob.length();
System.out.println("Capacity is this "+capacity);
System.out.println("Capacity is this long"+blob.length());, "BinaryAttachmentManager getBufferredReader() allocating "+capacity+" buffer with characterset "+charsetName);
cbuf = CharBuffer.allocate(capacity);

BufferedInputStream bis = new BufferedInputStream(blob.getBinaryStream());
if(null!=charsetName) {
reader = new InputStreamReader(bis,charsetName);
} else {
reader = new InputStreamReader(bis);
long start = System.currentTimeMillis();, "BinaryAttachmentManager getBufferredReader() reading Blob bytes into CharBuffer");
int count =;
cbuf.limit(count); //truncate any unused space, "BinaryAttachmentManager getBufferredReader() read "+count+" characters, elapsed="+(System.currentTimeMillis()-start)+" msec");

return cbuf;
------------------------------------------------------------------------------------------Out Put ----------------------------------------------------------------------------

06:34:51,190 INFO BinaryAttachmentManager,main:46 - BinaryAttachmentManager getBufferredReader() allocating 16666465 buffer with characterset null
06:34:51,331 INFO BinaryAttachmentManager,main:46 - BinaryAttachmentManager getBufferredReader() reading Blob bytes into CharBuffer
06:34:53,394 INFO BinaryAttachmentManager,main:46 - BinaryAttachmentManager getBufferredReader() read 16654336 characters, elapsed=2063 msec


10 years ago
Is it possible to update an xml using a SAX parser.

As per my knowledge the sax parser loads the xml in chunks is it still possible to update the xml using sax if yes where can i find a sample example for the same.

My sample code for DOM which works on smaller files is below , I am unable to figure out how the following code needs to be changed so that it can work on files of size 18 MB

static List voList = new ArrayList();

public static void main(String argv[]) {
try {

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new File("c:\\xmlfiles\\first.xml"));

// normalize text representation
System.out.println("Root element of the doc is "
+ doc.getDocumentElement().getNodeName());

NodeList listOfBodies = doc
int totalBodies = listOfBodies.getLength();
System.out.println("Total no of Body Tags are : " + totalBodies);

for (int s = 0; s < listOfBodies.getLength(); s++) {

Node firstPersonNode = listOfBodies.item(s);
// MyIdsVo myIdVo = (MyIdsVo) voList.get(s);
if (firstPersonNode.getNodeType() == Node.ELEMENT_NODE) {

Element firstPersonElement = (Element) firstPersonNode;
NodeList firstNameList = firstPersonElement

Element firstNameElement = (Element) firstNameList.item(0);

// firstNameElement.setTextContent(myIdVo.getAuthCode());

NodeList lastNameList = firstPersonElement
Element lastNameElement = (Element) lastNameList.item(0);

// lastNameElement.setTextContent(myIdVo.getDeviceID());

NodeList textLNList = lastNameElement.getChildNodes();
.println("Last Name : "
+ ((Node) textLNList.item(0))


// set up a transformer
TransformerFactory transfac = TransformerFactory.newInstance();
Transformer trans = transfac.newTransformer();

// create string from xml tree
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
DOMSource source = new DOMSource(doc);
trans.transform(source, result);
String xmlString = sw.toString();

OutputStream f0;
byte buf[] = xmlString.getBytes();
f0 = new FileOutputStream("c:\\xmlfiles\\first.xml");
for (int i = 0; i < buf.length; i++) {
buf = null;
}// end of if clause
} catch (Exception e) {


private void getParameters() {
String str, tmp, tmp1, tmp2, csvFileName = "c:\\Dummy_Devices_3_20000.prn";
StringTokenizer tok;
int lineCount = 0;

try {
FileInputStream fis = new FileInputStream(csvFileName);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
do {
str = br.readLine();
if (str == null) {
// taking tokens based on "," token separator and adding them to
// two vectors
tok = new StringTokenizer(str, ",");
try {
MyIdsVo vo = new MyIdsVo();
tmp = tok.nextToken();
tmp1 = tok.nextToken();
tmp2 = tok.nextToken();
System.out.println(" " + tmp2);

} catch (NoSuchElementException ex) {
} while (true);
} catch (FileNotFoundException fnofe) {
} catch (Exception e) {


12 years ago
There should be some way of reading huge xml files in java

I guess this might not be the way but there should be a way to do it
12 years ago

Code :

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(new File("c:\\xmlfiles\\first.xml"));

I am trying to open an XML file using the above mentioned code and I receive the exception below, I changed my eclipse settings to
C:\eclipse_new\eclipse\eclipse.exe -vmargs -Xms256m -Xmx512M
but even this doesnt help.

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at org.apache.xerces.dom.DeferredDocumentImpl.createChunk(Unknown Source)
at org.apache.xerces.dom.DeferredDocumentImpl.ensureCapacity(Unknown Source)
at org.apache.xerces.dom.DeferredDocumentImpl.createNode(Unknown Source)
at org.apache.xerces.dom.DeferredDocumentImpl.createDeferredTextNode(Unknown Source)
at org.apache.xerces.parsers.AbstractDOMParser.characters(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanContent(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at MySampleCode.main(
12 years ago
Hi Friends,

If I change (update/edit) a Java file in my workspace and do a ANT build the changes are not reflected on the server.

However the JSP changes are reflected.

Is there a way I can update the changes to the server when my server is on.

I am using JBOSS 4.x

I know this can be done when the debugger is on.

12 years ago
Hay Mario Thanks,

This works fine and hence I had put this in my code but then the Quality guy got hold of me when the same date comparision failed.

since you have taken both the Date instances using the cal.set
the result is fine.

But the problem occurs when one date is from the data base and other
is made by cal.set
and then the comparision is made

hope you understand what i am saying

the cal.set has a time lag of few hundred millseconds

Date From Cal.set 1220207400321
Date From the database 1220207400000

see the difference above
13 years ago
Tried doing the same as you have suggested.
I have used the same format cal.set(2008, Calendar.SEPTEMBER, 1);
but still the problem exists

This is like 1==1 returning false.
13 years ago
I was working with the compareDates method to compare 2 dates
for some reason my code returns the getTime() with a difference

The code does not works fine when the dates are same
I have a date object from the database and the second one is created this way

Calendar cal = Calendar.getInstance();
cal.set(2008, 8, 01,0,0,0);
Date dateConstant = cal.getTime();

I know there is a mismatch between the time in milliseconds which causes the failure
I also know after can reslove my problem
but my question is why this difference ?

new date is this 1220207400345
effective date is this 1220207400000

this is my code

private static boolean compareDates(Date effectiveDate)
Calendar cal = Calendar.getInstance();
cal.set(2008, 8, 01);
Date dateConstant = cal.getTime();
if (dateConstant.compareTo(effectiveDate) < 0)
return true;
else if (dateConstant.compareTo(effectiveDate) > 0)
return false;
return true;
13 years ago
Keep on changing the page event

HeaderFooterPageNumber marker2 = new HeaderFooterPageNumber(payload);
Hi All

I am a new user of Itext. Currently I am using Inetsoft StyleReports but we are getting performance issues so we decided to evaluate Itext. I have gone through the docs/api's but still I am a beginner.

In my application we have different reports generated based on user selection(The screen has about 5 checkboxes). Each checkbox generates a particular report and if a user selects multiple checkboxes, a combined report is generated.

Each report has its own header and footer which repeats on every page of that particular document. I have seen there is a PDFTemplate class which can be used to set a template, but my problem is if the user selects multiple checkboxes, then each report will have a different PDFTemplate. I am using a listner which attaches the PDFTemplate to a document in onStartPage() method. How can I attach multiple templates to a document.

One possible solution is to generate all pdf's separately and then combine them at the end, but it is not the best approach keeping performance in mind. What I am planning to do is to pass document object to different methods based on user's selection of checkboxes and generate the report. But I cant find a way to attach different templates.

It would be great if some one sends me an example

Thanks in Advance
Aadhar Sharma
Thanks a Ton Jai

Worked out for me

I am creating a stateless session bean using JBoss 4 server and JDK 6.0

I receive the folowing error when I try to call the EJb from my Java Application

below is the trace i have attached my jboss.xml jndi and ejb-jar.xml.

Exception in thread "main" javax.naming.CommunicationException [Root exception is org.jboss.ejb3.session.BaseSessionRemoteProxy; local class incompatible: stream classdesc serialVersionUID = 8310915813626447181, local class serialVersionUID = 2609262789016232311]
at org.jnp.interfaces.NamingContext.lookup(
at org.jnp.interfaces.NamingContext.lookup(
at javax.naming.InitialContext.lookup(Unknown Source)
at client.Client.main(
Caused by: org.jboss.ejb3.session.BaseSessionRemoteProxy; local class incompatible: stream classdesc serialVersionUID = 8310915813626447181, local class serialVersionUID = 2609262789016232311
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at Source)
at java.rmi.MarshalledObject.get(Unknown Source)
at org.jnp.interfaces.MarshalledValuePair.get(
at org.jnp.interfaces.NamingContext.lookup(
... 3 more

<?xml version="1.0" encoding="UTF-8"?>
<description>JBoss Stateless Session Bean Tutorial</description>
<display-name>JBoss Stateless Session Bean Tutorial</display-name>

<?xml version="1.0"?>

package client;

import java.util.Properties;

import javax.naming.InitialContext;

import stateless.Calculator;
import stateless.CalculatorRemote;

public class Client {
public static void main(String[] args) throws Exception {

Properties p = new Properties();
"org.jboss.naming rg.jnp.interfaces");
p.put("java.naming.provider.url", "localhost:1099");

// System.setProperty("java.naming.factory.initial",
// "org.jnp.interfaces.NamingContextFactory");
// System.setProperty("java.naming.factory.url.pkgs","org.jboss.naming rg.jnp.interfaces");
// System.setProperty("java.naming.provider.url", "localhost:1099");

InitialContext ctx = new InitialContext(p);
Calculator calculator = (Calculator) ctx.lookup("statelessExamples.CalculatorRemote");

System.out.println("1 + 1 = " + calculator.add(1, 1));
System.out.println("1 - 1 = " + calculator.subtract(1, 1));

Thanks and Regards

Aadhar Sharma