diff options
author | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2021-03-24 11:08:57 +0000 |
---|---|---|
committer | Thomas Lenz <thomas.lenz@egiz.gv.at> | 2021-03-24 11:08:57 +0000 |
commit | 666d8c9f8cec7573e60a14ab039c0874f6a9ec53 (patch) | |
tree | d9b2506506cf544ea3758322fd5488c913073427 /moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/URLDecoder.java | |
parent | d003a873fdeec22b1dd57d61590a12a1691ae137 (diff) | |
parent | cd65b47cc30e7119593bbb05afa48d4f896a4859 (diff) | |
download | moa-sig-666d8c9f8cec7573e60a14ab039c0874f6a9ec53.tar.gz moa-sig-666d8c9f8cec7573e60a14ab039c0874f6a9ec53.tar.bz2 moa-sig-666d8c9f8cec7573e60a14ab039c0874f6a9ec53.zip |
Merge branch 'feature/codestyle_and_gitlab_ci' into 'master'
Feature/codestyle and gitlab ci
See merge request egiz/moa-sig!1
Diffstat (limited to 'moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/URLDecoder.java')
-rw-r--r-- | moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/URLDecoder.java | 50 |
1 files changed, 27 insertions, 23 deletions
diff --git a/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/URLDecoder.java b/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/URLDecoder.java index af71e2d..cfebbb2 100644 --- a/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/URLDecoder.java +++ b/moaSig/common/src/main/java/at/gv/egovernment/moaspss/util/URLDecoder.java @@ -21,7 +21,6 @@ * that you distribute must include a readable copy of the "NOTICE" text file. */ - package at.gv.egovernment.moaspss.util; import java.io.ByteArrayOutputStream; @@ -30,55 +29,60 @@ import java.io.StringReader; import java.io.UnsupportedEncodingException; /** - * Decodes an URL encoded String using a specified character encoding. - * Provides a function missing in JDK 1.3. + * Decodes an URL encoded String using a specified character encoding. Provides + * a function missing in JDK 1.3. + * * @author Paul Ivancsics * @version $Id$ */ public class URLDecoder { /** - * Decodes an <code>application/x-www-form-urlencoded</code> string using a specific encoding scheme. - * @param s the string to decode + * Decodes an <code>application/x-www-form-urlencoded</code> string using a + * specific encoding scheme. + * + * @param s the string to decode * @param encoding name of character encoding * @return the newly decoded string * @throws UnsupportedEncodingException if the encoding is not supported */ public static String decode(String s, String encoding) throws UnsupportedEncodingException { - StringReader in = new StringReader(s); - ByteArrayOutputStream bout = new ByteArrayOutputStream(); - for (int b = read(in); b >= 0; b = read(in)) + final StringReader in = new StringReader(s); + final ByteArrayOutputStream bout = new ByteArrayOutputStream(); + for (int b = read(in); b >= 0; b = read(in)) { bout.write(b); + } return bout.toString(encoding); } + /** * Decodes the next byte from the string reader. + * * @param in string reader - * @return the next byte decoded; - * -1 upon end of string, on erroneous data, and on any exception caught + * @return the next byte decoded; -1 upon end of string, on erroneous data, and + * on any exception caught * @todo syntax check on string */ private static int read(StringReader in) { - try { - int b = in.read(); - if (b == '+') + try { + final int b = in.read(); + if (b == '+') { return ' '; + } if (b == '%') { - char[] hex = new char[2]; + final char[] hex = new char[2]; if (in.read(hex, 0, 2) >= 0) { - String hexString = new String(hex); + final String hexString = new String(hex); return Integer.valueOf(hexString, 16).intValue(); - } - else + } else { return -1; + } } return b; - } - catch (IOException ex) { - return -1; - } - catch (NumberFormatException ex) { - return -1; + } catch (final IOException ex) { + return -1; + } catch (final NumberFormatException ex) { + return -1; } } } |