97345def93f0dd7929bcf3eb5fee493db147ec31
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.core / src / org / eclipse / linuxtools / internal / lttng2 / control / core / relayd / lttngviewerCommands / MetadataPacketResponse.java
1 /**********************************************************************
2 * Copyright (c) 2014 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial implementation and API
11 * Marc-Andre Laperle - Initial implementation and API
12 **********************************************************************/
13
14 package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands;
15
16 import java.io.DataInputStream;
17 import java.io.IOException;
18 import java.nio.ByteBuffer;
19 import java.nio.ByteOrder;
20
21 /**
22 * Metadata packet response containing a packet of metadata
23 *
24 * @author Matthew Khouzam
25 * @since 3.0
26 */
27 public class MetadataPacketResponse implements IRelayResponse {
28
29 /**
30 * Response size
31 *
32 * fData.length + fStatus
33 */
34 private static final int SIZE = (Long.SIZE + Integer.SIZE) / 8;
35 /** status of the metadata request */
36 private final GetMetadataReturnCode fStatus;
37 /** the packet */
38 private final byte fData[];
39
40 /**
41 * Read new metadata packet from the network
42 *
43 * @param inNet
44 * network input reader
45 * @throws IOException
46 * network error
47 */
48 public MetadataPacketResponse(DataInputStream inNet) throws IOException {
49 byte[] data = new byte[SIZE];
50 inNet.readFully(data);
51 ByteBuffer bb = ByteBuffer.wrap(data);
52 bb.order(ByteOrder.BIG_ENDIAN);
53 long length = bb.getLong();
54 fStatus = GetMetadataReturnCode.values()[bb.getInt() - 1];
55 if (length >= Integer.MAX_VALUE) {
56 throw new IOException("Metadata Packet too big " + length); //$NON-NLS-1$
57 }
58 fData = new byte[(int) length];
59 inNet.readFully(fData);
60 }
61
62 /**
63 * Get the packet
64 *
65 * @return the packet
66 */
67 public byte[] getData() {
68 return fData;
69 }
70
71 /**
72 * Gets the status
73 *
74 * @return the status
75 */
76 public GetMetadataReturnCode getStatus() {
77 return fStatus;
78 }
79 }
This page took 0.034437 seconds and 4 git commands to generate.