troubleshooting Question

StringIndexOutOfBoundsException

Avatar of bachra04
bachra04Flag for Canada asked on
Java
8 Comments2 Solutions660 ViewsLast Modified:
Hi Experts,

I m integrating some open source code into my application :

the following piece of code is generating :

StringIndexOutOfBoundsException

I think the problem is coming from the part inside the for (...)
Anyone with Java expertise can help me why is this exception ?

Thanks

public void sendChunks(InputStream inputStream, String msgId, String contentType, long totalSize) throws MsrpException {
        reportReceived = false;

		if (from == null) {
			throw new MsrpException("From not set");
		}
		
		if (to == null) {
			throw new MsrpException("To not set");
		}
		
		if (connection == null) {
			throw new MsrpException("No connection set");
		}
		
		// Reset cancel transfer flag 
		cancelTransfer = false;
		
		// Send content over MSRP 
		try {
			byte data[] = new byte[MsrpConstants.CHUNK_MAX_SIZE];
			long firstByte = 1;
			long lastByte = 0;
			
			// Send data chunk by chunk
			for (int i = inputStream.read(data); (!cancelTransfer) & (i>-1); i=inputStream.read(data)) {
				// Update upper byte range
				lastByte += i;

				// Send a chunk
				sendMsrpSendRequest(generateTransactionId(), to, from, msgId, contentType, i, data, firstByte, lastByte, totalSize);

				System.out.println("firstByte = "+ firstByte );
				System.out.println("lastByte = "+ lastByte );
				System.out.println("firstByte = "+ totalSize );
				
				//System.out.println("firstByte = "+ firstByte );
				
				// Update lower byte range
				firstByte += i;
				
				if (!cancelTransfer) {
					// Notify event listener
					msrpEventListener.msrpTransferProgress(lastByte, totalSize);
				}
			}
			
			if (cancelTransfer) {
				// Transfer has been aborted
				return;
			}

			// Test if waiting report is needed
			if (successReportOption) {
				// Wait report
				synchronized(reportSemaphore) {
					try {
						reportSemaphore.wait();
					} catch (InterruptedException e) {}
				}
			}
			
            // Notify event listener
            if (reportReceived) {
                msrpEventListener.msrpDataTransfered(msgId);
            } else {
                msrpEventListener.msrpTransferAborted();
            }
		} catch(Exception e) {
		    System.out.println(e.getMessage());
		    
			throw new MsrpException(e.getMessage());
		}
ASKER CERTIFIED SOLUTION
mccarl
IT Business Systems Analyst / Software Developer
Join our community to see this answer!
Unlock 2 Answers and 8 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros