本文整理汇总了Java中java.io.BufferedInputStream.reset方法的典型用法代码示例。如果您正苦于以下问题:Java BufferedInputStream.reset方法的具体用法?Java BufferedInputStream.reset怎么用?Java BufferedInputStream.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.BufferedInputStream
的用法示例。
在下文中一共展示了BufferedInputStream.reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNegative
import java.io.BufferedInputStream; //导入方法依赖的package包/类
private void testNegative(final int readLimit) throws IOException {
byte[] bytes = new byte[100];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) i;
}
// buffer of 10 bytes
BufferedInputStream bis =
new BufferedInputStream(new ByteArrayInputStream(bytes), 10);
// skip 10 bytes
bis.skip(10);
bis.mark(readLimit); // 1 byte short in buffer size
// read 30 bytes in total, with internal buffer incread to 20
bis.read(new byte[20]);
try {
bis.reset();
fail();
} catch (IOException ex) {
assertEquals("Resetting to invalid mark", ex.getMessage());
}
}
示例2: decodeBitmap
import java.io.BufferedInputStream; //导入方法依赖的package包/类
private static Bitmap decodeBitmap(InputStream inputStream, Rect rect) {
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
if (rect != null) {
options.inJustDecodeBounds = true;
bufferedInputStream.mark(MARK_POSITION);
BitmapFactory.decodeStream(bufferedInputStream, null, options);
try {
bufferedInputStream.reset();
} catch (IOException e) {
Debug.e(e);
}
options.inJustDecodeBounds = false;
options.inSampleSize = AbstractImageLoader.getSampleSize(options.outWidth, options.outHeight, rect.width(), rect.height());
}
return BitmapFactory.decodeStream(bufferedInputStream, null, options);
}
示例3: load
import java.io.BufferedInputStream; //导入方法依赖的package包/类
public void load(TGSongLoaderHandle handle) throws TGFileFormatException{
try{
BufferedInputStream stream = new BufferedInputStream(handle.getInputStream());
stream.mark(1);
Iterator<TGInputStreamBase> it = TGFileFormatManager.getInstance(this.context).getInputStreams();
while(it.hasNext() && handle.getSong() == null){
TGInputStreamBase reader = (TGInputStreamBase)it.next();
reader.init(handle.getFactory(),stream);
if( reader.isSupportedVersion() ){
handle.setSong(reader.readSong());
handle.setFormat(reader.getFileFormat());
return;
}
stream.reset();
}
stream.close();
} catch(Throwable throwable) {
throw new TGFileFormatException(throwable);
}
throw new TGFileFormatException("Unsupported file format");
}
示例4: testPositive
import java.io.BufferedInputStream; //导入方法依赖的package包/类
private void testPositive(final int readLimit) throws IOException {
byte[] bytes = new byte[100];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) i;
}
// buffer of 10 bytes
BufferedInputStream bis =
new BufferedInputStream(new ByteArrayInputStream(bytes), 10);
// skip 10 bytes
bis.skip(10);
bis.mark(readLimit); // buffer size would increase up to readLimit
// read 30 bytes in total, with internal buffer increased to 20
bis.read(new byte[20]);
bis.reset();
assert (bis.read() == 10);
}
示例5: testNegative
import java.io.BufferedInputStream; //导入方法依赖的package包/类
private void testNegative(final int readLimit) throws IOException {
byte[] bytes = new byte[100];
for (int i=0; i < bytes.length; i++)
bytes[i] = (byte)i;
// buffer of 10 bytes
BufferedInputStream bis =
new BufferedInputStream(new ByteArrayInputStream(bytes), 10);
// skip 10 bytes
bis.skip(10);
bis.mark(readLimit); // 1 byte short in buffer size
// read 30 bytes in total, with internal buffer incread to 20
bis.read(new byte[20]);
try {
bis.reset();
fail();
} catch(IOException ex) {
assertEquals("Resetting to invalid mark", ex.getMessage());
}
}
示例6: loadImage
import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
* @see org.newdawn.slick.opengl.LoadableImageData#loadImage(java.io.InputStream, boolean, boolean, int[])
*/
public ByteBuffer loadImage(InputStream is, boolean flipped, boolean forceAlpha, int[] transparent) throws IOException {
CompositeIOException exception = new CompositeIOException();
ByteBuffer buffer = null;
BufferedInputStream in = new BufferedInputStream(is, is.available());
in.mark(is.available());
// cycle through our source until one of them works
for (int i=0;i<sources.size();i++) {
in.reset();
try {
LoadableImageData data = (LoadableImageData) sources.get(i);
buffer = data.loadImage(in, flipped, forceAlpha, transparent);
picked = data;
break;
} catch (Exception e) {
Log.warn(sources.get(i).getClass()+" failed to read the data", e);
exception.addException(e);
}
}
if (picked == null) {
throw exception;
}
return buffer;
}
示例7: loadXml
import java.io.BufferedInputStream; //导入方法依赖的package包/类
@ApiMethod
public static Document loadXml(InputStream stream)
{
String docText = null;
try
{
int buffSize = 2048;
BufferedInputStream buff = new BufferedInputStream(stream, buffSize);
byte[] debug = new byte[buffSize];
buff.mark(buffSize);
buff.read(debug);
docText = new String(debug);
docText = docText.trim();
buff.reset();
stream = buff;
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(stream);
doc.getDocumentElement().normalize();
return doc;
}
catch (Exception ex)
{
String msg = "Unable to parse document: " + ex.getMessage();
if (docText != null)
msg += "\r\n" + docText;
throw new RuntimeException(msg);
}
}
示例8: Gpx2Fit
import java.io.BufferedInputStream; //导入方法依赖的package包/类
public Gpx2Fit(String name, InputStream in, Gpx2FitOptions options) throws Exception {
mGpx2FitOptions = options;
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser parser = factory.newPullParser();
//parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, false);
courseName = name;
BufferedInputStream inputStream = new BufferedInputStream(in);
inputStream.mark(64000);
//FileInputStream in = new FileInputStream(file);
try {
parser.setInput(inputStream, null);
parser.nextTag();
readGPX(parser);
inputStream.close();
return;
} catch (Exception e) {
ns = HTTP_WWW_TOPOGRAFIX_COM_GPX_1_0;
Log.debug("Ex {}", e);
}
inputStream.reset();
try {
parser.setInput(inputStream, null);
parser.nextTag();
readGPX(parser);
} finally {
inputStream.close();
}
}
示例9: maybeDecompress
import java.io.BufferedInputStream; //导入方法依赖的package包/类
private static InputStream maybeDecompress(InputStream input) throws IOException {
// Due to a bug, Jira sometimes returns double-compressed responses. See JRA-37608
BufferedInputStream buffered = new BufferedInputStream(input, 2);
buffered.mark(2);
int[] buf = new int[2];
buf[0] = buffered.read();
buf[1] = buffered.read();
buffered.reset();
int header = (buf[1] << 8) | buf[0];
if (header == GZIPInputStream.GZIP_MAGIC) {
return new GZIPInputStream(buffered);
} else {
return buffered;
}
}
示例10: accept
import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
* Accept a connection. This method will block until the connection
* is made and four bytes can be read from the input stream.
* If the first four bytes are "POST", then an HttpReceiveSocket is
* returned, which will handle the HTTP protocol wrapping.
* Otherwise, a WrappedSocket is returned. The input stream will be
* reset to the beginning of the transmission.
* In either case, a BufferedInputStream will already be on top of
* the underlying socket's input stream.
* @exception IOException IO error when waiting for the connection.
*/
public Socket accept() throws IOException
{
Socket socket = super.accept();
BufferedInputStream in =
new BufferedInputStream(socket.getInputStream());
RMIMasterSocketFactory.proxyLog.log(Log.BRIEF,
"socket accepted (checking for POST)");
in.mark(4);
boolean isHttp = (in.read() == 'P') &&
(in.read() == 'O') &&
(in.read() == 'S') &&
(in.read() == 'T');
in.reset();
if (RMIMasterSocketFactory.proxyLog.isLoggable(Log.BRIEF)) {
RMIMasterSocketFactory.proxyLog.log(Log.BRIEF,
(isHttp ? "POST found, HTTP socket returned" :
"POST not found, direct socket returned"));
}
if (isHttp)
return new HttpReceiveSocket(socket, in, null);
else
return new WrappedSocket(socket, in, null);
}
示例11: readMagic
import java.io.BufferedInputStream; //导入方法依赖的package包/类
static byte[] readMagic(BufferedInputStream in) throws IOException {
in.mark(4);
byte[] magic = new byte[4];
for (int i = 0; i < magic.length; i++) {
// read 1 byte at a time, so we always get 4
if (1 != in.read(magic, i, 1))
break;
}
in.reset();
return magic;
}
示例12: isReadable
import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
* Returns true if we are confident that we can read data from this
* connection. This is more expensive and more accurate than {@link
* #isAlive()}; callers should check {@link #isAlive()} first.
*/
public boolean isReadable() {
if (!(in instanceof BufferedInputStream)) {
return true; // Optimistic.
}
if (isSpdy()) {
return true; // Optimistic. We can't test SPDY because its streams are in use.
}
BufferedInputStream bufferedInputStream = (BufferedInputStream) in;
try {
int readTimeout = socket.getSoTimeout();
try {
socket.setSoTimeout(1);
bufferedInputStream.mark(1);
if (bufferedInputStream.read() == -1) {
return false; // Stream is exhausted; socket is closed.
}
bufferedInputStream.reset();
return true;
} finally {
socket.setSoTimeout(readTimeout);
}
} catch (SocketTimeoutException ignored) {
return true; // Read timed out; socket is good.
} catch (IOException e) {
return false; // Couldn't read; socket is closed.
}
}
示例13: getFirstLine
import java.io.BufferedInputStream; //导入方法依赖的package包/类
private static String getFirstLine(BufferedInputStream in) throws IOException {
byte[] first = new byte[512];
in.mark(first.length - 1);
in.read(first);
in.reset();
int lineBreak = first.length;
for (int i = 0; i < lineBreak; i++) {
if (first[i] == '\n') {
lineBreak = i;
}
}
return new String(first, 0, lineBreak, "UTF-8");
}
示例14: testPositive
import java.io.BufferedInputStream; //导入方法依赖的package包/类
private void testPositive(final int readLimit) throws IOException {
byte[] bytes = new byte[100];
for (int i=0; i < bytes.length; i++)
bytes[i] = (byte)i;
// buffer of 10 bytes
BufferedInputStream bis =
new BufferedInputStream(new ByteArrayInputStream(bytes), 10);
// skip 10 bytes
bis.skip(10);
bis.mark(readLimit); // buffer size would increase up to readLimit
// read 30 bytes in total, with internal buffer increased to 20
bis.read(new byte[20]);
bis.reset();
assert(bis.read() == 10);
}
示例15: readNextLine
import java.io.BufferedInputStream; //导入方法依赖的package包/类
/**
* Read next line of bytes (cannot use BufferedReader.readLine() since it will do a lossy conversion to a String!)
*
* @param br BufferedInputStream supports mark and reset
* @return the next line in bytes
* @throws IOException
*/
static byte[] readNextLine(BufferedInputStream br) throws IOException {
br.mark(1<<20); // ridiculously large read limit
int nbytes=0;
byte b;
while( (b= (byte)br.read())!=-1 && b!='\r' && b!= '\n' ) nbytes++;
if( nbytes==0 ) return null;
br.reset();
byte[] lineBytes = new byte[nbytes+1]; // always read the LF
br.read(lineBytes);
return lineBytes;
}