sharebuffer.java
来自「一个代理服务器的源码实现 本例中HTTP代理服务器默认于8000端口建立代理服」· Java 代码 · 共 83 行
JAVA
83 行
/*
* Created on 2004-12-30
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
* @author mq
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class ShareBuffer {
byte buffer[] = new byte[1024*20];
boolean isempty;
int len;
public ShareBuffer()
{
isempty = false;
len = 0;
}
public synchronized void fetchData(byte[] b)
{
if(isempty)
{
try
{
System.out.println("接收数据线程阻塞");
wait();
}
catch (Exception e)
{
//
}
}
if(!isempty)
{
isempty = true;
System.out.println("接收数据");
System.arraycopy(buffer,0,b,0,buffer.length);
notifyAll();
}
return ;
}
public synchronized void saveData(byte[] b)
{
if(!isempty)
{
try
{
System.out.println("发送数据线程阻塞");
wait();
}
catch (Exception e)
{
//
}
}
if(isempty)
{
isempty = false;
System.out.println("发送数据");
System.arraycopy(b,0,buffer,0,buffer.length);
notifyAll();
}
return ;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?