KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > internetcds > jdbc > tds > TdsAsciiInputStream


1 //
2
// Copyright 1998 CDS Networks, Inc., Medford Oregon
3
//
4
// All rights reserved.
5
//
6
// Redistribution and use in source and binary forms, with or without
7
// modification, are permitted provided that the following conditions are met:
8
// 1. Redistributions of source code must retain the above copyright
9
// notice, this list of conditions and the following disclaimer.
10
// 2. Redistributions in binary form must reproduce the above copyright
11
// notice, this list of conditions and the following disclaimer in the
12
// documentation and/or other materials provided with the distribution.
13
// 3. All advertising materials mentioning features or use of this software
14
// must display the following acknowledgement:
15
// This product includes software developed by CDS Networks, Inc.
16
// 4. The name of CDS Networks, Inc. may not be used to endorse or promote
17
// products derived from this software without specific prior
18
// written permission.
19
//
20
// THIS SOFTWARE IS PROVIDED BY CDS NETWORKS, INC. ``AS IS'' AND
21
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
// ARE DISCLAIMED. IN NO EVENT SHALL CDS NETWORKS, INC. BE LIABLE
24
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30
// SUCH DAMAGE.
31
//
32

33 package com.internetcds.jdbc.tds;
34
35 import java.io.*;
36
37
38 /**
39  * Extend the java.io.InputStream class for the TDS driver.
40  * <p>
41  * This class is used the the <code>getAsciiStream</code>
42  * of the <A HREF=ResultSet.html#getAsciiStream>ResultSet</A> class.
43  * <p>
44  * The current implementation reads the entire column of data into a
45  * String. This limits the maximum BLOB size to the largest BLOB
46  * that will fit in memory.
47  *
48  * @author Craig Spannring
49  * @version $Id: TdsAsciiInputStream.java,v 1.1 2006/06/23 10:39:30 sinisa Exp $
50  */

51 class TdsAsciiInputStream extends java.io.InputStream JavaDoc
52 {
53    public static final String JavaDoc cvsVersion = "$Id: TdsAsciiInputStream.java,v 1.1 2006/06/23 10:39:30 sinisa Exp $";
54
55    // The data that will be read from the stream.
56
String JavaDoc data;
57
58    // next is the index into data of the next byte of data in the stream
59
int next = 0;
60
61    public TdsAsciiInputStream(String JavaDoc data_)
62    {
63       data = data_;
64       next = 0;
65    }
66
67
68    public String JavaDoc getData()
69    {
70       return data;
71    }
72
73
74    public String JavaDoc toString()
75    {
76       return getData();
77    }
78
79
80    public int read()
81       throws java.io.IOException JavaDoc
82    {
83       int result;
84
85       if (data == null)
86       {
87          throw new java.io.IOException JavaDoc("stream was null");
88       }
89       else if (next == data.length())
90       {
91          result = -1;
92       }
93       else
94       {
95          result = data.charAt(next);
96          next++;
97       }
98       return result;
99    }
100 }
101
Popular Tags