forked from JoyChou93/java-sec-code
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTools.java
More file actions
20 lines (16 loc) · 678 Bytes
/
Tools.java
File metadata and controls
20 lines (16 loc) · 678 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package org.joychou.utils;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
public class Tools {
// Get request body.
public static String getRequestBody(HttpServletRequest request) throws IOException {
InputStream in = request.getInputStream();
return convertStreamToString(in);
}
// https://stackoverflow.com/questions/309424/how-do-i-read-convert-an-inputstream-into-a-string-in-java
public static String convertStreamToString(java.io.InputStream is) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? s.next() : "";
}
}