• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

String with null bytes

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
IBM's MQSeries is being used in the following:
MQMessage msg;
int len = 5;
String str = msg.readString(len);
The underlying class for MQMessage is a byte[]. It creates ByteArrayOutputStreams to read from.
What happens is str ends up with a value of null bytes and I get false with the following comparisons:
str.equals(null) results in false
str == null results in false
str.equals( new String() ) results in false
It doesn't appear to be specific to MQSeries but I do not know. Does anyone know of how to solve this in Java so that I can determine if str actually read something in?
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If your saying that 'msg.readString(len)' should not return null, then you need to provide the code for MQMessage.readString(int) so that we can debug it.
 
tony hutcheson
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am sorry. I only have the class files. However, I do not have a problem with it returning null. The problem occurs when it returns a string of 'len' length, but filled with null bytes. So if you get the length of the string it will give you whatever the value of 'len' is, but it will contain all null values. I did not know if this is something about the way that java handles ByteArrayOutputStreams. The only solution that I can think of is creating a string :
nullStr = new String( new byte[len] )
and comparing it thus:
str.equals( nullStr )
although I am not sure that this will work.
 
Mark Savory
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that your trick will work!

 
The harder you work, the luckier you get. This tiny ad brings luck - just not good luck or bad luck.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic