1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.apache.giraph.utils;
19
20 import java.io.DataOutput;
21
22 /**
23 * Add a few features to data output
24 */
25 public interface ExtendedDataOutput extends DataOutput {
26 /**
27 * Ensure that backing byte structure has at least minSize
28 * additional bytes
29 *
30 * @param minSize additional size required
31 */
32 void ensureWritable(int minSize);
33
34 /**
35 * Skip some number of bytes.
36 *
37 * @param bytesToSkip Number of bytes to skip
38 */
39 void skipBytes(int bytesToSkip);
40
41 /**
42 * In order to write a size as a first part of an data output, it is
43 * useful to be able to write an int at an arbitrary location in the stream
44 *
45 * @param pos Byte position in the output stream
46 * @param value Value to write
47 */
48 void writeInt(int pos, int value);
49
50 /**
51 * Get the position in the output stream
52 *
53 * @return Position in the output stream
54 */
55 int getPos();
56
57 /**
58 * Get the internal byte array (if possible), read-only
59 *
60 * @return Internal byte array (do not modify)
61 */
62 byte[] getByteArray();
63
64 /**
65 * Copies the internal byte array
66 *
67 * @return Copied byte array
68 */
69 byte[] toByteArray();
70
71 /**
72 * Return a copy of slice of byte array
73 *
74 * @param offset offset of array
75 * @param length length of slice
76 * @return byte array
77 */
78 byte[] toByteArray(int offset, int length);
79
80 /**
81 * Clears the buffer
82 */
83 void reset();
84 }