Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
MuleMessageWorker |
|
| 1.6666666666666667;1.667 |
1 | /* | |
2 | * $Id: MuleMessageWorker.java 7976 2007-08-21 14:26:13Z dirk.olmes $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com | |
5 | * | |
6 | * The software in this package is published under the terms of the CPAL v1.0 | |
7 | * license, a copy of which has been included with this distribution in the | |
8 | * LICENSE.txt file. | |
9 | */ | |
10 | ||
11 | package org.mule.providers.tcp.protocols; | |
12 | ||
13 | import org.mule.impl.MuleMessage; | |
14 | import org.mule.impl.RequestContext; | |
15 | ||
16 | import java.io.IOException; | |
17 | ||
18 | import org.apache.commons.lang.SerializationUtils; | |
19 | ||
20 | /** | |
21 | * Helper class for Mule message handling so that we can apply the same logic across all | |
22 | * sub-protocols (default, EOF and length). | |
23 | */ | |
24 | class MuleMessageWorker | |
25 | { | |
26 | ||
27 | private MuleMessageWorker() | |
28 | 0 | { |
29 | // no-op | |
30 | 0 | } |
31 | ||
32 | public static byte[] doWrite() throws IOException | |
33 | { | |
34 | 0 | MuleMessage msg = (MuleMessage) RequestContext.getEvent().getMessage(); |
35 | 0 | return SerializationUtils.serialize(msg); |
36 | } | |
37 | ||
38 | public static Object doRead(Object message) throws IOException | |
39 | { | |
40 | 0 | byte[] tmp = (byte[]) message; |
41 | ||
42 | 0 | if (tmp == null) |
43 | { | |
44 | 0 | return null; |
45 | } | |
46 | else | |
47 | { | |
48 | 0 | return SerializationUtils.deserialize(tmp); |
49 | } | |
50 | } | |
51 | ||
52 | } |