Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!

Mansukhdeep Thind

Ranch Hand
+ Follow
since Jul 27, 2010
Mansukhdeep likes ...
Eclipse IDE Firefox Browser Java
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 Mansukhdeep Thind

Piet Souris wrote:Keep in mind the difference between a reference variable and the object it references. Suppose we have

what will be garbage collected (if at all)?

So once you say p = null, the Point object that was initially created on the heap memory becomes an orphan. So it becomes available for garbage collection.
2 years ago

Campbell Ritchie wrote:I am not happy with that solution. The read() method is really awkward to use, and may give slower performance than readLine() (not certain about performance). I do my level best to avoid read(), so there shou‍ld be a better way to do this with readLine. Why are you not using an XML parser? Can you check whether each line is closed with a tag corresponding to its opening tag, and if not concatenate two lines?

I'm using the JAXB methodology to unmarshal the XML. Makes life easier than using a SAX/DOM parser. I made sure that the XML is formatted properly and that all the tags are properly closed. That didn't resolve the issue either. I understand your concern of not using read(). But I couldn't for the life of me , figure out why it was unnecessarily taking a space for a line feed and appending it to the StringBuilder.

Tony Docherty wrote:I suggest you add a System.out.println() statement to print out the value of 'line' before you add it to docContent. This will show if your symptom-category tag contains a newline char as Paul suspects is the case.
However, If it is prints out that line as one line without the space between the tags then you need to check in your xml file to see what character that whitespace character actually is - it clearly isn't a standard ASCII space character. Write some code to read in that line byte by byte and dump the byte values to the console, an ASCII space is 20H.

I replaced the readLine() with read(). Reading character by character resolved the issue. It was reading a single line in the XML as 2 separate lines. Thank you for you suggestions everyone.

Paul Clapham wrote:One thing I notice is that your posted code reads the input, line by line, and appends the line to some object, dropping the line-feed characters between the lines. So if a fragment of your XML looked like this:

then that object would contain this substring:

<Tag attr1="val1"attr2="val2">

Which is indeed not valid XML. There's no reason to drop the line-feed characters from your XML, the parser will deal with them appropriately, and as you can see it's possible that dropping them makes the XML malformed. So I'd start by not doing that any more.

That's what's happening, it is, indeed, taking that single line of the XML as 2 separate line and then appending it in the string buffer. But I'm still trying to figure out why. Cause I already spaced the line properly in the XML.
3 years ago
This is the part of the XMl that's causing the issue, the symptom-category tag. It has 2 attributes and there is a whitespace between value of first and name of second one.

Why should it then concatenate it while reading and give me :

(no space)
3 years ago
Hi there

Have been caught in this frustrating problem for a couple of days now. I'm attempting to read from a buffered stream which has code something on the lines of :

The stream is basically an XML file with attributes and their values. The problem is that when it reaches a particular tag which has 2 attribute=value pairs, for ex, <Tag attr1=val1 attr2=val2> </Tag> , it concatenates the value of the first attribute and the name of the second attribute when reading that line, so it becomes <Tag attr1=val1attr2=val2></Tag> And when parsing that XML string using JAXB, the unmarshalling API spits out an exception saying that the element <Tag> must be followed by /> or attribute.

Any ideas?
3 years ago
Hi all

I have a use case wherein I want to do something on the line of -

delete from table1 inner join table2 ON table1.column1 = table2.column2 where table1.col2 = ? and table1.col3 = ?, table2.column3 IN (?,?,?,?....) ;

I want to use this in a PreparedStatement in Java code with multiple AND conditions. I tried quite a few things but nothing seems to work. This is a link that followed :

Any guidance would be appreciated!

It's simple Robert. getWorker(final int) method returns a Worker type that is fetched by implementing the Worker interface as an anonymous inner class when you say:

What's the exact confusion?
6 years ago
There are some things you can control and some things that you can't control. I suggest that you change your flat.
7 years ago