Skip to content
This repository was archived by the owner on Feb 8, 2023. It is now read-only.

Commit bea0d64

Browse files
Add Java 6 support
1 parent 9ee5688 commit bea0d64

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

.classpath

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@
1717
<attribute name="maven.pomderived" value="true"/>
1818
</attributes>
1919
</classpathentry>
20-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
20+
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
21+
<attributes>
22+
<attribute name="maven.pomderived" value="true"/>
23+
</attributes>
24+
</classpathentry>
25+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6">
2126
<attributes>
2227
<attribute name="maven.pomderived" value="true"/>
2328
</attributes>

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
A simple Java API for handling cookies
44

5+
* Supports Java 6+
56
* [Unobtrusive](#json-data-binding) JSON Data Binding support
67
* [RFC 6265](http://www.rfc-editor.org/rfc/rfc6265.txt) compliant
78
* Enable [custom decoding](#converter)

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@
7171
<artifactId>maven-compiler-plugin</artifactId>
7272
<version>3.1</version>
7373
<configuration>
74-
<source>1.7</source>
75-
<target>1.7</target>
74+
<source>1.6</source>
75+
<target>1.6</target>
7676
</configuration>
7777
</plugin>
7878
<plugin>

src/main/java/org/jscookie/Cookies.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.CharArrayWriter;
44
import java.io.IOException;
55
import java.io.UnsupportedEncodingException;
6-
import java.nio.charset.StandardCharsets;
76
import java.util.HashMap;
87
import java.util.HashSet;
98
import java.util.List;
@@ -21,6 +20,7 @@
2120
import com.fasterxml.jackson.databind.ObjectMapper;
2221

2322
public final class Cookies implements CookiesDefinition {
23+
private static String UTF_8 = "UTF-8";
2424
private HttpServletRequest request;
2525
private HttpServletResponse response;
2626
private AttributesDefinition defaults = Attributes.empty();
@@ -298,7 +298,7 @@ private String encode( String decoded, Set<Integer> exceptions ) {
298298
try {
299299
String character = new String( Character.toChars( codePoint ) );
300300
CharArrayWriter hexSequence = new CharArrayWriter();
301-
byte[] bytes = character.getBytes( StandardCharsets.UTF_8.name() );
301+
byte[] bytes = character.getBytes( UTF_8 );
302302
for ( int bytesIndex = 0; bytesIndex < bytes.length; bytesIndex++ ) {
303303
char left = Character.forDigit( bytes[ bytesIndex ] >> 4 & 0xF, 16 );
304304
char right = Character.forDigit( bytes[ bytesIndex ] & 0xF, 16 );
@@ -330,7 +330,7 @@ private String decode( String encoded ) {
330330
bytes[ i - 1 ] = ( byte )Integer.parseInt( encodedByte, 16 );
331331
}
332332
try {
333-
String decodedChar = new String( bytes, StandardCharsets.UTF_8.toString() );
333+
String decodedChar = new String( bytes, UTF_8 );
334334
decoded = decoded.replace( encodedChar, decodedChar );
335335
} catch ( UnsupportedEncodingException e ) {
336336
e.printStackTrace();
@@ -340,7 +340,7 @@ private String decode( String encoded ) {
340340
}
341341

342342
private String encodeValue( String decodedValue ) {
343-
Set<Integer> exceptions = new HashSet<>();
343+
Set<Integer> exceptions = new HashSet<Integer>();
344344
for ( int i = 0; i < decodedValue.length(); ) {
345345
int codePoint = decodedValue.codePointAt( i );
346346
i += Character.charCount( codePoint );
@@ -393,7 +393,7 @@ private String decodeValue( String encodedValue, String decodedName ) {
393393
}
394394

395395
private Map<String, String> getCookies( String cookieHeader ) {
396-
Map<String, String> result = new HashMap<>();
396+
Map<String, String> result = new HashMap<String, String>();
397397
String[] cookies = cookieHeader.split( "; " );
398398
for ( int i = 0; i < cookies.length; i++ ) {
399399
String cookie = cookies[ i ];

src/test/java/org/jscookie/test/integration/encoding/EncodingServlet.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import java.io.IOException;
44
import java.io.UnsupportedEncodingException;
55
import java.net.URLDecoder;
6-
import java.nio.charset.StandardCharsets;
76

87
import javax.servlet.ServletException;
98
import javax.servlet.annotation.WebServlet;
@@ -46,7 +45,7 @@ private String getUTF8Param( String name, HttpServletRequest request ) throws Un
4645
String query = request.getQueryString();
4746
for ( String pair : query.split( "&" ) ) {
4847
if ( name.equals( pair.split( "=" )[ 0 ] ) ) {
49-
return URLDecoder.decode( pair.split( "=" )[ 1 ], StandardCharsets.UTF_8.name() );
48+
return URLDecoder.decode( pair.split( "=" )[ 1 ], "UTF-8" );
5049
}
5150
}
5251
return null;

0 commit comments

Comments
 (0)