1/*
2 * Copyright (C) 2011 The Guava Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14
15package com.google.common.hash;
16
17import com.google.common.annotations.Beta;
18
19import java.nio.charset.Charset;
20
21/**
22 * An object which can receive a stream of primitive values.
23 *
24 * @author Kevin Bourrillion
25 * @since 11.0
26 */
27@Beta
28public interface Sink {
29  /**
30   * Puts a byte into this sink.
31   *
32   * @param b a byte
33   * @return this instance
34   */
35  Sink putByte(byte b);
36
37  /**
38   * Puts an array of bytes into this sink.
39   *
40   * @param bytes a byte array
41   * @return this instance
42   */
43  Sink putBytes(byte[] bytes);
44
45  /**
46   * Puts a chunk of an array of bytes into this sink. {@code bytes[off]} is the first byte written,
47   * {@code bytes[off + len - 1]} is the last.
48   *
49   * @param bytes a byte array
50   * @param off the start offset in the array
51   * @param len the number of bytes to write
52   * @return this instance
53   * @throws IndexOutOfBoundsException if {@code off < 0} or {@code off + len > bytes.length} or
54   *   {@code len < 0}
55   */
56  Sink putBytes(byte[] bytes, int off, int len);
57
58  /**
59   * Puts a short into this sink.
60   */
61  Sink putShort(short s);
62
63  /**
64   * Puts an int into this sink.
65   */
66  Sink putInt(int i);
67
68  /**
69   * Puts a long into this sink.
70   */
71  Sink putLong(long l);
72
73  /**
74   * Puts a float into this sink.
75   */
76  Sink putFloat(float f);
77
78  /**
79   * Puts a double into this sink.
80   */
81  Sink putDouble(double d);
82
83  /**
84   * Puts a boolean into this sink.
85   */
86  Sink putBoolean(boolean b);
87
88  /**
89   * Puts a character into this sink.
90   */
91  Sink putChar(char c);
92
93  /**
94   * Puts a string into this sink.
95   */
96  Sink putString(CharSequence charSequence);
97
98  /**
99   * Puts a string into this sink using the given charset.
100   */
101  Sink putString(CharSequence charSequence, Charset charset);
102}
103