Merge pull request #7910 from mnafshin/MalformedInputException
[BAEL-2505] MalformedInputException test functions are added
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
package com.baeldung.encoding;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.CharsetDecoder;
|
||||
import java.nio.charset.CodingErrorAction;
|
||||
|
||||
public class CharacterEncodingExamples {
|
||||
|
||||
@@ -29,4 +34,12 @@ public class CharacterEncodingExamples {
|
||||
}
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
static String decodeText(String input, Charset charset, CodingErrorAction codingErrorAction) throws IOException {
|
||||
CharsetDecoder charsetDecoder = charset.newDecoder();
|
||||
charsetDecoder.onMalformedInput(codingErrorAction);
|
||||
return new BufferedReader(
|
||||
new InputStreamReader(
|
||||
new ByteArrayInputStream(input.getBytes()), charsetDecoder)).readLine();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user