java how to call getReader twice
Java
public class CustomHttpServletRequestWrapper extends HttpServletRequestWrapper {
private static final Logger logger = Logger.getLogger(CustomHttpServletRequestWrapper.class);
private final String body;
public CustomHttpServletRequestWrapper(HttpServletRequest request) {
super(request);
StringBuilder stringBuilder = new StringBuilder();
BufferedReader bufferedReader = null;
try {
InputStream inputStream = request.getInputStream();
if (inputStream != null) {
bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
char[] charBuffer = new char[128];
int bytesRead = -1;
while ((bytesRead = bufferedReader.read(charBuffer)) > 0) {
stringBuilder.append(charBuffer, 0, bytesRead);
}
} else {
stringBuilder.append("");
}
} catch (IOException ex) {
logger.error("Error reading the request body...");
} finally {
if (bufferedReader != null) {
try {
bufferedReader.close();
} catch (IOException ex) {
logger.error("Error closing bufferedReader...");
}
}
}
body = stringBuilder.toString();
}
@Override
public ServletInputStream getInputStream () throws IOException {
final ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(body.getBytes());
ServletInputStream inputStream = new ServletInputStream() {
public int read () throws IOException {
return byteArrayInputStream.read();
}
};
return inputStream;
}
}
Also in Java:
- Title
- java split string
- Category
- Java
- Title
- creating the functional interface in java
- Category
- Java
- Title
- how add strings together
- Category
- Java
- Title
- java how to stop code
- Category
- Java
- Title
- java how to read file extension
- Category
- Java
- Title
- java 8 findany on null list
- Category
- Java
- Title
- java check for string length
- Category
- Java
- Title
- cannot lock java compile cache as it has already been locked by this process
- Category
- Java
- Title
- convert integer array to string array
- Category
- Java
- Title
- how to create a 2d arraylist java
- Category
- Java
- Title
- arraylist set method
- Category
- Java
- Title
- list in java
- Category
- Java
- Title
- java classes and methods
- Category
- Java
- Title
- java get int from double without rounding
- Category
- Java
- Title
- index 1 out of bound for length 1 java
- Category
- Java
- Title
- java date time
- Category
- Java
- Title
- initialize arraylist
- Category
- Java
- Title
- java delay
- Category
- Java
- Title
- new hashmap java
- Category
- Java
- Title
- Matlab java.lang.IllegalArgumentException: Invalid range
- Category
- Java
- Title
- android image view showing rotate image
- Category
- Java
- Title
- get tfidf score for a sentence
- Category
- Java
- Title
- boolean java.lang.String.equals(java.lang.Object)' on a null object reference
- Category
- Java
- Title
- Fab to CircularRevealFrameLayout example
- Category
- Java
- Title
- two pointer approach java
- Category
- Java
- Title
- java string replace character at position
- Category
- Java
- Title
- java insertion sort
- Category
- Java
- Title
- java substring
- Category
- Java
- Title
- Removing DOM nodes when traversing a NodeList
- Category
- Java
- Title
- how to change the color of a menubar in java
- Category
- Java
- Title
- vector in java
- Category
- Java
- Title
- Fragment DashboardFragment not associated with a fragment manager.
- Category
- Java
- Title
- how to see if a shape is touching another shape in java
- Category
- Java
- Title
- add a value to a list java in java hashmap
- Category
- Java
- Title
- loop and save letters in a string java
- Category
- Java
- Title
- Java nested array hashcode
- Category
- Java
- Title
- map multiple fields from java stream
- Category
- Java
- Title
- how to write a java for loop?
- Category
- Java
- Title
- money value commas java
- Category
- Java
- Title
- java int passed by reference
- Category
- Java
- Title
- java android show toast
- Category
- Java
- Title
- coding with WDSL spring
- Category
- Java
- Title
- long input in JAVA
- Category
- Java
- Title
- Please ensure that your JAVA_HOME points to a valid Java SDK. You are currently pointing to: /usr/lib/jvm/java-13-oracle
- Category
- Java
- Title
- convert string to localdatetime
- Category
- Java
- Title
- fibonacci sequence java
- Category
- Java
- Title
- fusion vecteur ordonner java
- Category
- Java
- Title
- how to create java jframe in eclipse
- Category
- Java
- Title
- how to add an image to a gui in java windowbuilder
- Category
- Java
- Title
- download spring
- Category
- Java
- Title
- how to remove a certain string in a arraylist java
- Category
- Java
- Title
- how to initialize main in java
- Category
- Java
- Title
- java fileinputstream
- Category
- Java
- Title
- android get last crash adb
- Category
- Java
- Title
- how to pass a float between activities in android studio
- Category
- Java
- Title
- spigot despawn entity
- Category
- Java
- Title
- finding min and max from given number in java
- Category
- Java
- Title
- java check if args is empty
- Category
- Java
- Title
- bukkit java connect player to another server in bungeecord
- Category
- Java
- Title
- java load image
- Category
- Java
- Title
- crit chance in java
- Category
- Java
- Title
- compile java
- Category
- Java
- Title
- java swing draw centered text
- Category
- Java
- Title
- cgange background from button click java fx
- Category
- Java
- Title
- java previous permutation
- Category
- Java
- Title
- java scanner next()
- Category
- Java
- Title
- install java debian 8
- Category
- Java
- Title
- java for
- Category
- Java
- Title
- primitive data types in java
- Category
- Java
- Title
- que es un length en java
- Category
- Java
- Title
- on click android studio not working
- Category
- Java
- Title
- google translate
- Category
- Java
- Title
- mutable string in java
- Category
- Java
- Title
- junit meaning in java
- Category
- Java
- Title
- arraylist get last
- Category
- Java
- Title
- java compareto
- Category
- Java
- Title
- writing to a text file java
- Category
- Java
- Title
- java arraylist to array
- Category
- Java
- Title
- java animated gif example
- Category
- Java
- Title
- file with line numbers inserted java
- Category
- Java
- Title
- java indexof not found
- Category
- Java
- Title
- java console text color
- Category
- Java
- Title
- java stack empty
- Category
- Java
- Title
- android how to switch between activities
- Category
- Java
- Title
- array null pointer java
- Category
- Java
- Title
- java split string on two or more spaces except for words in quotes
- Category
- Java
- Title
- what is java
- Category
- Java
- Title
- Error creating bean with name 'dataSource' defined in class path resource
- Category
- Java
- Title
- java map iteration
- Category
- Java
- Title
- java create txt file
- Category
- Java
- Title
- jq selector body
- Category
- Java
- Title
- java integer to binary string
- Category
- Java
- Title
- how to remove duplicates from an array java
- Category
- Java
- Title
- refrence xml textfield in javafx
- Category
- Java
- Title
- from file to array java
- Category
- Java
- Title
- fibonacci sequence in java recursion
- Category
- Java
- Title
- how to reverse a list in java
- Category
- Java
- Title
- java call another constructor
- Category
- Java
- Title
- summary of operator java
- Category
- Java
- Title
- java create arraly list
- Category
- Java