org.jsmpp.util.StrictBufferedInputStream Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jsmpp Show documentation
Show all versions of jsmpp Show documentation
The Java implementation of SMPP protocol (currently supports SMPP v 3.4)
package org.jsmpp.util;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* There were some ongoing bugs related to use of DataInputStream in conjunction
* with BufferedInputStream. Listed below:
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4112757
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4030995
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4401235
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4100022
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4479751
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6192696
*
* This class can be used a drop-in replacement for BufferedInputStream and
* provides a workaround to the faulty behavior in BufferedInputStream.
*
* Adapted from the comment by [email protected] at the URL below:
* http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4030995
*
* @author Shantanu Kumar ([email protected])
*
*/
public class StrictBufferedInputStream extends BufferedInputStream {
public StrictBufferedInputStream(final InputStream in) {
super(in);
}
public StrictBufferedInputStream(final InputStream in, final int size) {
super(in, size);
}
/** Workaround for an unexpected behavior of 'BufferedInputStream'! */
@Override
public int read(final byte[] buffer, final int bufPos, final int length)
throws IOException {
int i = super.read(buffer, bufPos, length);
if ((i == length) || (i == -1))
return i;
int j = super.read(buffer, bufPos + i, length - i);
if (j == -1)
return i;
return j + i;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy