001/* 002 * Copyright (C) 2011 The Guava Authors 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 005 * in compliance with the License. You may obtain a copy of the License at 006 * 007 * http://www.apache.org/licenses/LICENSE-2.0 008 * 009 * Unless required by applicable law or agreed to in writing, software distributed under the License 010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 011 * or implied. See the License for the specific language governing permissions and limitations under 012 * the License. 013 */ 014 015package com.google.common.hash; 016 017import com.google.common.annotations.Beta; 018 019import java.nio.charset.Charset; 020 021/** 022 * An object which can receive a stream of primitive values. 023 * 024 * @author Kevin Bourrillion 025 * @since 12.0 (in 11.0 as {@code Sink}) 026 */ 027@Beta 028public interface PrimitiveSink { 029 /** 030 * Puts a byte into this sink. 031 * 032 * @param b a byte 033 * @return this instance 034 */ 035 PrimitiveSink putByte(byte b); 036 037 /** 038 * Puts an array of bytes into this sink. 039 * 040 * @param bytes a byte array 041 * @return this instance 042 */ 043 PrimitiveSink putBytes(byte[] bytes); 044 045 /** 046 * Puts a chunk of an array of bytes into this sink. {@code bytes[off]} is the first byte written, 047 * {@code bytes[off + len - 1]} is the last. 048 * 049 * @param bytes a byte array 050 * @param off the start offset in the array 051 * @param len the number of bytes to write 052 * @return this instance 053 * @throws IndexOutOfBoundsException if {@code off < 0} or {@code off + len > bytes.length} or 054 * {@code len < 0} 055 */ 056 PrimitiveSink putBytes(byte[] bytes, int off, int len); 057 058 /** 059 * Puts a short into this sink. 060 */ 061 PrimitiveSink putShort(short s); 062 063 /** 064 * Puts an int into this sink. 065 */ 066 PrimitiveSink putInt(int i); 067 068 /** 069 * Puts a long into this sink. 070 */ 071 PrimitiveSink putLong(long l); 072 073 /** 074 * Puts a float into this sink. 075 */ 076 PrimitiveSink putFloat(float f); 077 078 /** 079 * Puts a double into this sink. 080 */ 081 PrimitiveSink putDouble(double d); 082 083 /** 084 * Puts a boolean into this sink. 085 */ 086 PrimitiveSink putBoolean(boolean b); 087 088 /** 089 * Puts a character into this sink. 090 */ 091 PrimitiveSink putChar(char c); 092 093 /** 094 * Puts a string into this sink. 095 */ 096 PrimitiveSink putString(CharSequence charSequence); 097 098 /** 099 * Puts a string into this sink using the given charset. 100 */ 101 PrimitiveSink putString(CharSequence charSequence, Charset charset); 102}