/* * Copyright (c) 2004, 2005 Kazuya Ujihara * * This software is provided 'as-is', without any express or implied warranty. * In no event will the authors be held liable for any damages arising from the use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it freely, * subject to the following restrictions: * 1. The origin of this software must not be misrepresented; * you must not claim that you wrote the original software. * If you use this software in a product, an acknowledgment * in the product documentation would be appreciated but is not required. * 2. Altered source versions must be plainly marked as such, * and must not be misrepresented as being the original software. * 3. This notice may not be removed or altered from any source distribution. */ package jp.ujihara.jsharp.io; import System.IO.Stream; import System.ObjectDisposedException; import System.IO.SeekOrigin; import java.io.InputStream; public class JavaInputStream extends InputStream { protected Stream fxStream; public JavaInputStream(Stream fxStream) { this.fxStream = fxStream; } /** @beanproperty */ public final Stream getDotNetStream() { return fxStream; } public int read() throws java.io.IOException { try { return fxStream.ReadByte(); } catch (System.NotSupportedException e) { throw new java.io.IOException(e.get_Message()); } catch (System.ObjectDisposedException e) { throw new java.io.IOException(e.get_Message()); } } public int read(byte[] b, int off, int len) throws java.io.IOException { if (b == null) throw new NullPointerException(); if (off < 0 || len < 0 || off + len > b.length) throw new IndexOutOfBoundsException(); if (len == 0) return 0; int l; try { l = fxStream.Read((ubyte[])(Object)b, off, len); } catch (Exception e) { throw new java.io.IOException(e.get_Message()); } if (l == 0) return -1; return l; } public long skip(long n) throws java.io.IOException { if (n <= 0) return 0; try { return fxStream.Seek(n, SeekOrigin.Current); } catch (Exception e) { throw new java.io.IOException(e.get_Message()); } } public void close() throws java.io.IOException { try { fxStream.Close(); } catch (ObjectDisposedException e) { throw new java.io.IOException(e.get_Message()); } } }