001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions Copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2010–2011 ApexIdentity Inc. 015 * Portions Copyright 2011-2014 ForgeRock AS. 016 */ 017 018package org.forgerock.openig.io; 019 020import java.io.InputStream; 021 022/** 023 * An input stream that holds no data. GNDN. 024 */ 025public class NullInputStream extends InputStream { 026 027 /** 028 * Unconditionally returns {@code -1} to indicate the end of stream has been reached. 029 * 030 * @return {@code -1} to indicate the end of stream has been reached. 031 */ 032 @Override 033 public int read() { 034 // always at end of stream 035 return -1; 036 } 037 038 /** 039 * Unconditionally returns {@code -1} to indicate the end of stream has been reached. 040 * 041 * @param b 042 * The byte to read. 043 * @return {@code -1} to indicate the end of stream has been reached. 044 */ 045 @Override 046 public int read(byte[] b) { 047 return -1; 048 } 049 050 /** 051 * Unconditionally returns {@code -1} to indicate the end of stream has been reached. 052 * 053 * @param b 054 * the buffer into which the data is read. 055 * @param off 056 * the start offset in array b at which the data is written. 057 * @param len 058 * the maximum number of bytes to read. 059 * @return {@code -1} to indicate the end of stream has been reached. 060 */ 061 @Override 062 public int read(byte[] b, int off, int len) { 063 return -1; 064 } 065 066 /** 067 * Always returns 0 to indicate that no bytes were skipped. 068 * 069 * @param n 070 * the number of bytes to be skipped. 071 * @return 0 to indicate that no bytes were skipped. 072 */ 073 @Override 074 public long skip(long n) { 075 return 0; 076 } 077 078 /** 079 * Always returns 0 to indicate that no bytes are available. 080 * 081 * @return 0 to indicate that no bytes are available. 082 */ 083 @Override 084 public int available() { 085 return 0; 086 } 087}