我有一台服务器,出于某些原因和实验,我想减慢它的速度
long length = fileToSend.length();
byte [] longBytes = new byte[8];
ByteBuffer bbuffer = ByteBuffer.wrap(longBytes);
bbuffer.putLong(length);
connectionSocket.getOutputStream().write(longBytes);
BufferedOutputStream bout = new BufferedOutputStream(connectionSocket.getOutputStream());
BufferedInputStream bain = new BufferedInputStream(new FileInputStream(fileToSend));
byte buffer [] = new byte [1024];
int i = 0;
while((i = bain.read(buffer, 0, 1024)) >= 0){
bout.write(buffer, 0, i);
}
System.out.println("chunk sended");
bout.close();
bain.close();
我有一些想法使用线程睡眠之类的东西!但我现在不知道它是否足够和好的解决方案!有人可以指导我如何做到这一点