Skip to content

Commit

Permalink
Use java8 Base64 implementation for jdk10 compat
Browse files Browse the repository at this point in the history
- Adjust tests to explicitly join base64 strings prior to comparison
  • Loading branch information
easel committed May 5, 2018
1 parent ed114bf commit 676b48e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package play.api.cache.redis.connector

import javax.inject._
import java.util.Base64

import javax.inject._
import scala.language.implicitConversions
import scala.reflect.ClassTag
import scala.util._

import play.api.cache.redis._

import akka.actor.ActorSystem
import akka.serialization._

Expand Down Expand Up @@ -72,7 +72,7 @@ private[ connector ] class AkkaEncoder( serializer: Serialization ) {

/** Produces BASE64 encoded string from an array of bytes */
protected def binaryToString( bytes: Array[ Byte ] ): String =
new sun.misc.BASE64Encoder( ).encode( bytes )
Base64.getEncoder.encodeToString( bytes )

/** unsafe method converting AnyRef into BASE64 string */
protected def anyRefToString( value: AnyRef ): String =
Expand Down Expand Up @@ -117,7 +117,7 @@ private[ connector ] class AkkaDecoder( serializer: Serialization ) {

/** consumes BASE64 string and returns array of bytes */
protected def stringToBinary( base64: String ): Array[ Byte ] =
new sun.misc.BASE64Decoder( ).decodeBuffer( base64 )
Base64.getDecoder.decode( base64 )

/** deserializes the binary stream into the object */
protected def binaryToAnyRef[ T ]( binary: Array[ Byte ] )( implicit classTag: ClassTag[ T ] ): AnyRef =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ class SerializerSpecs extends Specification with Mockito {
|TG9yZy9qb2RhL3RpbWUvQ2hyb25vbG9neTt4cAAAAAAAAeJAc3IAJ29yZy5qb2RhLnRpbWUuY2hy
|b25vLklTT0Nocm9ub2xvZ3kkU3R1YqnIEWZxN1AnAwAAeHBzcgAfb3JnLmpvZGEudGltZS5EYXRl
|VGltZVpvbmUkU3R1YqYvAZp8MhrjAwAAeHB3BQADVVRDeHg=
""".stripMargin.trim
""".stripMargin.lines.map(_.trim).mkString
}

"custom classes" in {
SimpleObject( "B", 3 ).encoded mustEqual """
|rO0ABXNyADtwbGF5LmFwaS5jYWNoZS5yZWRpcy5jb25uZWN0b3IuU2VyaWFsaXplclNwZWNzJFNp
|bXBsZU9iamVjdMm6wvThiaEsAgACSQAFdmFsdWVMAANrZXl0ABJMamF2YS9sYW5nL1N0cmluZzt4
|cAAAAAN0AAFC
""".stripMargin.trim
""".stripMargin.lines.map(_.trim).mkString
}

"null" in {
Expand All @@ -91,7 +91,7 @@ class SerializerSpecs extends Specification with Mockito {
|rO0ABXNyADJzY2FsYS5jb2xsZWN0aW9uLmltbXV0YWJsZS5MaXN0JFNlcmlhbGl6YXRpb25Qcm94
|eQAAAAAAAAABAwAAeHB0AAFBdAABQnQAAUNzcgAsc2NhbGEuY29sbGVjdGlvbi5pbW11dGFibGUu
|TGlzdFNlcmlhbGl6ZUVuZCSKXGNb91MLbQIAAHhweA==
""".stripMargin.trim
""".stripMargin.lines.map(_.trim).mkString
}

}
Expand Down Expand Up @@ -151,23 +151,23 @@ class SerializerSpecs extends Specification with Mockito {
|TG9yZy9qb2RhL3RpbWUvQ2hyb25vbG9neTt4cAAAAAAAAeJAc3IAJ29yZy5qb2RhLnRpbWUuY2hy
|b25vLklTT0Nocm9ub2xvZ3kkU3R1YqnIEWZxN1AnAwAAeHBzcgAfb3JnLmpvZGEudGltZS5EYXRl
|VGltZVpvbmUkU3R1YqYvAZp8MhrjAwAAeHB3BQADVVRDeHg=
""".stripMargin.trim.decoded[ DateTime ] mustEqual new DateTime( 123456L, DateTimeZone.forID( "UTC" ) )
""".stripMargin.lines.map(_.trim).mkString.decoded[ DateTime ] mustEqual new DateTime( 123456L, DateTimeZone.forID( "UTC" ) )
}

"custom classes" in {
"""
|rO0ABXNyADtwbGF5LmFwaS5jYWNoZS5yZWRpcy5jb25uZWN0b3IuU2VyaWFsaXplclNwZWNzJFNp
|bXBsZU9iamVjdMm6wvThiaEsAgACSQAFdmFsdWVMAANrZXl0ABJMamF2YS9sYW5nL1N0cmluZzt4
|cAAAAAN0AAFC
""".stripMargin.trim.decoded[ SimpleObject ] mustEqual SimpleObject( "B", 3 )
""".stripMargin.lines.map(_.trim).mkString.decoded[ SimpleObject ] mustEqual SimpleObject( "B", 3 )
}

"list" in {
"""
|rO0ABXNyADJzY2FsYS5jb2xsZWN0aW9uLmltbXV0YWJsZS5MaXN0JFNlcmlhbGl6YXRpb25Qcm94
|eQAAAAAAAAABAwAAeHB0AAFBdAABQnQAAUNzcgAsc2NhbGEuY29sbGVjdGlvbi5pbW11dGFibGUu
|TGlzdFNlcmlhbGl6ZUVuZCSKXGNb91MLbQIAAHhweA==
""".stripMargin.trim.decoded[ List[ String ] ] mustEqual List( "A", "B", "C" )
""".stripMargin.lines.map(_.trim).mkString.decoded[ List[ String ] ] mustEqual List( "A", "B", "C" )
}

"forgotten type" in {
Expand Down

0 comments on commit 676b48e

Please sign in to comment.