📄 sharebuffer.java
字号:
/*
* 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -