android开发入门与实践源代码

源代码在线查看: excerptinputstream.java

软件大小: 7821 K
上传用户: 茗笑弑痛
关键词: android 实践 源代码
下载地址: 免注册下载 普通下载 VIP

相关代码

				package net.oauth.client;
				
				import java.io.BufferedInputStream;
				import java.io.IOException;
				import java.io.InputStream;
				
				/** A decorator that retains a copy of the first few bytes of data. */
				public class ExcerptInputStream extends BufferedInputStream
				{
				    /**
				     * A marker that's appended to the excerpt if it's less than the complete
				     * stream.
				     */
				    public static final byte[] ELLIPSIS = " ...".getBytes();
				
				    public ExcerptInputStream(InputStream in) throws IOException {
				        super(in);
				        mark(LIMIT);
				        int total = 0;
				        int read;
				        while ((read = read(excerpt, total, LIMIT - total)) != -1 && ((total += read) < LIMIT));
				        if (total == LIMIT) {
				            // Only add the ellipsis if there are at least LIMIT bytes
				            System.arraycopy(ELLIPSIS, 0, excerpt, total, ELLIPSIS.length);
				        } else {
				            byte[] tmp = new byte[total];
				            System.arraycopy(excerpt, 0, tmp, 0, total);
				            excerpt = tmp;
				        }
				        reset();
				    }
				
				    private static final int LIMIT = 1024;
				    private byte[] excerpt = new byte[LIMIT + ELLIPSIS.length];
				
				    /** The first few bytes of data, plus ELLIPSIS if there are more bytes. */
				    public byte[] getExcerpt()
				    {
				        return excerpt;
				    }
				
				}
							

相关资源