Last active
January 4, 2016 18:59
-
-
Save cormacrelf/8664818 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encodeMapResponse(results: List[Match]): HttpResponse = { | |
val response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK) | |
val stream = new ByteArrayOutputStream(1024) | |
val w = new ObjectOutputStream(stream) | |
try { | |
w.writeObject(results) | |
} catch { | |
case e:IOException => Console.err.println(id + ": " + e) | |
} | |
w.close | |
val content = stream.toByteArray.toString | |
response.setContent(copiedBuffer(content, UTF_8)) | |
response | |
} | |
def decodeMapResponse(response: HttpResponse): List[Match] = { | |
var list = List[Match]() | |
val cbuf:ChannelBuffer = response.getContent() | |
Console.err.println(cbuf.toString("UTF-8")) | |
if (cbuf.readable) { | |
val stream = new ByteArrayInputStream(cbuf.toString("UTF-8").getBytes()) | |
val w = new ObjectInputStream(stream) | |
try { | |
list = w.readObject.asInstanceOf[List[Match]] | |
} catch { | |
case e:IOException => Console.err.println(e) | |
} | |
w.close | |
} | |
list | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encodeMapResponse(results: List[Match]): HttpResponse = { | |
val response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK) | |
val stream = new ByteArrayOutputStream(1024) | |
val w = new ObjectOutputStream(stream) | |
try { | |
w.writeObject(results) | |
} catch { | |
case e:IOException => Console.err.println(id + ": " + e) | |
} | |
w.flush | |
w.close | |
val content = stream.toByteArray() | |
val cbuf = ChannelBuffers.copiedBuffer(content) | |
response.setContent(cbuf) | |
response | |
} | |
def decodeMapResponse(response: HttpResponse): List[Match] = { | |
var list = List[Match]() | |
val cbuf:ChannelBuffer = response.getContent() | |
var bytes = new Array[Byte](cbuf.readableBytes()) | |
cbuf.getBytes(cbuf.readerIndex(), bytes, 0, cbuf.readableBytes()) | |
if (cbuf.readable) { | |
val stream = new ByteArrayInputStream(bytes) | |
val w = new ObjectInputStream(stream) | |
try { | |
list = w.readObject.asInstanceOf[List[Match]] | |
} catch { | |
case e:IOException => Console.err.println(e) | |
} | |
w.close | |
} | |
list | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment