|
1 /* |
|
2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 * OST Writer |
|
17 * |
|
18 */ |
|
19 package com.nokia.traceviewer.ost; |
|
20 |
|
21 import java.io.IOException; |
|
22 import java.nio.ByteBuffer; |
|
23 import java.nio.channels.ByteChannel; |
|
24 |
|
25 import com.nokia.traceviewer.engine.DataWriter; |
|
26 |
|
27 /** |
|
28 * OST Writer |
|
29 * |
|
30 */ |
|
31 public class OstWriter implements DataWriter { |
|
32 |
|
33 /** |
|
34 * Target channel for write operations |
|
35 */ |
|
36 private ByteChannel writeChannel; |
|
37 |
|
38 /** |
|
39 * Constructor |
|
40 * |
|
41 * @param writeChannel |
|
42 * write channel |
|
43 */ |
|
44 public OstWriter(ByteChannel writeChannel) { |
|
45 this.writeChannel = writeChannel; |
|
46 } |
|
47 |
|
48 /* |
|
49 * (non-Javadoc) |
|
50 * |
|
51 * @see |
|
52 * com.nokia.traceviewer.engine.DataWriter#writeMessage(java.nio.ByteBuffer, |
|
53 * int, int) |
|
54 */ |
|
55 public void writeMessage(ByteBuffer sourceBuffer, int msgStart, int msgLen) { |
|
56 try { |
|
57 // Write the message to file |
|
58 if (sourceBuffer != null && writeChannel != null) { |
|
59 int position = sourceBuffer.position(); |
|
60 int limit = sourceBuffer.limit(); |
|
61 sourceBuffer.limit(msgStart + msgLen); |
|
62 sourceBuffer.position(msgStart); |
|
63 writeChannel.write(sourceBuffer); |
|
64 sourceBuffer.limit(limit); |
|
65 sourceBuffer.position(position); |
|
66 } |
|
67 } catch (Exception e) { |
|
68 e.printStackTrace(); |
|
69 } |
|
70 } |
|
71 |
|
72 /* |
|
73 * (non-Javadoc) |
|
74 * |
|
75 * @see com.nokia.traceviewer.engine.DataWriter#close() |
|
76 */ |
|
77 public void closeChannel() { |
|
78 try { |
|
79 if (writeChannel != null) { |
|
80 writeChannel.close(); |
|
81 writeChannel = null; |
|
82 } |
|
83 } catch (IOException e) { |
|
84 e.printStackTrace(); |
|
85 } |
|
86 } |
|
87 } |