001 /** 002 * Copyright (c) 2008 Regiscope Digital Imaging Co, LLC, All rights reserved. 003 * This program is free software; you can redistribute it and/or modify 004 * it under the terms of version 2 of the GNU General Public License as 005 * published by the Free Software Foundation. 006 * There are special exceptions to the terms and conditions of the GPL 007 * as it is applied to this software. See the GNU General Public License for more details. 008 * 009 * This program is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU General Public License for more details. 013 * 014 * You should have received a copy of the GNU General Public License 015 * along with this program; if not, write to the Free Software 016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 017 */ 018 019 020 package org.dbreplicator.replication.column; 021 022 import java.io.*; 023 import java.sql.*; 024 025 /** 026 * 027 */ 028 public class RepInputStream extends InputStream { 029 private long currentPosition; 030 private static RBlob blob; 031 032 public RepInputStream(RBlob blob0) { 033 blob = blob0; 034 currentPosition = 0; 035 } 036 037 /** 038 * read 039 * 040 * @return int 041 */ 042 public int read() throws IOException { 043 try { 044 byte b = blob.getBytes(currentPosition, 1)[0]; 045 currentPosition++; 046 return b; 047 } catch (SQLException ex) { 048 if (ex.getMessage().equalsIgnoreCase("NODATA")) { 049 return -1; 050 } 051 throw new IOException(ex.getMessage()); 052 } 053 } 054 055 public int read(byte b[]) throws IOException { 056 try { 057 int uLength = b.length; 058 byte[] temp = blob.getBytes(currentPosition, uLength); 059 currentPosition += temp.length; 060 System.arraycopy(temp, 0, b, 0, temp.length); 061 return temp.length; 062 } catch (SQLException ex) { 063 if (ex.getMessage().equalsIgnoreCase("NODATA")) { 064 return -1; 065 } 066 throw new IOException(ex.getMessage()); 067 } 068 } 069 070 public int read(byte b[], int off, int len) throws IOException { 071 try { 072 byte[] temp = blob.getBytes(currentPosition, len); 073 currentPosition += temp.length; 074 System.arraycopy(temp, 0, b, off, temp.length); 075 return temp.length; 076 } catch (SQLException ex) { 077 if (ex.getMessage().equalsIgnoreCase("NODATA")) { 078 return -1; 079 } 080 throw new IOException(ex.getMessage()); 081 } 082 } 083 084 public int available() throws IOException { 085 try { 086 int len = (int) blob.length(); 087 return len; 088 } catch (SQLException ex) { 089 throw new IOException(ex.getMessage()); 090 } 091 } 092 }

