Home > Articles > Programming > Java

  • Print
  • + Share This

Data Access Using ContentConnection

The ContentConnection interface works the same as the StreamConnection interface except that it supplies a few more helpful methods. Of interest here is the getLength() method, which returns the length of the content that's being provided. To make use of this method, declare a ContentConnection variable:

ContentConnection connStream = null;

I'll move the creation of the byte[] array down inside the try{} clause and change three other items:

  1. Typecast the output of the Connector.open() method to a ContentConnection.

  2. Once I have a ContentConnection, call c.getLength() to retrieve the length of the data.

  3. Once this length is available, dynamically create a byte[] array of that size.

These changes can be seen here (everything else remains the same as in the above example):

ConnStream = (ContentConnection)
int len = (int)connStream.getLength();
byte[] b = new byte[len];
  • + Share This
  • 🔖 Save To Your Account

Related Resources

There are currently no related titles. Please check back later.