FYI a couple of notes: 1) InputStream.available() only tells you how many bytes can be read without blocking. From its specification:
It is never correct to use the return value of this method to allocate a > buffer intended to hold all data in this stream. Just don't use it. 2) InputStream.read() is not guaranteed to fill your buffer. You must always use it in a loop. On Mon, Nov 23, 2009 at 5:50 PM, Ikai L (Google) <[email protected]> wrote: > What are you posting? This code works for me: > > public class TestPostServlet extends HttpServlet { > > protected void doPost(HttpServletRequest request, HttpServletResponse > response) throws ServletException, IOException { > InputStream in = request.getInputStream(); > > int size = in.available(); > byte[] body = new byte[size]; > int status = in.read(body); > in.close(); > > response.getWriter().println("Status of read: " + status + " Size: > " + size); > response.getWriter().println("Got your post: " + new String(body)); > > } > } > > What mechanism are you using to POST to your application? Is it a browser > form or a custom client? > > > On Sat, Nov 21, 2009 at 12:37 PM, Bourke Floyd IV <[email protected]>wrote: > >> //This was working before I overhauled the authentication of my app >> //I'm trying to store the body of a Http POST as Text, I also plan on >> doing a Blob version >> //The maxLength is returning the correct size, but the read is >> returning -1 instead of properly >> //updating the body byte array >> >> //... >> >> InputStream httpIn = req.getInputStream(); >> byte[] body = new byte[httpIn.available()]; >> httpIn.read(body); >> >> Text myPostBody = new Text(new String(body)); //wasteful maybe? but >> should work >> >> //... >> >> //My old code was roughly the same >> >> //... >> >> int maxLength = req.getContentLength(); >> byte[] body = new byte[maxLength]; >> >> InputStream httpIn = req.getInputStream(); >> httpIn.read(body, 0, maxLength); >> >> String myPostBody = new String(body); //wasteful maybe? but should >> work >> >> //... >> >> -- >> >> You received this message because you are subscribed to the Google Groups >> "Google App Engine for Java" group. >> To post to this group, send email to >> [email protected]. >> To unsubscribe from this group, send email to >> [email protected]<google-appengine-java%[email protected]> >> . >> For more options, visit this group at >> http://groups.google.com/group/google-appengine-java?hl=. >> >> >> > > > -- > Ikai Lan > Developer Programs Engineer, Google App Engine > > -- > You received this message because you are subscribed to the Google Groups > "Google App Engine for Java" group. > > To post to this group, send email to > [email protected]. > To unsubscribe from this group, send email to > [email protected]<google-appengine-java%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/google-appengine-java?hl=. > -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.
