diff --git a/tools/cooja/java/se/sics/cooja/util/ArrayUtils.java b/tools/cooja/java/se/sics/cooja/util/ArrayUtils.java index 05f610579..a54d93fd1 100644 --- a/tools/cooja/java/se/sics/cooja/util/ArrayUtils.java +++ b/tools/cooja/java/se/sics/cooja/util/ArrayUtils.java @@ -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; + } + } }