001: /*
002: * @(#)ConnectionBase.java 1.17 06/10/10
003: *
004: * Copyright 1990-2006 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: *
026: */
027:
028: package com.sun.cdc.io;
029:
030: import java.io.*;
031: import javax.microedition.io.*;
032:
033: /**
034: * Base class for Connection protocols.
035: *
036: * @version 1.1 2/3/2000
037: */
038: abstract public class ConnectionBase extends GeneralBase implements
039: Connection, ConnectionBaseInterface {
040:
041: /**
042: * Open a connection to a target.
043: *
044: * @param string The URL for the connection
045: * @param mode The access mode
046: * @param timeouts A flag to indicate that the called wants timeout exceptions
047: *
048: * @exception IllegalArgumentException If a parameter is invalid.
049: * @exception ConnectionNotFoundException If the connection cannot be found.
050: * @exception IOException If some other kind of I/O error occurs.
051: */
052: abstract public void open(String name, int mode, boolean timeouts)
053: throws IOException;
054:
055: /**
056: * Open a connection to a target.
057: *
058: * @param string The URL for the connection
059: * @param mode The access mode
060: * @param timeouts A flag to indicate that the called wants timeout exceptions
061: * @return A new Connection object
062: *
063: * @exception IllegalArgumentException If a parameter is invalid.
064: * @exception ConnectionNotFoundException If the connection cannot be found.
065: * @exception IOException If some other kind of I/O error occurs.
066: */
067: public Connection openPrim(String name, int mode, boolean timeouts)
068: throws IOException {
069: open(name, mode, timeouts);
070: return this ;
071: }
072:
073: /**
074: * Open and return an input stream for a connection.
075: *
076: * @return An input stream
077: * @exception IOException If an I/O error occurs
078: */
079: public InputStream openInputStream() throws IOException {
080: throw new RuntimeException("No openInputStream");
081: }
082:
083: /**
084: * Open and return an output stream for a connection.
085: *
086: * @return An input stream
087: * @exception IOException If an I/O error occurs
088: */
089: public OutputStream openOutputStream() throws IOException {
090: throw new RuntimeException("No openOutputStream");
091: }
092:
093: /**
094: * Open and return a data input stream for a connection.
095: *
096: * @return An input stream
097: * @exception IOException If an I/O error occurs
098: */
099: public DataInputStream openDataInputStream() throws IOException {
100: InputStream is = openInputStream();
101: if (is instanceof DataInputStream) {
102: return (DataInputStream) is;
103: } else {
104: return new DataInputStream(is);
105: }
106: }
107:
108: /**
109: * Open and return a data output stream for a connection.
110: *
111: * @return An input stream
112: * @exception IOException If an I/O error occurs
113: */
114: public DataOutputStream openDataOutputStream() throws IOException {
115: OutputStream os = openOutputStream();
116: if (os instanceof DataOutputStream) {
117: return (DataOutputStream) os;
118: } else {
119: return new DataOutputStream(os);
120: }
121: }
122:
123: }
|