📄 ioutil.java
字号:
/**
* Project:ms4j (Message Server for Java)
* Date:2007-3-13
* Authoer : jobsun@gmail.com
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*/
package com.sunjob.ms4j.util;
import java.io.IOException;
import java.io.InputStream;
import java.nio.Buffer;
import java.nio.ByteBuffer;
/**
* @author sunjb
*
*/
public final class IOUtil {
public static byte[] read(InputStream is )
throws IOException
{
/*
int iMax = Integer.parseInt( PropertyUtil.getProperty("ms4j.socket.max.size") );
ByteBuffer bb = ByteBuffer.allocate(iMax);
byte[] b = new byte[1024];
boolean bIsRead = false;
int iLimit = 0;
do
{
int i = 0;
try
{
i = is.read(b);
}catch(IOException e)
{
throw e;
}
if(i > 0)
bIsRead = true;
else
{
System.out.println("Waiting read.");
continue;
}
if(bIsRead)
{
if(i > 0)
{
bb.put(b,0,i);
iLimit += i;
}
if(i < 1024 || i == 0)
break;
}
}while(true);
if(iLimit > iMax)
throw new IOException("Socket Content Size too Larget.");
// int iLen = bb.position();
// byte[] bRead = new byte[iLen];
// bRead = bb.
Buffer buffer = bb.limit(iLimit);
return ;
*/
int iMax = 0;
while(iMax == 0)
{
iMax = is.available();
}
//int iMax = Integer.parseInt( PropertyUtil.getProperty("ms4j.socket.max.size") );
ByteBuffer bb = ByteBuffer.allocate(iMax);
byte[] b = new byte[1024];
boolean bIsRead = false;
do
{
int i = 0;
try
{
i = is.read(b);
}catch(IOException e)
{
throw e;
}
if(i > 0)
{
bIsRead = true;
}
else
{
System.out.println("Waiting read.");
continue;
}
if(bIsRead)
{
if(i > 0)
{
bb.put(b,0,i);
}
if(i < 1024 || i == 0)
{
break;
}
}
}while(true);
return bb.array();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -