ITeye博客

流控 demo

blueyanghualong · 2011-05-05 23:05 · netmessage · 编程语言 · ITeye · thread · Markdown

http://www.iteye.com/topic/190329

看了下楼主的需求,感觉上面那位仁兄写的太麻烦了,写了一个方法,你看下如何 
public static byte[] read(int speed,InputStream fin) throws IOException{ 
byte[] b = new byte[speed]; 
ByteArrayOutputStream out = new ByteArrayOutputStream(); 
int len = 0; 
while(fin.available() >0){ 
len = fin.read(b); 
out.write(b,0,len); 
try { 
Thread.sleep(1000); 
} catch (InterruptedException e) { 
e.printStackTrace(); 
} 
} 
return out.toByteArray(); 
} 

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。