001/******************************************************************************* 002 * Copyright (c) 2024, 2026, Olivier Ayache. All rights reserved. 003 * 004 * This file is part of AVPKit. 005 * 006 * AVPKit is free software: you can redistribute it and/or modify 007 * it under the terms of the GNU Lesser General Public License as published by 008 * the Free Software Foundation, either version 3 of the License, or 009 * (at your option) any later version. 010 * 011 * AVPKit is distributed in the hope that it will be useful, 012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 014 * GNU Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public License 017 * along with AVPKit. If not, see <http://www.gnu.org/licenses/>. 018 *******************************************************************************/ 019 020package com.avpkit.core.io; 021 022import com.avpkit.core.io.IURLProtocolHandler; 023 024/** 025 * The NullProtocolHandler implements {@link IURLProtocolHandler}, but discards 026 * any data written and always returns 0 for reading. 027 * 028 * <p> 029 * This can be useful if your operating system doesn't have the unix 030 * equivalent of <code>/dev/null</code> or you want to cheaply 031 * discard data. 032 * </p> 033 * 034 * @author aclarke 035 * 036 */ 037public class NullProtocolHandler implements IURLProtocolHandler 038{ 039 040 // package level so other folks can't create it. 041 NullProtocolHandler() 042 { 043 } 044 045 public int close() 046 { 047 // Always succeed 048 return 0; 049 } 050 051 public boolean isStreamed(String aUrl, int aFlags) 052 { 053 // We're not streamed because, well, we do nothing. 054 return false; 055 } 056 057 public int open(String aUrl, int aFlags) 058 { 059 // Always succeed 060 return 0; 061 } 062 063 public int read(byte[] aBuf, int aSize) 064 { 065 // always read zero bytes 066 return 0; 067 } 068 069 public long seek(long aOffset, int aWhence) 070 { 071 // always seek to where we're asked to seek to 072 return aOffset; 073 } 074 075 public int write(byte[] aBuf, int aSize) 076 { 077 // always write all bytes 078 return aSize; 079 } 080 081}