当前位置: 首页>>代码示例>>Java>>正文


Java BufferedInputStream.reset方法代码示例

本文整理汇总了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());
    }
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:21,代码来源:BufferedInputStreamResetTest.java

示例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);
    }
 
开发者ID:nichbar,项目名称:Aequorea,代码行数:23,代码来源:BitmapWrapper.java

示例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");
}
 
开发者ID:axlecho,项目名称:tuxguitar,代码行数:23,代码来源:TGSongLoaderHelper.java

示例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);
}
 
开发者ID:aws,项目名称:aws-sdk-java-v2,代码行数:17,代码来源:BufferedInputStreamResetTest.java

示例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());
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:20,代码来源:BufferedInputStreamResetTest.java

示例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;
}
 
开发者ID:IngSW-unipv,项目名称:Progetto-C,代码行数:32,代码来源:CompositeImageData.java

示例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);
   }
}
 
开发者ID:wellsb1,项目名称:fort_j,代码行数:34,代码来源:Xml.java

示例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();
    }
}
 
开发者ID:gimportexportdevs,项目名称:gexporter,代码行数:34,代码来源:Gpx2Fit.java

示例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;
    }
}
 
开发者ID:pascalgn,项目名称:jiracli,代码行数:16,代码来源:HttpClient.java

示例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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:HttpAwareServerSocket.java

示例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;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:12,代码来源:Utils.java

示例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.
  }
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:33,代码来源:Connection.java

示例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");
}
 
开发者ID:LogisimIt,项目名称:Logisim,代码行数:15,代码来源:LogisimFile.java

示例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);
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:16,代码来源:BufferedInputStreamResetTest.java

示例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;
}
 
开发者ID:spennihana,项目名称:FasterWordEmbeddings,代码行数:19,代码来源:ComparisonUtils.java


注:本文中的java.io.BufferedInputStream.reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。