• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
15 package com.google.common.hash;
16 
17 import com.google.common.annotations.Beta;
18 
19 import java.nio.charset.Charset;
20 
21 /**
22  * An object which can receive a stream of primitive values.
23  *
24  * @author Kevin Bourrillion
25  * @since 12.0 (in 11.0 as {@code Sink})
26  */
27 @Beta
28 public interface PrimitiveSink {
29   /**
30    * Puts a byte into this sink.
31    *
32    * @param b a byte
33    * @return this instance
34    */
putByte(byte b)35   PrimitiveSink 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    */
putBytes(byte[] bytes)43   PrimitiveSink 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    */
putBytes(byte[] bytes, int off, int len)56   PrimitiveSink putBytes(byte[] bytes, int off, int len);
57 
58   /**
59    * Puts a short into this sink.
60    */
putShort(short s)61   PrimitiveSink putShort(short s);
62 
63   /**
64    * Puts an int into this sink.
65    */
putInt(int i)66   PrimitiveSink putInt(int i);
67 
68   /**
69    * Puts a long into this sink.
70    */
putLong(long l)71   PrimitiveSink putLong(long l);
72 
73   /**
74    * Puts a float into this sink.
75    */
putFloat(float f)76   PrimitiveSink putFloat(float f);
77 
78   /**
79    * Puts a double into this sink.
80    */
putDouble(double d)81   PrimitiveSink putDouble(double d);
82 
83   /**
84    * Puts a boolean into this sink.
85    */
putBoolean(boolean b)86   PrimitiveSink putBoolean(boolean b);
87 
88   /**
89    * Puts a character into this sink.
90    */
putChar(char c)91   PrimitiveSink putChar(char c);
92 
93   /**
94    * Puts each 16-bit code unit from the {@link CharSequence} into this sink.
95    *
96    * @since 15.0 (since 11.0 as putString(CharSequence))
97    */
putUnencodedChars(CharSequence charSequence)98   PrimitiveSink putUnencodedChars(CharSequence charSequence);
99 
100   /**
101    * Puts a string into this sink using the given charset.
102    */
putString(CharSequence charSequence, Charset charset)103   PrimitiveSink putString(CharSequence charSequence, Charset charset);
104 }
105