Back to project page NexusData.
The source code is released under:
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCT...
If you think the Android project NexusData listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.github.dkharrat.nexusdata.utils; /* ww w .j a v a 2 s. com*/ import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; public class StreamUtil { public static String getStringFromStream(InputStream in, int maxLength) throws IOException { if (maxLength == 0) { maxLength = Integer.MAX_VALUE; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[1024]; int lengthSoFar = 0; int curLength = 0; while ((curLength = in.read(buffer)) != -1 && lengthSoFar <= maxLength) { baos.write(buffer, 0, Math.min(curLength, maxLength - lengthSoFar)); lengthSoFar += curLength; } return new String(baos.toByteArray()); } }