mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-12-22 10:30:13 +00:00
added help method for reading from streams
This commit is contained in:
parent
54ac5bc64e
commit
b4a4572d97
@ -24,7 +24,7 @@
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: ArrayUtils.java,v 1.2 2009/10/27 09:52:24 fros4943 Exp $
|
||||
* $Id: ArrayUtils.java,v 1.3 2009/10/29 16:48:50 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.util;
|
||||
@ -35,6 +35,9 @@ import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import javax.swing.JFileChooser;
|
||||
|
||||
@ -131,4 +134,20 @@ public class ArrayUtils {
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] readFromStream(InputStream input) {
|
||||
try {
|
||||
int numRead = 0;
|
||||
int offset = 0;
|
||||
byte data[] = new byte[input.available()*2];
|
||||
DataInputStream dataIn = new DataInputStream(input);
|
||||
while ((numRead = dataIn.read(data, offset, data.length-offset)) >= 0) {
|
||||
offset += numRead;
|
||||
}
|
||||
byte[] streamData = new byte[offset];
|
||||
System.arraycopy(data, 0, streamData, 0, offset);
|
||||
return streamData;
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user