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   * @deprecated Use {PrimitiveSink#putUnencodedChars} instead. This method is scheduled for
097   *     removal in Guava 16.0.
098   */
099  @Deprecated
100  PrimitiveSink putString(CharSequence charSequence);
101
102  /**
103   * Puts each 16-bit code unit from the {@link CharSequence} into this sink.
104   *
105   * @since 15.0 (since 11.0 as putString(CharSequence))
106   */
107  PrimitiveSink putUnencodedChars(CharSequence charSequence);
108
109  /**
110   * Puts a string into this sink using the given charset.
111   */
112  PrimitiveSink putString(CharSequence charSequence, Charset charset);
113}