code
stringlengths 3
1.18M
| language
stringclasses 1
value |
|---|---|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Piped character-output streams.
* {@description.close}
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class PipedWriter extends Writer {
/* REMIND: identification of the read and write sides needs to be
more sophisticated. Either using thread groups (but what about
pipes within a thread?) or using finalization (but it may be a
long time until the next GC). */
private PipedReader sink;
/* This flag records the open status of this particular writer. It
* is independent of the status flags defined in PipedReader. It is
* used to do a sanity check on connect.
*/
private boolean closed = false;
/** {@collect.stats}
* {@description.open}
* Creates a piped writer connected to the specified piped
* reader. Data characters written to this stream will then be
* available as input from <code>snk</code>.
* {@description.close}
*
* @param snk The piped reader to connect to.
* @exception IOException if an I/O error occurs.
*/
public PipedWriter(PipedReader snk) throws IOException {
connect(snk);
}
/** {@collect.stats}
* {@description.open}
* Creates a piped writer that is not yet connected to a
* piped reader. It must be connected to a piped reader,
* either by the receiver or the sender, before being used.
* {@description.close}
*
* @see java.io.PipedReader#connect(java.io.PipedWriter)
* @see java.io.PipedWriter#connect(java.io.PipedReader)
*/
public PipedWriter() {
}
/** {@collect.stats}
* {@description.open}
* Connects this piped writer to a receiver. If this object
* is already connected to some other piped reader, an
* <code>IOException</code> is thrown.
* <p>
* If <code>snk</code> is an unconnected piped reader and
* <code>src</code> is an unconnected piped writer, they may
* be connected by either the call:
* <blockquote><pre>
* src.connect(snk)</pre></blockquote>
* or the call:
* <blockquote><pre>
* snk.connect(src)</pre></blockquote>
* The two calls have the same effect.
* {@description.close}
*
* @param snk the piped reader to connect to.
* @exception IOException if an I/O error occurs.
*/
public synchronized void connect(PipedReader snk) throws IOException {
if (snk == null) {
throw new NullPointerException();
} else if (sink != null || snk.connected) {
throw new IOException("Already connected");
} else if (snk.closedByReader || closed) {
throw new IOException("Pipe closed");
}
sink = snk;
snk.in = -1;
snk.out = 0;
snk.connected = true;
}
/** {@collect.stats}
* {@description.open}
* Writes the specified <code>char</code> to the piped output stream.
* If a thread was reading data characters from the connected piped input
* stream, but the thread is no longer alive, then an
* <code>IOException</code> is thrown.
* <p>
* Implements the <code>write</code> method of <code>Writer</code>.
* {@description.close}
*
* @param c the <code>char</code> to be written.
* @exception IOException if the pipe is
* <a href=PipedOutputStream.html#BROKEN> <code>broken</code></a>,
* {@link #connect(java.io.PipedReader) unconnected}, closed
* or an I/O error occurs.
*/
public void write(int c) throws IOException {
if (sink == null) {
throw new IOException("Pipe not connected");
}
sink.receive(c);
}
/** {@collect.stats}
* {@description.open}
* Writes <code>len</code> characters from the specified character array
* starting at offset <code>off</code> to this piped output stream.
* {@description.close}
* {@description.open blocking}
* This method blocks until all the characters are written to the output
* stream.
* {@description.close}
* {@description.open}
* If a thread was reading data characters from the connected piped input
* stream, but the thread is no longer alive, then an
* <code>IOException</code> is thrown.
* {@description.close}
*
* @param cbuf the data.
* @param off the start offset in the data.
* @param len the number of characters to write.
* @exception IOException if the pipe is
* <a href=PipedOutputStream.html#BROKEN> <code>broken</code></a>,
* {@link #connect(java.io.PipedReader) unconnected}, closed
* or an I/O error occurs.
*/
public void write(char cbuf[], int off, int len) throws IOException {
if (sink == null) {
throw new IOException("Pipe not connected");
} else if ((off | len | (off + len) | (cbuf.length - (off + len))) < 0) {
throw new IndexOutOfBoundsException();
}
sink.receive(cbuf, off, len);
}
/** {@collect.stats}
* {@description.open}
* Flushes this output stream and forces any buffered output characters
* to be written out.
* This will notify any readers that characters are waiting in the pipe.
* {@description.close}
*
* @exception IOException if the pipe is closed, or an I/O error occurs.
*/
public synchronized void flush() throws IOException {
if (sink != null) {
if (sink.closedByReader || closed) {
throw new IOException("Pipe closed");
}
synchronized (sink) {
sink.notifyAll();
}
}
}
/** {@collect.stats}
* {@description.open}
* Closes this piped output stream and releases any system resources
* associated with this stream.
* {@description.close}
* {@property.open runtime formal:java.io.Writer_ManipulateAfterClose}
* This stream may no longer be used for
* writing characters.
* {@property.close}
*
* @exception IOException if an I/O error occurs.
*/
public void close() throws IOException {
closed = true;
if (sink != null) {
sink.receivedLast();
}
}
}
|
Java
|
/*
* Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.security.*;
import java.util.Enumeration;
import java.util.List;
import java.util.ArrayList;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.Collections;
import java.io.ObjectStreamField;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.IOException;
import sun.security.util.SecurityConstants;
/** {@collect.stats}
* {@description.open}
* This class represents access to a file or directory. A FilePermission consists
* of a pathname and a set of actions valid for that pathname.
* <P>
* Pathname is the pathname of the file or directory granted the specified
* actions. A pathname that ends in "/*" (where "/" is
* the file separator character, <code>File.separatorChar</code>) indicates
* all the files and directories contained in that directory. A pathname
* that ends with "/-" indicates (recursively) all files
* and subdirectories contained in that directory. A pathname consisting of
* the special token "<<ALL FILES>>" matches <b>any</b> file.
* <P>
* Note: A pathname consisting of a single "*" indicates all the files
* in the current directory, while a pathname consisting of a single "-"
* indicates all the files in the current directory and
* (recursively) all files and subdirectories contained in the current
* directory.
* <P>
* The actions to be granted are passed to the constructor in a string containing
* a list of one or more comma-separated keywords. The possible keywords are
* "read", "write", "execute", and "delete". Their meaning is defined as follows:
* <P>
* <DL>
* <DT> read <DD> read permission
* <DT> write <DD> write permission
* <DT> execute
* <DD> execute permission. Allows <code>Runtime.exec</code> to
* be called. Corresponds to <code>SecurityManager.checkExec</code>.
* <DT> delete
* <DD> delete permission. Allows <code>File.delete</code> to
* be called. Corresponds to <code>SecurityManager.checkDelete</code>.
* </DL>
* <P>
* The actions string is converted to lowercase before processing.
* <P>
* Be careful when granting FilePermissions. Think about the implications
* of granting read and especially write access to various files and
* directories. The "<<ALL FILES>>" permission with write action is
* especially dangerous. This grants permission to write to the entire
* file system. One thing this effectively allows is replacement of the
* system binary, including the JVM runtime environment.
*
* <p>Please note: Code can always read a file from the same
* directory it's in (or a subdirectory of that directory); it does not
* need explicit permission to do so.
* {@description.close}
*
* @see java.security.Permission
* @see java.security.Permissions
* @see java.security.PermissionCollection
*
*
* @author Marianne Mueller
* @author Roland Schemers
* @since 1.2
*
* @serial exclude
*/
public final class FilePermission extends Permission implements Serializable {
/** {@collect.stats}
* {@description.open}
* Execute action.
* {@description.close}
*/
private final static int EXECUTE = 0x1;
/** {@collect.stats}
* {@description.open}
* Write action.
* {@description.close}
*/
private final static int WRITE = 0x2;
/** {@collect.stats}
* {@description.open}
* Read action.
* {@description.close}
*/
private final static int READ = 0x4;
/** {@collect.stats}
* {@description.open}
* Delete action.
* {@description.close}
*/
private final static int DELETE = 0x8;
/** {@collect.stats}
* {@description.open}
* All actions (read,write,execute,delete)
* {@description.close}
*/
private final static int ALL = READ|WRITE|EXECUTE|DELETE;
/** {@collect.stats}
* {@description.open}
* No actions.
* {@description.close}
*/
private final static int NONE = 0x0;
// the actions mask
private transient int mask;
// does path indicate a directory? (wildcard or recursive)
private transient boolean directory;
// is it a recursive directory specification?
private transient boolean recursive;
/** {@collect.stats}
* {@description.open}
* the actions string.
* {@description.close}
*
* @serial
*/
private String actions; // Left null as long as possible, then
// created and re-used in the getAction function.
// canonicalized dir path. In the case of
// directories, it is the name "/blah/*" or "/blah/-" without
// the last character (the "*" or "-").
private transient String cpath;
// static Strings used by init(int mask)
private static final char RECURSIVE_CHAR = '-';
private static final char WILD_CHAR = '*';
/*
public String toString()
{
StringBuffer sb = new StringBuffer();
sb.append("***\n");
sb.append("cpath = "+cpath+"\n");
sb.append("mask = "+mask+"\n");
sb.append("actions = "+getActions()+"\n");
sb.append("directory = "+directory+"\n");
sb.append("recursive = "+recursive+"\n");
sb.append("***\n");
return sb.toString();
}
*/
private static final long serialVersionUID = 7930732926638008763L;
/** {@collect.stats}
* {@description.open}
* initialize a FilePermission object. Common to all constructors.
* Also called during de-serialization.
* {@description.close}
*
* @param mask the actions mask to use.
*
*/
private void init(int mask)
{
if ((mask & ALL) != mask)
throw new IllegalArgumentException("invalid actions mask");
if (mask == NONE)
throw new IllegalArgumentException("invalid actions mask");
if ((cpath = getName()) == null)
throw new NullPointerException("name can't be null");
this.mask = mask;
if (cpath.equals("<<ALL FILES>>")) {
directory = true;
recursive = true;
cpath = "";
return;
}
// store only the canonical cpath if possible
cpath = AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
try {
return sun.security.provider.PolicyFile.canonPath(cpath);
} catch (IOException ioe) {
return cpath;
}
}
});
int len = cpath.length();
char last = ((len > 0) ? cpath.charAt(len - 1) : 0);
if (last == RECURSIVE_CHAR &&
cpath.charAt(len - 2) == File.separatorChar) {
directory = true;
recursive = true;
cpath = cpath.substring(0, --len);
} else if (last == WILD_CHAR &&
cpath.charAt(len - 2) == File.separatorChar) {
directory = true;
//recursive = false;
cpath = cpath.substring(0, --len);
} else {
// overkill since they are initialized to false, but
// commented out here to remind us...
//directory = false;
//recursive = false;
}
// XXX: at this point the path should be absolute. die if it isn't?
}
/** {@collect.stats}
* {@description.open}
* Creates a new FilePermission object with the specified actions.
* <i>path</i> is the pathname of a file or directory, and <i>actions</i>
* contains a comma-separated list of the desired actions granted on the
* file or directory. Possible actions are
* "read", "write", "execute", and "delete".
*
* <p>A pathname that ends in "/*" (where "/" is
* the file separator character, <code>File.separatorChar</code>)
* indicates all the files and directories contained in that directory.
* A pathname that ends with "/-" indicates (recursively) all files and
* subdirectories contained in that directory. The special pathname
* "<<ALL FILES>>" matches any file.
*
* <p>A pathname consisting of a single "*" indicates all the files
* in the current directory, while a pathname consisting of a single "-"
* indicates all the files in the current directory and
* (recursively) all files and subdirectories contained in the current
* directory.
*
* <p>A pathname containing an empty string represents an empty path.
* {@description.close}
*
* @param path the pathname of the file/directory.
* @param actions the action string.
*
* @throws IllegalArgumentException
* If actions is <code>null</code>, empty or contains an action
* other than the specified possible actions.
*/
public FilePermission(String path, String actions)
{
super(path);
init(getMask(actions));
}
/** {@collect.stats}
* {@description.open}
* Creates a new FilePermission object using an action mask.
* More efficient than the FilePermission(String, String) constructor.
* Can be used from within
* code that needs to create a FilePermission object to pass into the
* <code>implies</code> method.
* {@description.close}
*
* @param path the pathname of the file/directory.
* @param mask the action mask to use.
*/
// package private for use by the FilePermissionCollection add method
FilePermission(String path, int mask)
{
super(path);
init(mask);
}
/** {@collect.stats}
* {@description.open}
* Checks if this FilePermission object "implies" the specified permission.
* <P>
* More specifically, this method returns true if:<p>
* <ul>
* <li> <i>p</i> is an instanceof FilePermission,<p>
* <li> <i>p</i>'s actions are a proper subset of this
* object's actions, and <p>
* <li> <i>p</i>'s pathname is implied by this object's
* pathname. For example, "/tmp/*" implies "/tmp/foo", since
* "/tmp/*" encompasses all files in the "/tmp" directory,
* including the one named "foo".
* </ul>
* {@description.close}
*
* @param p the permission to check against.
*
* @return <code>true</code> if the specified permission is not
* <code>null</code> and is implied by this object,
* <code>false</code> otherwise.
*/
public boolean implies(Permission p) {
if (!(p instanceof FilePermission))
return false;
FilePermission that = (FilePermission) p;
// we get the effective mask. i.e., the "and" of this and that.
// They must be equal to that.mask for implies to return true.
return ((this.mask & that.mask) == that.mask) && impliesIgnoreMask(that);
}
/** {@collect.stats}
* {@description.open}
* Checks if the Permission's actions are a proper subset of the
* this object's actions. Returns the effective mask iff the
* this FilePermission's path also implies that FilePermission's path.
* {@description.close}
*
* @param that the FilePermission to check against.
* @param exact return immediately if the masks are not equal
* @return the effective mask
*/
boolean impliesIgnoreMask(FilePermission that) {
if (this.directory) {
if (this.recursive) {
// make sure that.path is longer then path so
// something like /foo/- does not imply /foo
if (that.directory) {
return (that.cpath.length() >= this.cpath.length()) &&
that.cpath.startsWith(this.cpath);
} else {
return ((that.cpath.length() > this.cpath.length()) &&
that.cpath.startsWith(this.cpath));
}
} else {
if (that.directory) {
// if the permission passed in is a directory
// specification, make sure that a non-recursive
// permission (i.e., this object) can't imply a recursive
// permission.
if (that.recursive)
return false;
else
return (this.cpath.equals(that.cpath));
} else {
int last = that.cpath.lastIndexOf(File.separatorChar);
if (last == -1)
return false;
else {
// this.cpath.equals(that.cpath.substring(0, last+1));
// Use regionMatches to avoid creating new string
return (this.cpath.length() == (last + 1)) &&
this.cpath.regionMatches(0, that.cpath, 0, last+1);
}
}
}
} else if (that.directory) {
// if this is NOT recursive/wildcarded,
// do not let it imply a recursive/wildcarded permission
return false;
} else {
return (this.cpath.equals(that.cpath));
}
}
/** {@collect.stats}
* {@description.open}
* Checks two FilePermission objects for equality. Checks that <i>obj</i> is
* a FilePermission, and has the same pathname and actions as this object.
* <P>
* {@description.close}
* @param obj the object we are testing for equality with this object.
* @return <code>true</code> if obj is a FilePermission, and has the same
* pathname and actions as this FilePermission object,
* <code>false</code> otherwise.
*/
public boolean equals(Object obj) {
if (obj == this)
return true;
if (! (obj instanceof FilePermission))
return false;
FilePermission that = (FilePermission) obj;
return (this.mask == that.mask) &&
this.cpath.equals(that.cpath) &&
(this.directory == that.directory) &&
(this.recursive == that.recursive);
}
/** {@collect.stats}
* {@description.open}
* Returns the hash code value for this object.
* {@description.close}
*
* @return a hash code value for this object.
*/
public int hashCode() {
return this.cpath.hashCode();
}
/** {@collect.stats}
* {@description.open}
* Converts an actions String to an actions mask.
* {@description.close}
*
* @param action the action string.
* @return the actions mask.
*/
private static int getMask(String actions) {
int mask = NONE;
// Null action valid?
if (actions == null) {
return mask;
}
// Check against use of constants (used heavily within the JDK)
if (actions == SecurityConstants.FILE_READ_ACTION) {
return READ;
} else if (actions == SecurityConstants.FILE_WRITE_ACTION) {
return WRITE;
} else if (actions == SecurityConstants.FILE_EXECUTE_ACTION) {
return EXECUTE;
} else if (actions == SecurityConstants.FILE_DELETE_ACTION) {
return DELETE;
}
char[] a = actions.toCharArray();
int i = a.length - 1;
if (i < 0)
return mask;
while (i != -1) {
char c;
// skip whitespace
while ((i!=-1) && ((c = a[i]) == ' ' ||
c == '\r' ||
c == '\n' ||
c == '\f' ||
c == '\t'))
i--;
// check for the known strings
int matchlen;
if (i >= 3 && (a[i-3] == 'r' || a[i-3] == 'R') &&
(a[i-2] == 'e' || a[i-2] == 'E') &&
(a[i-1] == 'a' || a[i-1] == 'A') &&
(a[i] == 'd' || a[i] == 'D'))
{
matchlen = 4;
mask |= READ;
} else if (i >= 4 && (a[i-4] == 'w' || a[i-4] == 'W') &&
(a[i-3] == 'r' || a[i-3] == 'R') &&
(a[i-2] == 'i' || a[i-2] == 'I') &&
(a[i-1] == 't' || a[i-1] == 'T') &&
(a[i] == 'e' || a[i] == 'E'))
{
matchlen = 5;
mask |= WRITE;
} else if (i >= 6 && (a[i-6] == 'e' || a[i-6] == 'E') &&
(a[i-5] == 'x' || a[i-5] == 'X') &&
(a[i-4] == 'e' || a[i-4] == 'E') &&
(a[i-3] == 'c' || a[i-3] == 'C') &&
(a[i-2] == 'u' || a[i-2] == 'U') &&
(a[i-1] == 't' || a[i-1] == 'T') &&
(a[i] == 'e' || a[i] == 'E'))
{
matchlen = 7;
mask |= EXECUTE;
} else if (i >= 5 && (a[i-5] == 'd' || a[i-5] == 'D') &&
(a[i-4] == 'e' || a[i-4] == 'E') &&
(a[i-3] == 'l' || a[i-3] == 'L') &&
(a[i-2] == 'e' || a[i-2] == 'E') &&
(a[i-1] == 't' || a[i-1] == 'T') &&
(a[i] == 'e' || a[i] == 'E'))
{
matchlen = 6;
mask |= DELETE;
} else {
// parse error
throw new IllegalArgumentException(
"invalid permission: " + actions);
}
// make sure we didn't just match the tail of a word
// like "ackbarfaccept". Also, skip to the comma.
boolean seencomma = false;
while (i >= matchlen && !seencomma) {
switch(a[i-matchlen]) {
case ',':
seencomma = true;
/*FALLTHROUGH*/
case ' ': case '\r': case '\n':
case '\f': case '\t':
break;
default:
throw new IllegalArgumentException(
"invalid permission: " + actions);
}
i--;
}
// point i at the location of the comma minus one (or -1).
i -= matchlen;
}
return mask;
}
/** {@collect.stats}
* {@description.open}
* Return the current action mask. Used by the FilePermissionCollection.
* {@description.close}
*
* @return the actions mask.
*/
int getMask() {
return mask;
}
/** {@collect.stats}
* {@description.open}
* Return the canonical string representation of the actions.
* Always returns present actions in the following order:
* read, write, execute, delete.
* {@description.close}
*
* @return the canonical string representation of the actions.
*/
private static String getActions(int mask)
{
StringBuilder sb = new StringBuilder();
boolean comma = false;
if ((mask & READ) == READ) {
comma = true;
sb.append("read");
}
if ((mask & WRITE) == WRITE) {
if (comma) sb.append(',');
else comma = true;
sb.append("write");
}
if ((mask & EXECUTE) == EXECUTE) {
if (comma) sb.append(',');
else comma = true;
sb.append("execute");
}
if ((mask & DELETE) == DELETE) {
if (comma) sb.append(',');
else comma = true;
sb.append("delete");
}
return sb.toString();
}
/** {@collect.stats}
* {@description.open}
* Returns the "canonical string representation" of the actions.
* That is, this method always returns present actions in the following order:
* read, write, execute, delete. For example, if this FilePermission object
* allows both write and read actions, a call to <code>getActions</code>
* will return the string "read,write".
* {@description.close}
*
* @return the canonical string representation of the actions.
*/
public String getActions()
{
if (actions == null)
actions = getActions(this.mask);
return actions;
}
/** {@collect.stats}
* {@description.open}
* Returns a new PermissionCollection object for storing FilePermission
* objects.
* <p>
* FilePermission objects must be stored in a manner that allows them
* to be inserted into the collection in any order, but that also enables the
* PermissionCollection <code>implies</code>
* method to be implemented in an efficient (and consistent) manner.
*
* <p>For example, if you have two FilePermissions:
* <OL>
* <LI> <code>"/tmp/-", "read"</code>
* <LI> <code>"/tmp/scratch/foo", "write"</code>
* </OL>
*
* <p>and you are calling the <code>implies</code> method with the FilePermission:
*
* <pre>
* "/tmp/scratch/foo", "read,write",
* </pre>
*
* then the <code>implies</code> function must
* take into account both the "/tmp/-" and "/tmp/scratch/foo"
* permissions, so the effective permission is "read,write",
* and <code>implies</code> returns true. The "implies" semantics for
* FilePermissions are handled properly by the PermissionCollection object
* returned by this <code>newPermissionCollection</code> method.
* {@description.close}
*
* @return a new PermissionCollection object suitable for storing
* FilePermissions.
*/
public PermissionCollection newPermissionCollection() {
return new FilePermissionCollection();
}
/** {@collect.stats}
* {@description.open}
* WriteObject is called to save the state of the FilePermission
* to a stream. The actions are serialized, and the superclass
* takes care of the name.
* {@description.close}
*/
private void writeObject(ObjectOutputStream s)
throws IOException
{
// Write out the actions. The superclass takes care of the name
// call getActions to make sure actions field is initialized
if (actions == null)
getActions();
s.defaultWriteObject();
}
/** {@collect.stats}
* {@description.open}
* readObject is called to restore the state of the FilePermission from
* a stream.
* {@description.close}
*/
private void readObject(ObjectInputStream s)
throws IOException, ClassNotFoundException
{
// Read in the actions, then restore everything else by calling init.
s.defaultReadObject();
init(getMask(actions));
}
}
/** {@collect.stats}
* {@description.open}
* A FilePermissionCollection stores a set of FilePermission permissions.
* FilePermission objects
* must be stored in a manner that allows them to be inserted in any
* order, but enable the implies function to evaluate the implies
* method.
* For example, if you have two FilePermissions:
* <OL>
* <LI> "/tmp/-", "read"
* <LI> "/tmp/scratch/foo", "write"
* </OL>
* And you are calling the implies function with the FilePermission:
* "/tmp/scratch/foo", "read,write", then the implies function must
* take into account both the /tmp/- and /tmp/scratch/foo
* permissions, so the effective permission is "read,write".
* {@description.close}
*
* @see java.security.Permission
* @see java.security.Permissions
* @see java.security.PermissionCollection
*
*
* @author Marianne Mueller
* @author Roland Schemers
*
* @serial include
*
*/
final class FilePermissionCollection extends PermissionCollection
implements Serializable {
// Not serialized; see serialization section at end of class
private transient List perms;
/** {@collect.stats}
* {@description.open}
* Create an empty FilePermissions object.
* {@description.close}
*
*/
public FilePermissionCollection() {
perms = new ArrayList();
}
/** {@collect.stats}
* {@description.open}
* Adds a permission to the FilePermissions. The key for the hash is
* permission.path.
* {@description.close}
*
* @param permission the Permission object to add.
*
* @exception IllegalArgumentException - if the permission is not a
* FilePermission
*
* @exception SecurityException - if this FilePermissionCollection object
* has been marked readonly
*/
public void add(Permission permission)
{
if (! (permission instanceof FilePermission))
throw new IllegalArgumentException("invalid permission: "+
permission);
if (isReadOnly())
throw new SecurityException(
"attempt to add a Permission to a readonly PermissionCollection");
synchronized (this) {
perms.add(permission);
}
}
/** {@collect.stats}
* {@description.open}
* Check and see if this set of permissions implies the permissions
* expressed in "permission".
* {@description.close}
*
* @param p the Permission object to compare
*
* @return true if "permission" is a proper subset of a permission in
* the set, false if not.
*/
public boolean implies(Permission permission)
{
if (! (permission instanceof FilePermission))
return false;
FilePermission fp = (FilePermission) permission;
int desired = fp.getMask();
int effective = 0;
int needed = desired;
synchronized (this) {
int len = perms.size();
for (int i = 0; i < len; i++) {
FilePermission x = (FilePermission) perms.get(i);
if (((needed & x.getMask()) != 0) && x.impliesIgnoreMask(fp)) {
effective |= x.getMask();
if ((effective & desired) == desired)
return true;
needed = (desired ^ effective);
}
}
}
return false;
}
/** {@collect.stats}
* {@description.open}
* Returns an enumeration of all the FilePermission objects in the
* container.
* {@description.close}
*
* @return an enumeration of all the FilePermission objects.
*/
public Enumeration elements() {
// Convert Iterator into Enumeration
synchronized (this) {
return Collections.enumeration(perms);
}
}
private static final long serialVersionUID = 2202956749081564585L;
// Need to maintain serialization interoperability with earlier releases,
// which had the serializable field:
// private Vector permissions;
/** {@collect.stats}
* @serialField permissions java.util.Vector
* A list of FilePermission objects.
*/
private static final ObjectStreamField[] serialPersistentFields = {
new ObjectStreamField("permissions", Vector.class),
};
/** {@collect.stats}
* @serialData "permissions" field (a Vector containing the FilePermissions).
*/
/*
* Writes the contents of the perms field out as a Vector for
* serialization compatibility with earlier releases.
*/
private void writeObject(ObjectOutputStream out) throws IOException {
// Don't call out.defaultWriteObject()
// Write out Vector
Vector permissions = new Vector(perms.size());
synchronized (this) {
permissions.addAll(perms);
}
ObjectOutputStream.PutField pfields = out.putFields();
pfields.put("permissions", permissions);
out.writeFields();
}
/*
* Reads in a Vector of FilePermissions and saves them in the perms field.
*/
private void readObject(ObjectInputStream in) throws IOException,
ClassNotFoundException {
// Don't call defaultReadObject()
// Read in serialized fields
ObjectInputStream.GetField gfields = in.readFields();
// Get the one we want
Vector permissions = (Vector)gfields.get("permissions", null);
perms = new ArrayList(permissions.size());
perms.addAll(permissions);
}
}
|
Java
|
/*
* Copyright (c) 2005, 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.util.*;
import java.io.File;
/** {@collect.stats}
* {@description.open}
* This class holds a set of filenames to be deleted on VM exit through a shutdown hook.
* A set is used both to prevent double-insertion of the same file as well as offer
* quick removal.
* {@description.close}
*/
class DeleteOnExitHook {
private static DeleteOnExitHook instance = null;
private static LinkedHashSet<String> files = new LinkedHashSet<String>();
static DeleteOnExitHook hook() {
if (instance == null)
instance = new DeleteOnExitHook();
return instance;
}
private DeleteOnExitHook() {}
static synchronized void add(String file) {
if(files == null)
throw new IllegalStateException("Shutdown in progress");
files.add(file);
}
void run() {
LinkedHashSet<String> theFiles;
synchronized (DeleteOnExitHook.class) {
theFiles = files;
files = null;
}
ArrayList<String> toBeDeleted = new ArrayList<String>(theFiles);
// reverse the list to maintain previous jdk deletion order.
// Last in first deleted.
Collections.reverse(toBeDeleted);
for (String filename : toBeDeleted) {
(new File(filename)).delete();
}
}
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Thrown when an instance is required to have a Serializable interface.
* The serialization runtime or the class of the instance can throw
* this exception. The argument should be the name of the class.
* {@description.close}
*
* @author unascribed
* @since JDK1.1
*/
public class NotSerializableException extends ObjectStreamException {
private static final long serialVersionUID = 2906642554793891381L;
/** {@collect.stats}
* {@description.open}
* Constructs a NotSerializableException object with message string.
* {@description.close}
*
* @param classname Class of the instance being serialized/deserialized.
*/
public NotSerializableException(String classname) {
super(classname);
}
/** {@collect.stats}
* {@description.open}
* Constructs a NotSerializableException object.
* {@description.close}
*/
public NotSerializableException() {
super();
}
}
|
Java
|
/*
* Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Signals that an I/O exception of some sort has occurred. This
* class is the general class of exceptions produced by failed or
* interrupted I/O operations.
* {@description.close}
*
* @author unascribed
* @see java.io.InputStream
* @see java.io.OutputStream
* @since JDK1.0
*/
public
class IOException extends Exception {
static final long serialVersionUID = 7818375828146090155L;
/** {@collect.stats}
* {@description.open}
* Constructs an {@code IOException} with {@code null}
* as its error detail message.
* {@description.close}
*/
public IOException() {
super();
}
/** {@collect.stats}
* {@description.open}
* Constructs an {@code IOException} with the specified detail message.
* {@description.close}
*
* @param message
* The detail message (which is saved for later retrieval
* by the {@link #getMessage()} method)
*/
public IOException(String message) {
super(message);
}
/** {@collect.stats}
* {@description.open}
* Constructs an {@code IOException} with the specified detail message
* and cause.
*
* <p> Note that the detail message associated with {@code cause} is
* <i>not</i> automatically incorporated into this exception's detail
* message.
* {@description.close}
*
* @param message
* The detail message (which is saved for later retrieval
* by the {@link #getMessage()} method)
*
* @param cause
* The cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A null value is permitted,
* and indicates that the cause is nonexistent or unknown.)
*
* @since 1.6
*/
public IOException(String message, Throwable cause) {
super(message, cause);
}
/** {@collect.stats}
* {@description.open}
* Constructs an {@code IOException} with the specified cause and a
* detail message of {@code (cause==null ? null : cause.toString())}
* (which typically contains the class and detail message of {@code cause}).
* This constructor is useful for IO exceptions that are little more
* than wrappers for other throwables.
* {@description.close}
*
* @param cause
* The cause (which is saved for later retrieval by the
* {@link #getCause()} method). (A null value is permitted,
* and indicates that the cause is nonexistent or unknown.)
*
* @since 1.6
*/
public IOException(Throwable cause) {
super(cause);
}
}
|
Java
|
/*
* Copyright (c) 1994, 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.net.URI;
import java.net.URL;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Map;
import java.util.Hashtable;
import java.security.AccessController;
import java.security.AccessControlException;
import java.security.SecureRandom;
import sun.security.action.GetPropertyAction;
/** {@collect.stats}
* {@description.open}
* An abstract representation of file and directory pathnames.
*
* <p> User interfaces and operating systems use system-dependent <em>pathname
* strings</em> to name files and directories. This class presents an
* abstract, system-independent view of hierarchical pathnames. An
* <em>abstract pathname</em> has two components:
*
* <ol>
* <li> An optional system-dependent <em>prefix</em> string,
* such as a disk-drive specifier, <code>"/"</code> for the UNIX root
* directory, or <code>"\\\\"</code> for a Microsoft Windows UNC pathname, and
* <li> A sequence of zero or more string <em>names</em>.
* </ol>
*
* The first name in an abstract pathname may be a directory name or, in the
* case of Microsoft Windows UNC pathnames, a hostname. Each subsequent name
* in an abstract pathname denotes a directory; the last name may denote
* either a directory or a file. The <em>empty</em> abstract pathname has no
* prefix and an empty name sequence.
*
* <p> The conversion of a pathname string to or from an abstract pathname is
* inherently system-dependent. When an abstract pathname is converted into a
* pathname string, each name is separated from the next by a single copy of
* the default <em>separator character</em>. The default name-separator
* character is defined by the system property <code>file.separator</code>, and
* is made available in the public static fields <code>{@link
* #separator}</code> and <code>{@link #separatorChar}</code> of this class.
* When a pathname string is converted into an abstract pathname, the names
* within it may be separated by the default name-separator character or by any
* other name-separator character that is supported by the underlying system.
*
* <p> A pathname, whether abstract or in string form, may be either
* <em>absolute</em> or <em>relative</em>. An absolute pathname is complete in
* that no other information is required in order to locate the file that it
* denotes. A relative pathname, in contrast, must be interpreted in terms of
* information taken from some other pathname. By default the classes in the
* <code>java.io</code> package always resolve relative pathnames against the
* current user directory. This directory is named by the system property
* <code>user.dir</code>, and is typically the directory in which the Java
* virtual machine was invoked.
*
* <p> The <em>parent</em> of an abstract pathname may be obtained by invoking
* the {@link #getParent} method of this class and consists of the pathname's
* prefix and each name in the pathname's name sequence except for the last.
* Each directory's absolute pathname is an ancestor of any <tt>File</tt>
* object with an absolute abstract pathname which begins with the directory's
* absolute pathname. For example, the directory denoted by the abstract
* pathname <tt>"/usr"</tt> is an ancestor of the directory denoted by the
* pathname <tt>"/usr/local/bin"</tt>.
*
* <p> The prefix concept is used to handle root directories on UNIX platforms,
* and drive specifiers, root directories and UNC pathnames on Microsoft Windows platforms,
* as follows:
*
* <ul>
*
* <li> For UNIX platforms, the prefix of an absolute pathname is always
* <code>"/"</code>. Relative pathnames have no prefix. The abstract pathname
* denoting the root directory has the prefix <code>"/"</code> and an empty
* name sequence.
*
* <li> For Microsoft Windows platforms, the prefix of a pathname that contains a drive
* specifier consists of the drive letter followed by <code>":"</code> and
* possibly followed by <code>"\\"</code> if the pathname is absolute. The
* prefix of a UNC pathname is <code>"\\\\"</code>; the hostname and the share
* name are the first two names in the name sequence. A relative pathname that
* does not specify a drive has no prefix.
*
* </ul>
*
* <p> Instances of this class may or may not denote an actual file-system
* object such as a file or a directory. If it does denote such an object
* then that object resides in a <i>partition</i>. A partition is an
* operating system-specific portion of storage for a file system. A single
* storage device (e.g. a physical disk-drive, flash memory, CD-ROM) may
* contain multiple partitions. The object, if any, will reside on the
* partition <a name="partName">named</a> by some ancestor of the absolute
* form of this pathname.
*
* <p> A file system may implement restrictions to certain operations on the
* actual file-system object, such as reading, writing, and executing. These
* restrictions are collectively known as <i>access permissions</i>. The file
* system may have multiple sets of access permissions on a single object.
* For example, one set may apply to the object's <i>owner</i>, and another
* may apply to all other users. The access permissions on an object may
* cause some methods in this class to fail.
*
* <p> Instances of the <code>File</code> class are immutable; that is, once
* created, the abstract pathname represented by a <code>File</code> object
* will never change.
* {@description.close}
*
* @author unascribed
* @since JDK1.0
*/
public class File
implements Serializable, Comparable<File>
{
/** {@collect.stats}
* {@description.open}
* The FileSystem object representing the platform's local file system.
* {@description.close}
*/
static private FileSystem fs = FileSystem.getFileSystem();
/** {@collect.stats}
* {@description.open}
* This abstract pathname's normalized pathname string. A normalized
* pathname string uses the default name-separator character and does not
* contain any duplicate or redundant separators.
* {@description.close}
*
* @serial
*/
private String path;
/** {@collect.stats}
* {@description.open}
* The length of this abstract pathname's prefix, or zero if it has no
* prefix.
* {@description.close}
*/
private transient int prefixLength;
/** {@collect.stats}
* {@description.open}
* Returns the length of this abstract pathname's prefix.
* For use by FileSystem classes.
* {@description.close}
*/
int getPrefixLength() {
return prefixLength;
}
/** {@collect.stats}
* {@description.open}
* The system-dependent default name-separator character. This field is
* initialized to contain the first character of the value of the system
* property <code>file.separator</code>. On UNIX systems the value of this
* field is <code>'/'</code>; on Microsoft Windows systems it is <code>'\\'</code>.
* {@description.close}
*
* @see java.lang.System#getProperty(java.lang.String)
*/
public static final char separatorChar = fs.getSeparator();
/** {@collect.stats}
* {@description.open}
* The system-dependent default name-separator character, represented as a
* string for convenience. This string contains a single character, namely
* <code>{@link #separatorChar}</code>.
* {@description.close}
*/
public static final String separator = "" + separatorChar;
/** {@collect.stats}
* {@description.open}
* The system-dependent path-separator character. This field is
* initialized to contain the first character of the value of the system
* property <code>path.separator</code>. This character is used to
* separate filenames in a sequence of files given as a <em>path list</em>.
* On UNIX systems, this character is <code>':'</code>; on Microsoft Windows systems it
* is <code>';'</code>.
* {@description.close}
*
* @see java.lang.System#getProperty(java.lang.String)
*/
public static final char pathSeparatorChar = fs.getPathSeparator();
/** {@collect.stats}
* {@description.open}
* The system-dependent path-separator character, represented as a string
* for convenience. This string contains a single character, namely
* <code>{@link #pathSeparatorChar}</code>.
* {@description.close}
*/
public static final String pathSeparator = "" + pathSeparatorChar;
/* -- Constructors -- */
/** {@collect.stats}
* {@description.open}
* Internal constructor for already-normalized pathname strings.
* {@description.close}
*/
private File(String pathname, int prefixLength) {
this.path = pathname;
this.prefixLength = prefixLength;
}
/** {@collect.stats}
* {@description.open}
* Internal constructor for already-normalized pathname strings.
* The parameter order is used to disambiguate this method from the
* public(File, String) constructor.
* {@description.close}
*/
private File(String child, File parent) {
assert parent.path != null;
assert (!parent.path.equals(""));
this.path = fs.resolve(parent.path, child);
this.prefixLength = parent.prefixLength;
}
/** {@collect.stats}
* {@description.open}
* Creates a new <code>File</code> instance by converting the given
* pathname string into an abstract pathname. If the given string is
* the empty string, then the result is the empty abstract pathname.
* {@description.close}
*
* @param pathname A pathname string
* @throws NullPointerException
* If the <code>pathname</code> argument is <code>null</code>
*/
public File(String pathname) {
if (pathname == null) {
throw new NullPointerException();
}
this.path = fs.normalize(pathname);
this.prefixLength = fs.prefixLength(this.path);
}
/* Note: The two-argument File constructors do not interpret an empty
parent abstract pathname as the current user directory. An empty parent
instead causes the child to be resolved against the system-dependent
directory defined by the FileSystem.getDefaultParent method. On Unix
this default is "/", while on Microsoft Windows it is "\\". This is required for
compatibility with the original behavior of this class. */
/** {@collect.stats}
* {@description.open}
* Creates a new <code>File</code> instance from a parent pathname string
* and a child pathname string.
*
* <p> If <code>parent</code> is <code>null</code> then the new
* <code>File</code> instance is created as if by invoking the
* single-argument <code>File</code> constructor on the given
* <code>child</code> pathname string.
*
* <p> Otherwise the <code>parent</code> pathname string is taken to denote
* a directory, and the <code>child</code> pathname string is taken to
* denote either a directory or a file. If the <code>child</code> pathname
* string is absolute then it is converted into a relative pathname in a
* system-dependent way. If <code>parent</code> is the empty string then
* the new <code>File</code> instance is created by converting
* <code>child</code> into an abstract pathname and resolving the result
* against a system-dependent default directory. Otherwise each pathname
* string is converted into an abstract pathname and the child abstract
* pathname is resolved against the parent.
* {@description.close}
*
* @param parent The parent pathname string
* @param child The child pathname string
* @throws NullPointerException
* If <code>child</code> is <code>null</code>
*/
public File(String parent, String child) {
if (child == null) {
throw new NullPointerException();
}
if (parent != null) {
if (parent.equals("")) {
this.path = fs.resolve(fs.getDefaultParent(),
fs.normalize(child));
} else {
this.path = fs.resolve(fs.normalize(parent),
fs.normalize(child));
}
} else {
this.path = fs.normalize(child);
}
this.prefixLength = fs.prefixLength(this.path);
}
/** {@collect.stats}
* {@description.open}
* Creates a new <code>File</code> instance from a parent abstract
* pathname and a child pathname string.
*
* <p> If <code>parent</code> is <code>null</code> then the new
* <code>File</code> instance is created as if by invoking the
* single-argument <code>File</code> constructor on the given
* <code>child</code> pathname string.
*
* <p> Otherwise the <code>parent</code> abstract pathname is taken to
* denote a directory, and the <code>child</code> pathname string is taken
* to denote either a directory or a file. If the <code>child</code>
* pathname string is absolute then it is converted into a relative
* pathname in a system-dependent way. If <code>parent</code> is the empty
* abstract pathname then the new <code>File</code> instance is created by
* converting <code>child</code> into an abstract pathname and resolving
* the result against a system-dependent default directory. Otherwise each
* pathname string is converted into an abstract pathname and the child
* abstract pathname is resolved against the parent.
* {@description.close}
*
* @param parent The parent abstract pathname
* @param child The child pathname string
* @throws NullPointerException
* If <code>child</code> is <code>null</code>
*/
public File(File parent, String child) {
if (child == null) {
throw new NullPointerException();
}
if (parent != null) {
if (parent.path.equals("")) {
this.path = fs.resolve(fs.getDefaultParent(),
fs.normalize(child));
} else {
this.path = fs.resolve(parent.path,
fs.normalize(child));
}
} else {
this.path = fs.normalize(child);
}
this.prefixLength = fs.prefixLength(this.path);
}
/** {@collect.stats}
* {@description.open}
* Creates a new <tt>File</tt> instance by converting the given
* <tt>file:</tt> URI into an abstract pathname.
*
* <p> The exact form of a <tt>file:</tt> URI is system-dependent, hence
* the transformation performed by this constructor is also
* system-dependent.
*
* <p> For a given abstract pathname <i>f</i> it is guaranteed that
*
* <blockquote><tt>
* new File(</tt><i> f</i><tt>.{@link #toURI() toURI}()).equals(</tt><i> f</i><tt>.{@link #getAbsoluteFile() getAbsoluteFile}())
* </tt></blockquote>
*
* so long as the original abstract pathname, the URI, and the new abstract
* pathname are all created in (possibly different invocations of) the same
* Java virtual machine. This relationship typically does not hold,
* however, when a <tt>file:</tt> URI that is created in a virtual machine
* on one operating system is converted into an abstract pathname in a
* virtual machine on a different operating system.
* {@description.close}
*
* @param uri
* An absolute, hierarchical URI with a scheme equal to
* <tt>"file"</tt>, a non-empty path component, and undefined
* authority, query, and fragment components
*
* @throws NullPointerException
* If <tt>uri</tt> is <tt>null</tt>
*
* @throws IllegalArgumentException
* If the preconditions on the parameter do not hold
*
* @see #toURI()
* @see java.net.URI
* @since 1.4
*/
public File(URI uri) {
// Check our many preconditions
if (!uri.isAbsolute())
throw new IllegalArgumentException("URI is not absolute");
if (uri.isOpaque())
throw new IllegalArgumentException("URI is not hierarchical");
String scheme = uri.getScheme();
if ((scheme == null) || !scheme.equalsIgnoreCase("file"))
throw new IllegalArgumentException("URI scheme is not \"file\"");
if (uri.getAuthority() != null)
throw new IllegalArgumentException("URI has an authority component");
if (uri.getFragment() != null)
throw new IllegalArgumentException("URI has a fragment component");
if (uri.getQuery() != null)
throw new IllegalArgumentException("URI has a query component");
String p = uri.getPath();
if (p.equals(""))
throw new IllegalArgumentException("URI path component is empty");
// Okay, now initialize
p = fs.fromURIPath(p);
if (File.separatorChar != '/')
p = p.replace('/', File.separatorChar);
this.path = fs.normalize(p);
this.prefixLength = fs.prefixLength(this.path);
}
/* -- Path-component accessors -- */
/** {@collect.stats}
* {@description.open}
* Returns the name of the file or directory denoted by this abstract
* pathname. This is just the last name in the pathname's name
* sequence. If the pathname's name sequence is empty, then the empty
* string is returned.
* {@description.close}
*
* @return The name of the file or directory denoted by this abstract
* pathname, or the empty string if this pathname's name sequence
* is empty
*/
public String getName() {
int index = path.lastIndexOf(separatorChar);
if (index < prefixLength) return path.substring(prefixLength);
return path.substring(index + 1);
}
/** {@collect.stats}
* {@description.open}
* Returns the pathname string of this abstract pathname's parent, or
* <code>null</code> if this pathname does not name a parent directory.
*
* <p> The <em>parent</em> of an abstract pathname consists of the
* pathname's prefix, if any, and each name in the pathname's name
* sequence except for the last. If the name sequence is empty then
* the pathname does not name a parent directory.
* {@description.close}
*
* @return The pathname string of the parent directory named by this
* abstract pathname, or <code>null</code> if this pathname
* does not name a parent
*/
public String getParent() {
int index = path.lastIndexOf(separatorChar);
if (index < prefixLength) {
if ((prefixLength > 0) && (path.length() > prefixLength))
return path.substring(0, prefixLength);
return null;
}
return path.substring(0, index);
}
/** {@collect.stats}
* {@description.open}
* Returns the abstract pathname of this abstract pathname's parent,
* or <code>null</code> if this pathname does not name a parent
* directory.
*
* <p> The <em>parent</em> of an abstract pathname consists of the
* pathname's prefix, if any, and each name in the pathname's name
* sequence except for the last. If the name sequence is empty then
* the pathname does not name a parent directory.
* {@description.close}
*
* @return The abstract pathname of the parent directory named by this
* abstract pathname, or <code>null</code> if this pathname
* does not name a parent
*
* @since 1.2
*/
public File getParentFile() {
String p = this.getParent();
if (p == null) return null;
return new File(p, this.prefixLength);
}
/** {@collect.stats}
* {@description.open}
* Converts this abstract pathname into a pathname string. The resulting
* string uses the {@link #separator default name-separator character} to
* separate the names in the name sequence.
* {@description.close}
*
* @return The string form of this abstract pathname
*/
public String getPath() {
return path;
}
/* -- Path operations -- */
/** {@collect.stats}
* {@description.open}
* Tests whether this abstract pathname is absolute. The definition of
* absolute pathname is system dependent. On UNIX systems, a pathname is
* absolute if its prefix is <code>"/"</code>. On Microsoft Windows systems, a
* pathname is absolute if its prefix is a drive specifier followed by
* <code>"\\"</code>, or if its prefix is <code>"\\\\"</code>.
* {@description.close}
*
* @return <code>true</code> if this abstract pathname is absolute,
* <code>false</code> otherwise
*/
public boolean isAbsolute() {
return fs.isAbsolute(this);
}
/** {@collect.stats}
* {@description.open}
* Returns the absolute pathname string of this abstract pathname.
*
* <p> If this abstract pathname is already absolute, then the pathname
* string is simply returned as if by the <code>{@link #getPath}</code>
* method. If this abstract pathname is the empty abstract pathname then
* the pathname string of the current user directory, which is named by the
* system property <code>user.dir</code>, is returned. Otherwise this
* pathname is resolved in a system-dependent way. On UNIX systems, a
* relative pathname is made absolute by resolving it against the current
* user directory. On Microsoft Windows systems, a relative pathname is made absolute
* by resolving it against the current directory of the drive named by the
* pathname, if any; if not, it is resolved against the current user
* directory.
* {@description.close}
*
* @return The absolute pathname string denoting the same file or
* directory as this abstract pathname
*
* @throws SecurityException
* If a required system property value cannot be accessed.
*
* @see java.io.File#isAbsolute()
*/
public String getAbsolutePath() {
return fs.resolve(this);
}
/** {@collect.stats}
* {@description.open}
* Returns the absolute form of this abstract pathname. Equivalent to
* <code>new File(this.{@link #getAbsolutePath})</code>.
* {@description.close}
*
* @return The absolute abstract pathname denoting the same file or
* directory as this abstract pathname
*
* @throws SecurityException
* If a required system property value cannot be accessed.
*
* @since 1.2
*/
public File getAbsoluteFile() {
String absPath = getAbsolutePath();
return new File(absPath, fs.prefixLength(absPath));
}
/** {@collect.stats}
* {@description.open}
* Returns the canonical pathname string of this abstract pathname.
*
* <p> A canonical pathname is both absolute and unique. The precise
* definition of canonical form is system-dependent. This method first
* converts this pathname to absolute form if necessary, as if by invoking the
* {@link #getAbsolutePath} method, and then maps it to its unique form in a
* system-dependent way. This typically involves removing redundant names
* such as <tt>"."</tt> and <tt>".."</tt> from the pathname, resolving
* symbolic links (on UNIX platforms), and converting drive letters to a
* standard case (on Microsoft Windows platforms).
*
* <p> Every pathname that denotes an existing file or directory has a
* unique canonical form. Every pathname that denotes a nonexistent file
* or directory also has a unique canonical form. The canonical form of
* the pathname of a nonexistent file or directory may be different from
* the canonical form of the same pathname after the file or directory is
* created. Similarly, the canonical form of the pathname of an existing
* file or directory may be different from the canonical form of the same
* pathname after the file or directory is deleted.
* {@description.close}
*
* @return The canonical pathname string denoting the same file or
* directory as this abstract pathname
*
* @throws IOException
* If an I/O error occurs, which is possible because the
* construction of the canonical pathname may require
* filesystem queries
*
* @throws SecurityException
* If a required system property value cannot be accessed, or
* if a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead}</code> method denies
* read access to the file
*
* @since JDK1.1
*/
public String getCanonicalPath() throws IOException {
return fs.canonicalize(fs.resolve(this));
}
/** {@collect.stats}
* {@description.open}
* Returns the canonical form of this abstract pathname. Equivalent to
* <code>new File(this.{@link #getCanonicalPath})</code>.
* {@description.close}
*
* @return The canonical pathname string denoting the same file or
* directory as this abstract pathname
*
* @throws IOException
* If an I/O error occurs, which is possible because the
* construction of the canonical pathname may require
* filesystem queries
*
* @throws SecurityException
* If a required system property value cannot be accessed, or
* if a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead}</code> method denies
* read access to the file
*
* @since 1.2
*/
public File getCanonicalFile() throws IOException {
String canonPath = getCanonicalPath();
return new File(canonPath, fs.prefixLength(canonPath));
}
private static String slashify(String path, boolean isDirectory) {
String p = path;
if (File.separatorChar != '/')
p = p.replace(File.separatorChar, '/');
if (!p.startsWith("/"))
p = "/" + p;
if (!p.endsWith("/") && isDirectory)
p = p + "/";
return p;
}
/** {@collect.stats}
* {@description.open}
* Converts this abstract pathname into a <code>file:</code> URL. The
* exact form of the URL is system-dependent. If it can be determined that
* the file denoted by this abstract pathname is a directory, then the
* resulting URL will end with a slash.
* {@description.close}
*
* @return A URL object representing the equivalent file URL
*
* @throws MalformedURLException
* If the path cannot be parsed as a URL
*
* @see #toURI()
* @see java.net.URI
* @see java.net.URI#toURL()
* @see java.net.URL
* @since 1.2
*
* @deprecated This method does not automatically escape characters that
* are illegal in URLs. It is recommended that new code convert an
* abstract pathname into a URL by first converting it into a URI, via the
* {@link #toURI() toURI} method, and then converting the URI into a URL
* via the {@link java.net.URI#toURL() URI.toURL} method.
*/
@Deprecated
public URL toURL() throws MalformedURLException {
return new URL("file", "", slashify(getAbsolutePath(), isDirectory()));
}
/** {@collect.stats}
* {@description.open}
* Constructs a <tt>file:</tt> URI that represents this abstract pathname.
*
* <p> The exact form of the URI is system-dependent. If it can be
* determined that the file denoted by this abstract pathname is a
* directory, then the resulting URI will end with a slash.
*
* <p> For a given abstract pathname <i>f</i>, it is guaranteed that
*
* <blockquote><tt>
* new {@link #File(java.net.URI) File}(</tt><i> f</i><tt>.toURI()).equals(</tt><i> f</i><tt>.{@link #getAbsoluteFile() getAbsoluteFile}())
* </tt></blockquote>
*
* so long as the original abstract pathname, the URI, and the new abstract
* pathname are all created in (possibly different invocations of) the same
* Java virtual machine. Due to the system-dependent nature of abstract
* pathnames, however, this relationship typically does not hold when a
* <tt>file:</tt> URI that is created in a virtual machine on one operating
* system is converted into an abstract pathname in a virtual machine on a
* different operating system.
* {@description.close}
*
* @return An absolute, hierarchical URI with a scheme equal to
* <tt>"file"</tt>, a path representing this abstract pathname,
* and undefined authority, query, and fragment components
* @throws SecurityException If a required system property value cannot
* be accessed.
*
* @see #File(java.net.URI)
* @see java.net.URI
* @see java.net.URI#toURL()
* @since 1.4
*/
public URI toURI() {
try {
File f = getAbsoluteFile();
String sp = slashify(f.getPath(), f.isDirectory());
if (sp.startsWith("//"))
sp = "//" + sp;
return new URI("file", null, sp, null);
} catch (URISyntaxException x) {
throw new Error(x); // Can't happen
}
}
/* -- Attribute accessors -- */
/** {@collect.stats}
* {@description.open}
* Tests whether the application can read the file denoted by this
* abstract pathname.
* {@description.close}
*
* @return <code>true</code> if and only if the file specified by this
* abstract pathname exists <em>and</em> can be read by the
* application; <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file
*/
public boolean canRead() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(path);
}
return fs.checkAccess(this, FileSystem.ACCESS_READ);
}
/** {@collect.stats}
* {@description.open}
* Tests whether the application can modify the file denoted by this
* abstract pathname.
* {@description.close}
*
* @return <code>true</code> if and only if the file system actually
* contains a file denoted by this abstract pathname <em>and</em>
* the application is allowed to write to the file;
* <code>false</code> otherwise.
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the file
*/
public boolean canWrite() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(path);
}
return fs.checkAccess(this, FileSystem.ACCESS_WRITE);
}
/** {@collect.stats}
* {@description.open}
* Tests whether the file or directory denoted by this abstract pathname
* exists.
* {@description.close}
*
* @return <code>true</code> if and only if the file or directory denoted
* by this abstract pathname exists; <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file or directory
*/
public boolean exists() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(path);
}
return ((fs.getBooleanAttributes(this) & FileSystem.BA_EXISTS) != 0);
}
/** {@collect.stats}
* {@description.open}
* Tests whether the file denoted by this abstract pathname is a
* directory.
* {@description.close}
*
* @return <code>true</code> if and only if the file denoted by this
* abstract pathname exists <em>and</em> is a directory;
* <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file
*/
public boolean isDirectory() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(path);
}
return ((fs.getBooleanAttributes(this) & FileSystem.BA_DIRECTORY)
!= 0);
}
/** {@collect.stats}
* {@description.open}
* Tests whether the file denoted by this abstract pathname is a normal
* file. A file is <em>normal</em> if it is not a directory and, in
* addition, satisfies other system-dependent criteria. Any non-directory
* file created by a Java application is guaranteed to be a normal file.
* {@description.close}
*
* @return <code>true</code> if and only if the file denoted by this
* abstract pathname exists <em>and</em> is a normal file;
* <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file
*/
public boolean isFile() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(path);
}
return ((fs.getBooleanAttributes(this) & FileSystem.BA_REGULAR) != 0);
}
/** {@collect.stats}
* {@description.open}
* Tests whether the file named by this abstract pathname is a hidden
* file. The exact definition of <em>hidden</em> is system-dependent. On
* UNIX systems, a file is considered to be hidden if its name begins with
* a period character (<code>'.'</code>). On Microsoft Windows systems, a file is
* considered to be hidden if it has been marked as such in the filesystem.
* {@description.close}
*
* @return <code>true</code> if and only if the file denoted by this
* abstract pathname is hidden according to the conventions of the
* underlying platform
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file
*
* @since 1.2
*/
public boolean isHidden() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(path);
}
return ((fs.getBooleanAttributes(this) & FileSystem.BA_HIDDEN) != 0);
}
/** {@collect.stats}
* {@description.open}
* Returns the time that the file denoted by this abstract pathname was
* last modified.
* {@description.close}
*
* @return A <code>long</code> value representing the time the file was
* last modified, measured in milliseconds since the epoch
* (00:00:00 GMT, January 1, 1970), or <code>0L</code> if the
* file does not exist or if an I/O error occurs
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file
*/
public long lastModified() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(path);
}
return fs.getLastModifiedTime(this);
}
/** {@collect.stats}
* {@description.open}
* Returns the length of the file denoted by this abstract pathname.
* {@description.close}
* {@property.open runtime formal:java.io.File_LengthOnDirectory}
* The return value is unspecified if this pathname denotes a directory.
* {@property.close}
*
* @return The length, in bytes, of the file denoted by this abstract
* pathname, or <code>0L</code> if the file does not exist. Some
* operating systems may return <code>0L</code> for pathnames
* denoting system-dependent entities such as devices or pipes.
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method denies read access to the file
*/
public long length() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(path);
}
return fs.getLength(this);
}
/* -- File operations -- */
/** {@collect.stats}
* {@description.open}
* Atomically creates a new, empty file named by this abstract pathname if
* and only if a file with this name does not yet exist. The check for the
* existence of the file and the creation of the file if it does not exist
* are a single operation that is atomic with respect to all other
* filesystem activities that might affect the file.
* {@description.close}
* {@property.open uncheckable}
* <P>
* Note: this method should <i>not</i> be used for file-locking, as
* the resulting protocol cannot be made to work reliably. The
* {@link java.nio.channels.FileLock FileLock}
* facility should be used instead.
* {@property.close}
*
* @return <code>true</code> if the named file does not exist and was
* successfully created; <code>false</code> if the named file
* already exists
*
* @throws IOException
* If an I/O error occurred
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the file
*
* @since 1.2
*/
public boolean createNewFile() throws IOException {
SecurityManager security = System.getSecurityManager();
if (security != null) security.checkWrite(path);
return fs.createFileExclusively(path);
}
/** {@collect.stats}
* {@description.open}
* Deletes the file or directory denoted by this abstract pathname. If
* this pathname denotes a directory, then the directory must be empty in
* order to be deleted.
* {@description.close}
*
* @return <code>true</code> if and only if the file or directory is
* successfully deleted; <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkDelete}</code> method denies
* delete access to the file
*/
public boolean delete() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkDelete(path);
}
return fs.delete(this);
}
/** {@collect.stats}
* {@description.open}
* Requests that the file or directory denoted by this abstract
* pathname be deleted when the virtual machine terminates.
* Files (or directories) are deleted in the reverse order that
* they are registered. Invoking this method to delete a file or
* directory that is already registered for deletion has no effect.
* Deletion will be attempted only for normal termination of the
* virtual machine, as defined by the Java Language Specification.
*
* <p> Once deletion has been requested, it is not possible to cancel the
* request. This method should therefore be used with care.
* {@description.close}
*
* {@property.open uncheckable}
* <P>
* Note: this method should <i>not</i> be used for file-locking, as
* the resulting protocol cannot be made to work reliably. The
* {@link java.nio.channels.FileLock FileLock}
* facility should be used instead.
* {@property.close}
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkDelete}</code> method denies
* delete access to the file
*
* @see #delete
*
* @since 1.2
*/
public void deleteOnExit() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkDelete(path);
}
DeleteOnExitHook.add(path);
}
/** {@collect.stats}
* {@description.open}
* Returns an array of strings naming the files and directories in the
* directory denoted by this abstract pathname.
*
* <p> If this abstract pathname does not denote a directory, then this
* method returns {@code null}. Otherwise an array of strings is
* returned, one for each file or directory in the directory. Names
* denoting the directory itself and the directory's parent directory are
* not included in the result. Each string is a file name rather than a
* complete path.
*
* <p> There is no guarantee that the name strings in the resulting array
* will appear in any specific order; they are not, in particular,
* guaranteed to appear in alphabetical order.
* {@description.close}
*
* @return An array of strings naming the files and directories in the
* directory denoted by this abstract pathname. The array will be
* empty if the directory is empty. Returns {@code null} if
* this abstract pathname does not denote a directory, or if an
* I/O error occurs.
*
* @throws SecurityException
* If a security manager exists and its {@link
* SecurityManager#checkRead(String)} method denies read access to
* the directory
*/
public String[] list() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkRead(path);
}
return fs.list(this);
}
/** {@collect.stats}
* {@description.open}
* Returns an array of strings naming the files and directories in the
* directory denoted by this abstract pathname that satisfy the specified
* filter. The behavior of this method is the same as that of the
* {@link #list()} method, except that the strings in the returned array
* must satisfy the filter. If the given {@code filter} is {@code null}
* then all names are accepted. Otherwise, a name satisfies the filter if
* and only if the value {@code true} results when the {@link
* FilenameFilter#accept FilenameFilter.accept(File, String)} method
* of the filter is invoked on this abstract pathname and the name of a
* file or directory in the directory that it denotes.
* {@description.close}
*
* @param filter
* A filename filter
*
* @return An array of strings naming the files and directories in the
* directory denoted by this abstract pathname that were accepted
* by the given {@code filter}. The array will be empty if the
* directory is empty or if no names were accepted by the filter.
* Returns {@code null} if this abstract pathname does not denote
* a directory, or if an I/O error occurs.
*
* @throws SecurityException
* If a security manager exists and its {@link
* SecurityManager#checkRead(String)} method denies read access to
* the directory
*/
public String[] list(FilenameFilter filter) {
String names[] = list();
if ((names == null) || (filter == null)) {
return names;
}
ArrayList v = new ArrayList();
for (int i = 0 ; i < names.length ; i++) {
if (filter.accept(this, names[i])) {
v.add(names[i]);
}
}
return (String[])(v.toArray(new String[v.size()]));
}
/** {@collect.stats}
* {@description.open}
* Returns an array of abstract pathnames denoting the files in the
* directory denoted by this abstract pathname.
*
* <p> If this abstract pathname does not denote a directory, then this
* method returns {@code null}. Otherwise an array of {@code File} objects
* is returned, one for each file or directory in the directory. Pathnames
* denoting the directory itself and the directory's parent directory are
* not included in the result. Each resulting abstract pathname is
* constructed from this abstract pathname using the {@link #File(File,
* String) File(File, String)} constructor. Therefore if this
* pathname is absolute then each resulting pathname is absolute; if this
* pathname is relative then each resulting pathname will be relative to
* the same directory.
*
* <p> There is no guarantee that the name strings in the resulting array
* will appear in any specific order; they are not, in particular,
* guaranteed to appear in alphabetical order.
* {@description.close}
*
* @return An array of abstract pathnames denoting the files and
* directories in the directory denoted by this abstract pathname.
* The array will be empty if the directory is empty. Returns
* {@code null} if this abstract pathname does not denote a
* directory, or if an I/O error occurs.
*
* @throws SecurityException
* If a security manager exists and its {@link
* SecurityManager#checkRead(String)} method denies read access to
* the directory
*
* @since 1.2
*/
public File[] listFiles() {
String[] ss = list();
if (ss == null) return null;
int n = ss.length;
File[] fs = new File[n];
for (int i = 0; i < n; i++) {
fs[i] = new File(ss[i], this);
}
return fs;
}
/** {@collect.stats}
* {@description.open}
* Returns an array of abstract pathnames denoting the files and
* directories in the directory denoted by this abstract pathname that
* satisfy the specified filter. The behavior of this method is the same
* as that of the {@link #listFiles()} method, except that the pathnames in
* the returned array must satisfy the filter. If the given {@code filter}
* is {@code null} then all pathnames are accepted. Otherwise, a pathname
* satisfies the filter if and only if the value {@code true} results when
* the {@link FilenameFilter#accept
* FilenameFilter.accept(File, String)} method of the filter is
* invoked on this abstract pathname and the name of a file or directory in
* the directory that it denotes.
* {@description.close}
*
* @param filter
* A filename filter
*
* @return An array of abstract pathnames denoting the files and
* directories in the directory denoted by this abstract pathname.
* The array will be empty if the directory is empty. Returns
* {@code null} if this abstract pathname does not denote a
* directory, or if an I/O error occurs.
*
* @throws SecurityException
* If a security manager exists and its {@link
* SecurityManager#checkRead(String)} method denies read access to
* the directory
*
* @since 1.2
*/
public File[] listFiles(FilenameFilter filter) {
String ss[] = list();
if (ss == null) return null;
ArrayList<File> files = new ArrayList<File>();
for (String s : ss)
if ((filter == null) || filter.accept(this, s))
files.add(new File(s, this));
return files.toArray(new File[files.size()]);
}
/** {@collect.stats}
* {@description.open}
* Returns an array of abstract pathnames denoting the files and
* directories in the directory denoted by this abstract pathname that
* satisfy the specified filter. The behavior of this method is the same
* as that of the {@link #listFiles()} method, except that the pathnames in
* the returned array must satisfy the filter. If the given {@code filter}
* is {@code null} then all pathnames are accepted. Otherwise, a pathname
* satisfies the filter if and only if the value {@code true} results when
* the {@link FileFilter#accept FileFilter.accept(File)} method of the
* filter is invoked on the pathname.
* {@description.close}
*
* @param filter
* A file filter
*
* @return An array of abstract pathnames denoting the files and
* directories in the directory denoted by this abstract pathname.
* The array will be empty if the directory is empty. Returns
* {@code null} if this abstract pathname does not denote a
* directory, or if an I/O error occurs.
*
* @throws SecurityException
* If a security manager exists and its {@link
* SecurityManager#checkRead(String)} method denies read access to
* the directory
*
* @since 1.2
*/
public File[] listFiles(FileFilter filter) {
String ss[] = list();
if (ss == null) return null;
ArrayList<File> files = new ArrayList<File>();
for (String s : ss) {
File f = new File(s, this);
if ((filter == null) || filter.accept(f))
files.add(f);
}
return files.toArray(new File[files.size()]);
}
/** {@collect.stats}
* {@description.open}
* Creates the directory named by this abstract pathname.
* {@description.close}
*
* @return <code>true</code> if and only if the directory was
* created; <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method does not permit the named directory to be created
*/
public boolean mkdir() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(path);
}
return fs.createDirectory(this);
}
/** {@collect.stats}
* {@description.open}
* Creates the directory named by this abstract pathname, including any
* necessary but nonexistent parent directories. Note that if this
* operation fails it may have succeeded in creating some of the necessary
* parent directories.
* {@description.close}
*
* @return <code>true</code> if and only if the directory was created,
* along with all necessary parent directories; <code>false</code>
* otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkRead(java.lang.String)}</code>
* method does not permit verification of the existence of the
* named directory and all necessary parent directories; or if
* the <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method does not permit the named directory and all necessary
* parent directories to be created
*/
public boolean mkdirs() {
if (exists()) {
return false;
}
if (mkdir()) {
return true;
}
File canonFile = null;
try {
canonFile = getCanonicalFile();
} catch (IOException e) {
return false;
}
File parent = canonFile.getParentFile();
return (parent != null && (parent.mkdirs() || parent.exists()) &&
canonFile.mkdir());
}
/** {@collect.stats}
* {@description.open}
* Renames the file denoted by this abstract pathname.
*
* <p> Many aspects of the behavior of this method are inherently
* platform-dependent: The rename operation might not be able to move a
* file from one filesystem to another, it might not be atomic, and it
* might not succeed if a file with the destination abstract pathname
* already exists. The return value should always be checked to make sure
* that the rename operation was successful.
* {@description.close}
*
* @param dest The new abstract pathname for the named file
*
* @return <code>true</code> if and only if the renaming succeeded;
* <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to either the old or new pathnames
*
* @throws NullPointerException
* If parameter <code>dest</code> is <code>null</code>
*/
public boolean renameTo(File dest) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(path);
security.checkWrite(dest.path);
}
return fs.rename(this, dest);
}
/** {@collect.stats}
* {@description.open}
* Sets the last-modified time of the file or directory named by this
* abstract pathname.
*
* <p> All platforms support file-modification times to the nearest second,
* but some provide more precision. The argument will be truncated to fit
* the supported precision. If the operation succeeds and no intervening
* operations on the file take place, then the next invocation of the
* <code>{@link #lastModified}</code> method will return the (possibly
* truncated) <code>time</code> argument that was passed to this method.
* {@description.close}
*
* @param time The new last-modified time, measured in milliseconds since
* the epoch (00:00:00 GMT, January 1, 1970)
*
* @return <code>true</code> if and only if the operation succeeded;
* <code>false</code> otherwise
*
* @throws IllegalArgumentException If the argument is negative
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the named file
*
* @since 1.2
*/
public boolean setLastModified(long time) {
if (time < 0) throw new IllegalArgumentException("Negative time");
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(path);
}
return fs.setLastModifiedTime(this, time);
}
/** {@collect.stats}
* {@description.open}
* Marks the file or directory named by this abstract pathname so that
* only read operations are allowed. After invoking this method the file
* or directory is guaranteed not to change until it is either deleted or
* marked to allow write access. Whether or not a read-only file or
* directory may be deleted depends upon the underlying system.
* {@description.close}
*
* @return <code>true</code> if and only if the operation succeeded;
* <code>false</code> otherwise
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the named file
*
* @since 1.2
*/
public boolean setReadOnly() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(path);
}
return fs.setReadOnly(this);
}
/** {@collect.stats}
* {@description.open}
* Sets the owner's or everybody's write permission for this abstract
* pathname.
* {@description.close}
*
* @param writable
* If <code>true</code>, sets the access permission to allow write
* operations; if <code>false</code> to disallow write operations
*
* @param ownerOnly
* If <code>true</code>, the write permission applies only to the
* owner's write permission; otherwise, it applies to everybody. If
* the underlying file system can not distinguish the owner's write
* permission from that of others, then the permission will apply to
* everybody, regardless of this value.
*
* @return <code>true</code> if and only if the operation succeeded. The
* operation will fail if the user does not have permission to change
* the access permissions of this abstract pathname.
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the named file
*
* @since 1.6
*/
public boolean setWritable(boolean writable, boolean ownerOnly) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(path);
}
return fs.setPermission(this, FileSystem.ACCESS_WRITE, writable, ownerOnly);
}
/** {@collect.stats}
* {@description.open}
* A convenience method to set the owner's write permission for this abstract
* pathname.
*
* <p> An invocation of this method of the form <tt>file.setWritable(arg)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* file.setWritable(arg, true) </pre>
* {@description.close}
*
* @param writable
* If <code>true</code>, sets the access permission to allow write
* operations; if <code>false</code> to disallow write operations
*
* @return <code>true</code> if and only if the operation succeeded. The
* operation will fail if the user does not have permission to
* change the access permissions of this abstract pathname.
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the file
*
* @since 1.6
*/
public boolean setWritable(boolean writable) {
return setWritable(writable, true);
}
/** {@collect.stats}
* {@description.open}
* Sets the owner's or everybody's read permission for this abstract
* pathname.
* {@description.close}
*
* @param readable
* If <code>true</code>, sets the access permission to allow read
* operations; if <code>false</code> to disallow read operations
*
* @param ownerOnly
* If <code>true</code>, the read permission applies only to the
* owner's read permission; otherwise, it applies to everybody. If
* the underlying file system can not distinguish the owner's read
* permission from that of others, then the permission will apply to
* everybody, regardless of this value.
*
* @return <code>true</code> if and only if the operation succeeded. The
* operation will fail if the user does not have permission to
* change the access permissions of this abstract pathname. If
* <code>readable</code> is <code>false</code> and the underlying
* file system does not implement a read permission, then the
* operation will fail.
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the file
*
* @since 1.6
*/
public boolean setReadable(boolean readable, boolean ownerOnly) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(path);
}
return fs.setPermission(this, FileSystem.ACCESS_READ, readable, ownerOnly);
}
/** {@collect.stats}
* {@description.open}
* A convenience method to set the owner's read permission for this abstract
* pathname.
*
* <p>An invocation of this method of the form <tt>file.setReadable(arg)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* file.setReadable(arg, true) </pre>
* {@description.close}
*
* @param readable
* If <code>true</code>, sets the access permission to allow read
* operations; if <code>false</code> to disallow read operations
*
* @return <code>true</code> if and only if the operation succeeded. The
* operation will fail if the user does not have permission to
* change the access permissions of this abstract pathname. If
* <code>readable</code> is <code>false</code> and the underlying
* file system does not implement a read permission, then the
* operation will fail.
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the file
*
* @since 1.6
*/
public boolean setReadable(boolean readable) {
return setReadable(readable, true);
}
/** {@collect.stats}
* {@description.open}
* Sets the owner's or everybody's execute permission for this abstract
* pathname.
* {@description.close}
*
* @param executable
* If <code>true</code>, sets the access permission to allow execute
* operations; if <code>false</code> to disallow execute operations
*
* @param ownerOnly
* If <code>true</code>, the execute permission applies only to the
* owner's execute permission; otherwise, it applies to everybody.
* If the underlying file system can not distinguish the owner's
* execute permission from that of others, then the permission will
* apply to everybody, regardless of this value.
*
* @return <code>true</code> if and only if the operation succeeded. The
* operation will fail if the user does not have permission to
* change the access permissions of this abstract pathname. If
* <code>executable</code> is <code>false</code> and the underlying
* file system does not implement an execute permission, then the
* operation will fail.
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the file
*
* @since 1.6
*/
public boolean setExecutable(boolean executable, boolean ownerOnly) {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(path);
}
return fs.setPermission(this, FileSystem.ACCESS_EXECUTE, executable, ownerOnly);
}
/** {@collect.stats}
* {@description.open}
* A convenience method to set the owner's execute permission for this abstract
* pathname.
*
* <p>An invocation of this method of the form <tt>file.setExcutable(arg)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* file.setExecutable(arg, true) </pre>
* {@description.close}
*
* @param executable
* If <code>true</code>, sets the access permission to allow execute
* operations; if <code>false</code> to disallow execute operations
*
* @return <code>true</code> if and only if the operation succeeded. The
* operation will fail if the user does not have permission to
* change the access permissions of this abstract pathname. If
* <code>executable</code> is <code>false</code> and the underlying
* file system does not implement an excute permission, then the
* operation will fail.
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method denies write access to the file
*
* @since 1.6
*/
public boolean setExecutable(boolean executable) {
return setExecutable(executable, true);
}
/** {@collect.stats}
* {@description.open}
* Tests whether the application can execute the file denoted by this
* abstract pathname.
* {@description.close}
*
* @return <code>true</code> if and only if the abstract pathname exists
* <em>and</em> the application is allowed to execute the file
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkExec(java.lang.String)}</code>
* method denies execute access to the file
*
* @since 1.6
*/
public boolean canExecute() {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkExec(path);
}
return fs.checkAccess(this, FileSystem.ACCESS_EXECUTE);
}
/* -- Filesystem interface -- */
/** {@collect.stats}
* {@description.open}
* List the available filesystem roots.
*
* <p> A particular Java platform may support zero or more
* hierarchically-organized file systems. Each file system has a
* {@code root} directory from which all other files in that file system
* can be reached. Windows platforms, for example, have a root directory
* for each active drive; UNIX platforms have a single root directory,
* namely {@code "/"}. The set of available filesystem roots is affected
* by various system-level operations such as the insertion or ejection of
* removable media and the disconnecting or unmounting of physical or
* virtual disk drives.
*
* <p> This method returns an array of {@code File} objects that denote the
* root directories of the available filesystem roots. It is guaranteed
* that the canonical pathname of any file physically present on the local
* machine will begin with one of the roots returned by this method.
*
* <p> The canonical pathname of a file that resides on some other machine
* and is accessed via a remote-filesystem protocol such as SMB or NFS may
* or may not begin with one of the roots returned by this method. If the
* pathname of a remote file is syntactically indistinguishable from the
* pathname of a local file then it will begin with one of the roots
* returned by this method. Thus, for example, {@code File} objects
* denoting the root directories of the mapped network drives of a Windows
* platform will be returned by this method, while {@code File} objects
* containing UNC pathnames will not be returned by this method.
*
* <p> Unlike most methods in this class, this method does not throw
* security exceptions. If a security manager exists and its {@link
* SecurityManager#checkRead(String)} method denies read access to a
* particular root directory, then that directory will not appear in the
* result.
* {@description.close}
*
* @return An array of {@code File} objects denoting the available
* filesystem roots, or {@code null} if the set of roots could not
* be determined. The array will be empty if there are no
* filesystem roots.
*
* @since 1.2
*/
public static File[] listRoots() {
return fs.listRoots();
}
/* -- Disk usage -- */
/** {@collect.stats}
* {@description.open}
* Returns the size of the partition <a href="#partName">named</a> by this
* abstract pathname.
* {@description.close}
*
* @return The size, in bytes, of the partition or <tt>0L</tt> if this
* abstract pathname does not name a partition
*
* @throws SecurityException
* If a security manager has been installed and it denies
* {@link RuntimePermission}<tt>("getFileSystemAttributes")</tt>
* or its {@link SecurityManager#checkRead(String)} method denies
* read access to the file named by this abstract pathname
*
* @since 1.6
*/
public long getTotalSpace() {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission("getFileSystemAttributes"));
sm.checkRead(path);
}
return fs.getSpace(this, FileSystem.SPACE_TOTAL);
}
/** {@collect.stats}
* {@description.open}
* Returns the number of unallocated bytes in the partition <a
* href="#partName">named</a> by this abstract path name.
*
* <p> The returned number of unallocated bytes is a hint, but not
* a guarantee, that it is possible to use most or any of these
* bytes. The number of unallocated bytes is most likely to be
* accurate immediately after this call. It is likely to be made
* inaccurate by any external I/O operations including those made
* on the system outside of this virtual machine. This method
* makes no guarantee that write operations to this file system
* will succeed.
* {@description.close}
*
* @return The number of unallocated bytes on the partition <tt>0L</tt>
* if the abstract pathname does not name a partition. This
* value will be less than or equal to the total file system size
* returned by {@link #getTotalSpace}.
*
* @throws SecurityException
* If a security manager has been installed and it denies
* {@link RuntimePermission}<tt>("getFileSystemAttributes")</tt>
* or its {@link SecurityManager#checkRead(String)} method denies
* read access to the file named by this abstract pathname
*
* @since 1.6
*/
public long getFreeSpace() {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission("getFileSystemAttributes"));
sm.checkRead(path);
}
return fs.getSpace(this, FileSystem.SPACE_FREE);
}
/** {@collect.stats}
* {@description.open}
* Returns the number of bytes available to this virtual machine on the
* partition <a href="#partName">named</a> by this abstract pathname. When
* possible, this method checks for write permissions and other operating
* system restrictions and will therefore usually provide a more accurate
* estimate of how much new data can actually be written than {@link
* #getFreeSpace}.
*
* <p> The returned number of available bytes is a hint, but not a
* guarantee, that it is possible to use most or any of these bytes. The
* number of unallocated bytes is most likely to be accurate immediately
* after this call. It is likely to be made inaccurate by any external
* I/O operations including those made on the system outside of this
* virtual machine. This method makes no guarantee that write operations
* to this file system will succeed.
* {@description.close}
*
* @return The number of available bytes on the partition or <tt>0L</tt>
* if the abstract pathname does not name a partition. On
* systems where this information is not available, this method
* will be equivalent to a call to {@link #getFreeSpace}.
*
* @throws SecurityException
* If a security manager has been installed and it denies
* {@link RuntimePermission}<tt>("getFileSystemAttributes")</tt>
* or its {@link SecurityManager#checkRead(String)} method denies
* read access to the file named by this abstract pathname
*
* @since 1.6
*/
public long getUsableSpace() {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(new RuntimePermission("getFileSystemAttributes"));
sm.checkRead(path);
}
return fs.getSpace(this, FileSystem.SPACE_USABLE);
}
/* -- Temporary files -- */
// lazy initialization of SecureRandom and temporary file directory
private static class LazyInitialization {
static final SecureRandom random = new SecureRandom();
static final String temporaryDirectory = temporaryDirectory();
static String temporaryDirectory() {
return fs.normalize(
AccessController.doPrivileged(
new GetPropertyAction("java.io.tmpdir")));
}
}
private static File generateFile(String prefix, String suffix, File dir)
throws IOException
{
long n = LazyInitialization.random.nextLong();
if (n == Long.MIN_VALUE) {
n = 0; // corner case
} else {
n = Math.abs(n);
}
return new File(dir, prefix + Long.toString(n) + suffix);
}
private static boolean checkAndCreate(String filename, SecurityManager sm)
throws IOException
{
if (sm != null) {
try {
sm.checkWrite(filename);
} catch (AccessControlException x) {
/* Throwing the original AccessControlException could disclose
the location of the default temporary directory, so we
re-throw a more innocuous SecurityException */
throw new SecurityException("Unable to create temporary file");
}
}
return fs.createFileExclusively(filename);
}
/** {@collect.stats}
* {@description.open}
* <p> Creates a new empty file in the specified directory, using the
* given prefix and suffix strings to generate its name. If this method
* returns successfully then it is guaranteed that:
*
* <ol>
* <li> The file denoted by the returned abstract pathname did not exist
* before this method was invoked, and
* <li> Neither this method nor any of its variants will return the same
* abstract pathname again in the current invocation of the virtual
* machine.
* </ol>
*
* This method provides only part of a temporary-file facility.
* {@description.close}
* {@property.open runtime formal:java.io.File_DeleteTempFile}
* To arrange
* for a file created by this method to be deleted automatically, use the
* <code>{@link #deleteOnExit}</code> method.
* {@property.close}
*
* {@description.open}
* <p> The <code>prefix</code> argument must be at least three characters
* long. It is recommended that the prefix be a short, meaningful string
* such as <code>"hjb"</code> or <code>"mail"</code>. The
* <code>suffix</code> argument may be <code>null</code>, in which case the
* suffix <code>".tmp"</code> will be used.
*
* <p> To create the new file, the prefix and the suffix may first be
* adjusted to fit the limitations of the underlying platform. If the
* prefix is too long then it will be truncated, but its first three
* characters will always be preserved. If the suffix is too long then it
* too will be truncated, but if it begins with a period character
* (<code>'.'</code>) then the period and the first three characters
* following it will always be preserved. Once these adjustments have been
* made the name of the new file will be generated by concatenating the
* prefix, five or more internally-generated characters, and the suffix.
*
* <p> If the <code>directory</code> argument is <code>null</code> then the
* system-dependent default temporary-file directory will be used. The
* default temporary-file directory is specified by the system property
* <code>java.io.tmpdir</code>. On UNIX systems the default value of this
* property is typically <code>"/tmp"</code> or <code>"/var/tmp"</code>; on
* Microsoft Windows systems it is typically <code>"C:\\WINNT\\TEMP"</code>. A different
* value may be given to this system property when the Java virtual machine
* is invoked, but programmatic changes to this property are not guaranteed
* to have any effect upon the temporary directory used by this method.
* {@description.close}
*
* @param prefix The prefix string to be used in generating the file's
* name; must be at least three characters long
*
* @param suffix The suffix string to be used in generating the file's
* name; may be <code>null</code>, in which case the
* suffix <code>".tmp"</code> will be used
*
* @param directory The directory in which the file is to be created, or
* <code>null</code> if the default temporary-file
* directory is to be used
*
* @return An abstract pathname denoting a newly-created empty file
*
* @throws IllegalArgumentException
* If the <code>prefix</code> argument contains fewer than three
* characters
*
* @throws IOException If a file could not be created
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method does not allow a file to be created
*
* @since 1.2
*/
public static File createTempFile(String prefix, String suffix,
File directory)
throws IOException
{
if (prefix == null) throw new NullPointerException();
if (prefix.length() < 3)
throw new IllegalArgumentException("Prefix string too short");
String s = (suffix == null) ? ".tmp" : suffix;
if (directory == null) {
String tmpDir = LazyInitialization.temporaryDirectory();
directory = new File(tmpDir, fs.prefixLength(tmpDir));
}
SecurityManager sm = System.getSecurityManager();
File f;
do {
f = generateFile(prefix, s, directory);
} while (!checkAndCreate(f.getPath(), sm));
return f;
}
/** {@collect.stats}
* {@description.open}
* Creates an empty file in the default temporary-file directory, using
* the given prefix and suffix to generate its name. Invoking this method
* is equivalent to invoking <code>{@link #createTempFile(java.lang.String,
* java.lang.String, java.io.File)
* createTempFile(prefix, suffix, null)}</code>.
* {@description.close}
*
* @param prefix The prefix string to be used in generating the file's
* name; must be at least three characters long
*
* @param suffix The suffix string to be used in generating the file's
* name; may be <code>null</code>, in which case the
* suffix <code>".tmp"</code> will be used
*
* @return An abstract pathname denoting a newly-created empty file
*
* @throws IllegalArgumentException
* If the <code>prefix</code> argument contains fewer than three
* characters
*
* @throws IOException If a file could not be created
*
* @throws SecurityException
* If a security manager exists and its <code>{@link
* java.lang.SecurityManager#checkWrite(java.lang.String)}</code>
* method does not allow a file to be created
*
* @since 1.2
*/
public static File createTempFile(String prefix, String suffix)
throws IOException
{
return createTempFile(prefix, suffix, null);
}
/* -- Basic infrastructure -- */
/** {@collect.stats}
* {@description.open}
* Compares two abstract pathnames lexicographically. The ordering
* defined by this method depends upon the underlying system. On UNIX
* systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows
* systems it is not.
* {@description.close}
*
* @param pathname The abstract pathname to be compared to this abstract
* pathname
*
* @return Zero if the argument is equal to this abstract pathname, a
* value less than zero if this abstract pathname is
* lexicographically less than the argument, or a value greater
* than zero if this abstract pathname is lexicographically
* greater than the argument
*
* @since 1.2
*/
public int compareTo(File pathname) {
return fs.compare(this, pathname);
}
/** {@collect.stats}
* {@description.open}
* Tests this abstract pathname for equality with the given object.
* Returns <code>true</code> if and only if the argument is not
* <code>null</code> and is an abstract pathname that denotes the same file
* or directory as this abstract pathname. Whether or not two abstract
* pathnames are equal depends upon the underlying system. On UNIX
* systems, alphabetic case is significant in comparing pathnames; on Microsoft Windows
* systems it is not.
* {@description.close}
*
* @param obj The object to be compared with this abstract pathname
*
* @return <code>true</code> if and only if the objects are the same;
* <code>false</code> otherwise
*/
public boolean equals(Object obj) {
if ((obj != null) && (obj instanceof File)) {
return compareTo((File)obj) == 0;
}
return false;
}
/** {@collect.stats}
* {@description.open}
* Computes a hash code for this abstract pathname. Because equality of
* abstract pathnames is inherently system-dependent, so is the computation
* of their hash codes. On UNIX systems, the hash code of an abstract
* pathname is equal to the exclusive <em>or</em> of the hash code
* of its pathname string and the decimal value
* <code>1234321</code>. On Microsoft Windows systems, the hash
* code is equal to the exclusive <em>or</em> of the hash code of
* its pathname string converted to lower case and the decimal
* value <code>1234321</code>. Locale is not taken into account on
* lowercasing the pathname string.
* {@description.close}
*
* @return A hash code for this abstract pathname
*/
public int hashCode() {
return fs.hashCode(this);
}
/** {@collect.stats}
* {@description.open}
* Returns the pathname string of this abstract pathname. This is just the
* string returned by the <code>{@link #getPath}</code> method.
* {@description.close}
*
* @return The string form of this abstract pathname
*/
public String toString() {
return getPath();
}
/** {@collect.stats}
* {@description.open}
* WriteObject is called to save this filename.
* The separator character is saved also so it can be replaced
* in case the path is reconstituted on a different host type.
* <p>
* {@description.close}
* @serialData Default fields followed by separator character.
*/
private synchronized void writeObject(java.io.ObjectOutputStream s)
throws IOException
{
s.defaultWriteObject();
s.writeChar(this.separatorChar); // Add the separator character
}
/** {@collect.stats}
* {@description.open}
* readObject is called to restore this filename.
* The original separator character is read. If it is different
* than the separator character on this system, then the old separator
* is replaced by the local separator.
* {@description.close}
*/
private synchronized void readObject(java.io.ObjectInputStream s)
throws IOException, ClassNotFoundException
{
ObjectInputStream.GetField fields = s.readFields();
String pathField = (String)fields.get("path", null);
char sep = s.readChar(); // read the previous separator char
if (sep != separatorChar)
pathField = pathField.replace(sep, separatorChar);
this.path = fs.normalize(pathField);
this.prefixLength = fs.prefixLength(this.path);
}
/** {@collect.stats}
* {@description.open}
* use serialVersionUID from JDK 1.0.2 for interoperability
* {@description.close}
*/
private static final long serialVersionUID = 301077366599181567L;
// Set up JavaIODeleteOnExitAccess in SharedSecrets
// Added here as DeleteOnExitHook is package-private and SharedSecrets cannot easily access it.
static {
sun.misc.SharedSecrets.setJavaIODeleteOnExitAccess(
new sun.misc.JavaIODeleteOnExitAccess() {
public void run() {
DeleteOnExitHook.hook().run();
}
}
);
}
}
|
Java
|
/*
* Copyright (c) 1995, 2000, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Signals that an I/O operation has been interrupted. An
* <code>InterruptedIOException</code> is thrown to indicate that an
* input or output transfer has been terminated because the thread
* performing it was interrupted. The field {@link #bytesTransferred}
* indicates how many bytes were successfully transferred before
* the interruption occurred.
* {@description.close}
*
* @author unascribed
* @see java.io.InputStream
* @see java.io.OutputStream
* @see java.lang.Thread#interrupt()
* @since JDK1.0
*/
public
class InterruptedIOException extends IOException {
/** {@collect.stats}
* {@description.open}
* Constructs an <code>InterruptedIOException</code> with
* <code>null</code> as its error detail message.
* {@description.close}
*/
public InterruptedIOException() {
super();
}
/** {@collect.stats}
* {@description.open}
* Constructs an <code>InterruptedIOException</code> with the
* specified detail message. The string <code>s</code> can be
* retrieved later by the
* <code>{@link java.lang.Throwable#getMessage}</code>
* method of class <code>java.lang.Throwable</code>.
* {@description.close}
*
* @param s the detail message.
*/
public InterruptedIOException(String s) {
super(s);
}
/** {@collect.stats}
* {@description.open}
* Reports how many bytes had been transferred as part of the I/O
* operation before it was interrupted.
* {@description.close}
*
* @serial
*/
public int bytesTransferred = 0;
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
*
* {@description.open}
* Abstract class for writing to character streams. The only methods that a
* subclass must implement are write(char[], int, int), flush(), and close().
* Most subclasses, however, will override some of the methods defined here in
* order to provide higher efficiency, additional functionality, or both.
* {@description.close}
*
* @see Writer
* @see BufferedWriter
* @see CharArrayWriter
* @see FilterWriter
* @see OutputStreamWriter
* @see FileWriter
* @see PipedWriter
* @see PrintWriter
* @see StringWriter
* @see Reader
*
* @author Mark Reinhold
* @since JDK1.1
*/
public abstract class Writer implements Appendable, Closeable, Flushable {
/** {@collect.stats}
* {@description.open}
* Temporary buffer used to hold writes of strings and single characters
* {@description.close}
*/
private char[] writeBuffer;
/** {@collect.stats}
* {@description.open}
* Size of writeBuffer, must be >= 1
* {@description.close}
*/
private final int writeBufferSize = 1024;
/** {@collect.stats}
* {@description.open}
* The object used to synchronize operations on this stream. For
* efficiency, a character-stream object may use an object other than
* itself to protect critical sections. A subclass should therefore use
* the object in this field rather than <tt>this</tt> or a synchronized
* method.
* {@description.close}
*/
protected Object lock;
/** {@collect.stats}
* {@description.open}
* Creates a new character-stream writer whose critical sections will
* synchronize on the writer itself.
* {@description.close}
*/
protected Writer() {
this.lock = this;
}
/** {@collect.stats}
* {@description.open}
* Creates a new character-stream writer whose critical sections will
* synchronize on the given object.
* {@description.close}
*
* @param lock
* Object to synchronize on
*/
protected Writer(Object lock) {
if (lock == null) {
throw new NullPointerException();
}
this.lock = lock;
}
/** {@collect.stats}
* {@description.open}
* Writes a single character. The character to be written is contained in
* the 16 low-order bits of the given integer value; the 16 high-order bits
* are ignored.
*
* <p> Subclasses that intend to support efficient single-character output
* should override this method.
* {@description.close}
*
* @param c
* int specifying a character to be written
*
* @throws IOException
* If an I/O error occurs
*/
public void write(int c) throws IOException {
synchronized (lock) {
if (writeBuffer == null){
writeBuffer = new char[writeBufferSize];
}
writeBuffer[0] = (char) c;
write(writeBuffer, 0, 1);
}
}
/** {@collect.stats}
* {@description.open}
* Writes an array of characters.
* {@description.close}
*
* @param cbuf
* Array of characters to be written
*
* @throws IOException
* If an I/O error occurs
*/
public void write(char cbuf[]) throws IOException {
write(cbuf, 0, cbuf.length);
}
/** {@collect.stats}
* {@description.open}
* Writes a portion of an array of characters.
* {@description.close}
*
* @param cbuf
* Array of characters
*
* @param off
* Offset from which to start writing characters
*
* @param len
* Number of characters to write
*
* @throws IOException
* If an I/O error occurs
*/
abstract public void write(char cbuf[], int off, int len) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes a string.
* {@description.close}
*
* @param str
* String to be written
*
* @throws IOException
* If an I/O error occurs
*/
public void write(String str) throws IOException {
write(str, 0, str.length());
}
/** {@collect.stats}
* {@description.open}
* Writes a portion of a string.
* {@description.close}
*
* @param str
* A String
*
* @param off
* Offset from which to start writing characters
*
* @param len
* Number of characters to write
*
* @throws IndexOutOfBoundsException
* If <tt>off</tt> is negative, or <tt>len</tt> is negative,
* or <tt>off+len</tt> is negative or greater than the length
* of the given string
*
* @throws IOException
* If an I/O error occurs
*/
public void write(String str, int off, int len) throws IOException {
synchronized (lock) {
char cbuf[];
if (len <= writeBufferSize) {
if (writeBuffer == null) {
writeBuffer = new char[writeBufferSize];
}
cbuf = writeBuffer;
} else { // Don't permanently allocate very large buffers.
cbuf = new char[len];
}
str.getChars(off, (off + len), cbuf, 0);
write(cbuf, 0, len);
}
}
/** {@collect.stats}
* {@description.open}
* Appends the specified character sequence to this writer.
*
* <p> An invocation of this method of the form <tt>out.append(csq)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* out.write(csq.toString()) </pre>
*
* <p> Depending on the specification of <tt>toString</tt> for the
* character sequence <tt>csq</tt>, the entire sequence may not be
* appended. For instance, invoking the <tt>toString</tt> method of a
* character buffer will return a subsequence whose content depends upon
* the buffer's position and limit.
* {@description.close}
*
* @param csq
* The character sequence to append. If <tt>csq</tt> is
* <tt>null</tt>, then the four characters <tt>"null"</tt> are
* appended to this writer.
*
* @return This writer
*
* @throws IOException
* If an I/O error occurs
*
* @since 1.5
*/
public Writer append(CharSequence csq) throws IOException {
if (csq == null)
write("null");
else
write(csq.toString());
return this;
}
/** {@collect.stats}
* {@description.open}
* Appends a subsequence of the specified character sequence to this writer.
* <tt>Appendable</tt>.
*
* <p> An invocation of this method of the form <tt>out.append(csq, start,
* end)</tt> when <tt>csq</tt> is not <tt>null</tt> behaves in exactly the
* same way as the invocation
*
* <pre>
* out.write(csq.subSequence(start, end).toString()) </pre>
* {@description.close}
*
* @param csq
* The character sequence from which a subsequence will be
* appended. If <tt>csq</tt> is <tt>null</tt>, then characters
* will be appended as if <tt>csq</tt> contained the four
* characters <tt>"null"</tt>.
*
* @param start
* The index of the first character in the subsequence
*
* @param end
* The index of the character following the last character in the
* subsequence
*
* @return This writer
*
* @throws IndexOutOfBoundsException
* If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
* is greater than <tt>end</tt>, or <tt>end</tt> is greater than
* <tt>csq.length()</tt>
*
* @throws IOException
* If an I/O error occurs
*
* @since 1.5
*/
public Writer append(CharSequence csq, int start, int end) throws IOException {
CharSequence cs = (csq == null ? "null" : csq);
write(cs.subSequence(start, end).toString());
return this;
}
/** {@collect.stats}
* {@description.open}
* Appends the specified character to this writer.
*
* <p> An invocation of this method of the form <tt>out.append(c)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* out.write(c) </pre>
* {@description.close}
*
* @param c
* The 16-bit character to append
*
* @return This writer
*
* @throws IOException
* If an I/O error occurs
*
* @since 1.5
*/
public Writer append(char c) throws IOException {
write(c);
return this;
}
/** {@collect.stats}
* {@description.open}
* Flushes the stream. If the stream has saved any characters from the
* various write() methods in a buffer, write them immediately to their
* intended destination. Then, if that destination is another character or
* byte stream, flush it. Thus one flush() invocation will flush all the
* buffers in a chain of Writers and OutputStreams.
*
* <p> If the intended destination of this stream is an abstraction provided
* by the underlying operating system, for example a file, then flushing the
* stream guarantees only that bytes previously written to the stream are
* passed to the operating system for writing; it does not guarantee that
* they are actually written to a physical device such as a disk drive.
* {@description.close}
*
* @throws IOException
* If an I/O error occurs
*/
abstract public void flush() throws IOException;
/** {@collect.stats}
* {@description.open}
* Closes the stream, flushing it first.
* {@description.close}
* {@property.open runtime formal:java.io.Writer_ManipulateAfterClose}
* Once the stream has been closed,
* further write() or flush() invocations will cause an IOException to be
* thrown.
* {@property.close}
* {@property.open runtime formal:java.io.Closeable_MultipleClose}
* Closing a previously closed stream has no effect.
* {@property.close}
*
* @throws IOException
* If an I/O error occurs
*/
abstract public void close() throws IOException;
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Thrown when control information that was read from an object stream
* violates internal consistency checks.
* {@description.close}
*
* @author unascribed
* @since JDK1.1
*/
public class StreamCorruptedException extends ObjectStreamException {
private static final long serialVersionUID = 8983558202217591746L;
/** {@collect.stats}
* {@description.open}
* Create a StreamCorruptedException and list a reason why thrown.
* {@description.close}
*
* @param reason String describing the reason for the exception.
*/
public StreamCorruptedException(String reason) {
super(reason);
}
/** {@collect.stats}
* {@description.open}
* Create a StreamCorruptedException and list no reason why thrown.
* {@description.close}
*/
public StreamCorruptedException() {
super();
}
}
|
Java
|
/*
* Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* The <code>DataInput</code> interface provides
* for reading bytes from a binary stream and
* reconstructing from them data in any of
* the Java primitive types. There is also
* a
* facility for reconstructing a <code>String</code>
* from data in
* <a href="#modified-utf-8">modified UTF-8</a>
* format.
* <p>
* It is generally true of all the reading
* routines in this interface that if end of
* file is reached before the desired number
* of bytes has been read, an <code>EOFException</code>
* (which is a kind of <code>IOException</code>)
* is thrown. If any byte cannot be read for
* any reason other than end of file, an <code>IOException</code>
* other than <code>EOFException</code> is
* thrown. In particular, an <code>IOException</code>
* may be thrown if the input stream has been
* closed.
* {@description.close}
*
* {@property.open}
* <h4><a name="modified-utf-8">Modified UTF-8</a></h4>
* <p>
* Implementations of the DataInput and DataOutput interfaces represent
* Unicode strings in a format that is a slight modification of UTF-8.
* (For information regarding the standard UTF-8 format, see section
* <i>3.9 Unicode Encoding Forms</i> of <i>The Unicode Standard, Version
* 4.0</i>).
* Note that in the following tables, the most significant bit appears in the
* far left-hand column.
* <p>
* All characters in the range <code>'\u0001'</code> to
* <code>'\u007F'</code> are represented by a single byte:
*
* <blockquote>
* <table border="1" cellspacing="0" cellpadding="8" width="50%"
* summary="Bit values and bytes">
* <tr>
* <td></td>
* <th id="bit">Bit Values</th>
* </tr>
* <tr>
* <th id="byte1">Byte 1</th>
* <td>
* <table border="1" cellspacing="0" width="100%">
* <tr>
* <td width="12%"><center>0</center>
* <td colspan="7"><center>bits 6-0</center>
* </tr>
* </table>
* </td>
* </tr>
* </table>
* </blockquote>
*
* <p>
* The null character <code>'\u0000'</code> and characters in the
* range <code>'\u0080'</code> to <code>'\u07FF'</code> are
* represented by a pair of bytes:
*
* <blockquote>
* <table border="1" cellspacing="0" cellpadding="8" width="50%"
* summary="Bit values and bytes">
* <tr>
* <td></td>
* <th id="bit">Bit Values</th>
* </tr>
* <tr>
* <th id="byte1">Byte 1</th>
* <td>
* <table border="1" cellspacing="0" width="100%">
* <tr>
* <td width="12%"><center>1</center>
* <td width="13%"><center>1</center>
* <td width="12%"><center>0</center>
* <td colspan="5"><center>bits 10-6</center>
* </tr>
* </table>
* </td>
* </tr>
* <tr>
* <th id="byte2">Byte 2</th>
* <td>
* <table border="1" cellspacing="0" width="100%">
* <tr>
* <td width="12%"><center>1</center>
* <td width="13%"><center>0</center>
* <td colspan="6"><center>bits 5-0</center>
* </tr>
* </table>
* </td>
* </tr>
* </table>
* </blockquote>
*
* <br>
* <code>char</code> values in the range <code>'\u0800'</code> to
* <code>'\uFFFF'</code> are represented by three bytes:
*
* <blockquote>
* <table border="1" cellspacing="0" cellpadding="8" width="50%"
* summary="Bit values and bytes">
* <tr>
* <td></td>
* <th id="bit">Bit Values</th>
* </tr>
* <tr>
* <th id="byte1">Byte 1</th>
* <td>
* <table border="1" cellspacing="0" width="100%">
* <tr>
* <td width="12%"><center>1</center>
* <td width="13%"><center>1</center>
* <td width="12%"><center>1</center>
* <td width="13%"><center>0</center>
* <td colspan="4"><center>bits 15-12</center>
* </tr>
* </table>
* </td>
* </tr>
* <tr>
* <th id="byte2">Byte 2</th>
* <td>
* <table border="1" cellspacing="0" width="100%">
* <tr>
* <td width="12%"><center>1</center>
* <td width="13%"><center>0</center>
* <td colspan="6"><center>bits 11-6</center>
* </tr>
* </table>
* </td>
* </tr>
* <tr>
* <th id="byte3">Byte 3</th>
* <td>
* <table border="1" cellspacing="0" width="100%">
* <tr>
* <td width="12%"><center>1</center>
* <td width="13%"><center>0</center>
* <td colspan="6"><center>bits 5-0</center>
* </tr>
* </table>
* </td>
* </tr>
* </table>
* </blockquote>
*
* <p>
* The differences between this format and the
* standard UTF-8 format are the following:
* <ul>
* <li>The null byte <code>'\u0000'</code> is encoded in 2-byte format
* rather than 1-byte, so that the encoded strings never have
* embedded nulls.
* <li>Only the 1-byte, 2-byte, and 3-byte formats are used.
* <li><a href="../lang/Character.html#unicode">Supplementary characters</a>
* are represented in the form of surrogate pairs.
* </ul>
* {@property.close}
* @author Frank Yellin
* @see java.io.DataInputStream
* @see java.io.DataOutput
* @since JDK1.0
*/
public
interface DataInput {
/** {@collect.stats}
* {@description.open}
* Reads some bytes from an input
* stream and stores them into the buffer
* array <code>b</code>. The number of bytes
* read is equal
* to the length of <code>b</code>.
* {@description.close}
* {@description.open blocking}
* <p>
* This method blocks until one of the
* following conditions occurs:<p>
* <ul>
* <li><code>b.length</code>
* bytes of input data are available, in which
* case a normal return is made.
*
* <li>End of
* file is detected, in which case an <code>EOFException</code>
* is thrown.
*
* <li>An I/O error occurs, in
* which case an <code>IOException</code> other
* than <code>EOFException</code> is thrown.
* </ul>
* {@description.close}
* {@property.open}
* <p>
* If <code>b</code> is <code>null</code>,
* a <code>NullPointerException</code> is thrown.
* If <code>b.length</code> is zero, then
* no bytes are read. Otherwise, the first
* byte read is stored into element <code>b[0]</code>,
* the next one into <code>b[1]</code>, and
* so on.
* {@property.close}
* {@description.open}
* If an exception is thrown from
* this method, then it may be that some but
* not all bytes of <code>b</code> have been
* updated with data from the input stream.
* {@description.close}
*
* @param b the buffer into which the data is read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
void readFully(byte b[]) throws IOException;
/** {@collect.stats}
*
* {@description.open}
* Reads <code>len</code>
* bytes from
* an input stream.
* {@description.close}
* {@description.open blocking}
* <p>
* This method
* blocks until one of the following conditions
* occurs:<p>
* <ul>
* <li><code>len</code> bytes
* of input data are available, in which case
* a normal return is made.
*
* <li>End of file
* is detected, in which case an <code>EOFException</code>
* is thrown.
*
* <li>An I/O error occurs, in
* which case an <code>IOException</code> other
* than <code>EOFException</code> is thrown.
* </ul>
* {@description.close}
* {@property.open}
* <p>
* If <code>b</code> is <code>null</code>,
* a <code>NullPointerException</code> is thrown.
* If <code>off</code> is negative, or <code>len</code>
* is negative, or <code>off+len</code> is
* greater than the length of the array <code>b</code>,
* then an <code>IndexOutOfBoundsException</code>
* is thrown.
* {@property.close}
* {@description.open}
* If <code>len</code> is zero,
* then no bytes are read. Otherwise, the first
* byte read is stored into element <code>b[off]</code>,
* the next one into <code>b[off+1]</code>,
* and so on. The number of bytes read is,
* at most, equal to <code>len</code>.
* {@description.close}
*
* @param b the buffer into which the data is read.
* @param off an int specifying the offset into the data.
* @param len an int specifying the number of bytes to read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
void readFully(byte b[], int off, int len) throws IOException;
/** {@collect.stats}
* {@description.open}
* Makes an attempt to skip over
* <code>n</code> bytes
* of data from the input
* stream, discarding the skipped bytes.
* However,
* it may skip
* over some smaller number of
* bytes, possibly zero. This may result from
* any of a
* number of conditions; reaching
* end of file before <code>n</code> bytes
* have been skipped is
* only one possibility.
* This method never throws an <code>EOFException</code>.
* The actual
* number of bytes skipped is returned.
* {@description.close}
*
* @param n the number of bytes to be skipped.
* @return the number of bytes actually skipped.
* @exception IOException if an I/O error occurs.
*/
int skipBytes(int n) throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads one input byte and returns
* <code>true</code> if that byte is nonzero,
* <code>false</code> if that byte is zero.
* This method is suitable for reading
* the byte written by the <code>writeBoolean</code>
* method of interface <code>DataOutput</code>.
* {@description.close}
*
* @return the <code>boolean</code> value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
boolean readBoolean() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads and returns one input byte.
* The byte is treated as a signed value in
* the range <code>-128</code> through <code>127</code>,
* inclusive.
* This method is suitable for
* reading the byte written by the <code>writeByte</code>
* method of interface <code>DataOutput</code>.
* {@description.close}
*
* @return the 8-bit value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
byte readByte() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads one input byte, zero-extends
* it to type <code>int</code>, and returns
* the result, which is therefore in the range
* <code>0</code>
* through <code>255</code>.
* This method is suitable for reading
* the byte written by the <code>writeByte</code>
* method of interface <code>DataOutput</code>
* if the argument to <code>writeByte</code>
* was intended to be a value in the range
* <code>0</code> through <code>255</code>.
* {@description.close}
*
* @return the unsigned 8-bit value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
int readUnsignedByte() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads two input bytes and returns
* a <code>short</code> value. Let <code>a</code>
* be the first byte read and <code>b</code>
* be the second byte. The value
* returned
* is:
* <p><pre><code>(short)((a << 8) | (b & 0xff))
* </code></pre>
* This method
* is suitable for reading the bytes written
* by the <code>writeShort</code> method of
* interface <code>DataOutput</code>.
* {@description.close}
*
* @return the 16-bit value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
short readShort() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads two input bytes and returns
* an <code>int</code> value in the range <code>0</code>
* through <code>65535</code>. Let <code>a</code>
* be the first byte read and
* <code>b</code>
* be the second byte. The value returned is:
* <p><pre><code>(((a & 0xff) << 8) | (b & 0xff))
* </code></pre>
* This method is suitable for reading the bytes
* written by the <code>writeShort</code> method
* of interface <code>DataOutput</code> if
* the argument to <code>writeShort</code>
* was intended to be a value in the range
* <code>0</code> through <code>65535</code>.
* {@description.close}
*
* @return the unsigned 16-bit value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
int readUnsignedShort() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads two input bytes and returns a <code>char</code> value.
* Let <code>a</code>
* be the first byte read and <code>b</code>
* be the second byte. The value
* returned is:
* <p><pre><code>(char)((a << 8) | (b & 0xff))
* </code></pre>
* This method
* is suitable for reading bytes written by
* the <code>writeChar</code> method of interface
* <code>DataOutput</code>.
* {@description.close}
*
* @return the <code>char</code> value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
char readChar() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads four input bytes and returns an
* <code>int</code> value. Let <code>a-d</code>
* be the first through fourth bytes read. The value returned is:
* <p><pre>
* <code>
* (((a & 0xff) << 24) | ((b & 0xff) << 16) |
*  ((c & 0xff) << 8) | (d & 0xff))
* </code></pre>
* This method is suitable
* for reading bytes written by the <code>writeInt</code>
* method of interface <code>DataOutput</code>.
* {@description.close}
*
* @return the <code>int</code> value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
int readInt() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads eight input bytes and returns
* a <code>long</code> value. Let <code>a-h</code>
* be the first through eighth bytes read.
* The value returned is:
* <p><pre> <code>
* (((long)(a & 0xff) << 56) |
* ((long)(b & 0xff) << 48) |
* ((long)(c & 0xff) << 40) |
* ((long)(d & 0xff) << 32) |
* ((long)(e & 0xff) << 24) |
* ((long)(f & 0xff) << 16) |
* ((long)(g & 0xff) << 8) |
* ((long)(h & 0xff)))
* </code></pre>
* <p>
* This method is suitable
* for reading bytes written by the <code>writeLong</code>
* method of interface <code>DataOutput</code>.
* {@description.close}
*
* @return the <code>long</code> value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
long readLong() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads four input bytes and returns
* a <code>float</code> value. It does this
* by first constructing an <code>int</code>
* value in exactly the manner
* of the <code>readInt</code>
* method, then converting this <code>int</code>
* value to a <code>float</code> in
* exactly the manner of the method <code>Float.intBitsToFloat</code>.
* This method is suitable for reading
* bytes written by the <code>writeFloat</code>
* method of interface <code>DataOutput</code>.
* {@description.close}
*
* @return the <code>float</code> value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
float readFloat() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads eight input bytes and returns
* a <code>double</code> value. It does this
* by first constructing a <code>long</code>
* value in exactly the manner
* of the <code>readlong</code>
* method, then converting this <code>long</code>
* value to a <code>double</code> in exactly
* the manner of the method <code>Double.longBitsToDouble</code>.
* This method is suitable for reading
* bytes written by the <code>writeDouble</code>
* method of interface <code>DataOutput</code>.
* {@description.close}
*
* @return the <code>double</code> value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
double readDouble() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads the next line of text from the input stream.
* It reads successive bytes, converting
* each byte separately into a character,
* until it encounters a line terminator or
* end of
* file; the characters read are then
* returned as a <code>String</code>.
* {@description.close}
* {@property.open}
* Note
* that because this
* method processes bytes,
* it does not support input of the full Unicode
* character set.
* {@property.close}
* {@property.open}
* <p>
* If end of file is encountered
* before even one byte can be read, then <code>null</code>
* is returned. Otherwise, each byte that is
* read is converted to type <code>char</code>
* by zero-extension. If the character <code>'\n'</code>
* is encountered, it is discarded and reading
* ceases. If the character <code>'\r'</code>
* is encountered, it is discarded and, if
* the following byte converts  to the
* character <code>'\n'</code>, then that is
* discarded also; reading then ceases. If
* end of file is encountered before either
* of the characters <code>'\n'</code> and
* <code>'\r'</code> is encountered, reading
* ceases. Once reading has ceased, a <code>String</code>
* is returned that contains all the characters
* read and not discarded, taken in order.
* {@property.close}
* {@description.open}
* Note that every character in this string
* will have a value less than <code>\u0100</code>,
* that is, <code>(char)256</code>.
* {@description.close}
*
* @return the next line of text from the input stream,
* or <CODE>null</CODE> if the end of file is
* encountered before a byte can be read.
* @exception IOException if an I/O error occurs.
*/
String readLine() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads in a string that has been encoded using a
* <a href="#modified-utf-8">modified UTF-8</a>
* format.
* The general contract of <code>readUTF</code>
* is that it reads a representation of a Unicode
* character string encoded in modified
* UTF-8 format; this string of characters
* is then returned as a <code>String</code>.
* <p>
* First, two bytes are read and used to
* construct an unsigned 16-bit integer in
* exactly the manner of the <code>readUnsignedShort</code>
* method . This integer value is called the
* <i>UTF length</i> and specifies the number
* of additional bytes to be read. These bytes
* are then converted to characters by considering
* them in groups. The length of each group
* is computed from the value of the first
* byte of the group. The byte following a
* group, if any, is the first byte of the
* next group.
* <p>
* If the first byte of a group
* matches the bit pattern <code>0xxxxxxx</code>
* (where <code>x</code> means "may be <code>0</code>
* or <code>1</code>"), then the group consists
* of just that byte. The byte is zero-extended
* to form a character.
* <p>
* If the first byte
* of a group matches the bit pattern <code>110xxxxx</code>,
* then the group consists of that byte <code>a</code>
* and a second byte <code>b</code>. If there
* is no byte <code>b</code> (because byte
* <code>a</code> was the last of the bytes
* to be read), or if byte <code>b</code> does
* not match the bit pattern <code>10xxxxxx</code>,
* then a <code>UTFDataFormatException</code>
* is thrown. Otherwise, the group is converted
* to the character:<p>
* <pre><code>(char)(((a& 0x1F) << 6) | (b & 0x3F))
* </code></pre>
* If the first byte of a group
* matches the bit pattern <code>1110xxxx</code>,
* then the group consists of that byte <code>a</code>
* and two more bytes <code>b</code> and <code>c</code>.
* If there is no byte <code>c</code> (because
* byte <code>a</code> was one of the last
* two of the bytes to be read), or either
* byte <code>b</code> or byte <code>c</code>
* does not match the bit pattern <code>10xxxxxx</code>,
* then a <code>UTFDataFormatException</code>
* is thrown. Otherwise, the group is converted
* to the character:<p>
* <pre><code>
* (char)(((a & 0x0F) << 12) | ((b & 0x3F) << 6) | (c & 0x3F))
* </code></pre>
* If the first byte of a group matches the
* pattern <code>1111xxxx</code> or the pattern
* <code>10xxxxxx</code>, then a <code>UTFDataFormatException</code>
* is thrown.
* <p>
* If end of file is encountered
* at any time during this entire process,
* then an <code>EOFException</code> is thrown.
* <p>
* After every group has been converted to
* a character by this process, the characters
* are gathered, in the same order in which
* their corresponding groups were read from
* the input stream, to form a <code>String</code>,
* which is returned.
* <p>
* The <code>writeUTF</code>
* method of interface <code>DataOutput</code>
* may be used to write data that is suitable
* for reading by this method.
* {@description.close}
*
* @return a Unicode string.
* @exception EOFException if this stream reaches the end
* before reading all the bytes.
* @exception IOException if an I/O error occurs.
* @exception UTFDataFormatException if the bytes do not represent a
* valid modified UTF-8 encoding of a string.
*/
String readUTF() throws IOException;
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.util.Formatter;
import java.util.Locale;
/** {@collect.stats}
* {@description.open}
* Prints formatted representations of objects to a text-output stream. This
* class implements all of the <tt>print</tt> methods found in {@link
* PrintStream}. It does not contain methods for writing raw bytes, for which
* a program should use unencoded byte streams.
*
* <p> Unlike the {@link PrintStream} class, if automatic flushing is enabled
* it will be done only when one of the <tt>println</tt>, <tt>printf</tt>, or
* <tt>format</tt> methods is invoked, rather than whenever a newline character
* happens to be output. These methods use the platform's own notion of line
* separator rather than the newline character.
*
* <p> Methods in this class never throw I/O exceptions, although some of its
* constructors may. The client may inquire as to whether any errors have
* occurred by invoking {@link #checkError checkError()}.
* {@description.close}
*
* @author Frank Yellin
* @author Mark Reinhold
* @since JDK1.1
*/
public class PrintWriter extends Writer {
/** {@collect.stats}
* {@description.open}
* The underlying character-output stream of this
* <code>PrintWriter</code>.
* {@description.close}
*
* @since 1.2
*/
protected Writer out;
private boolean autoFlush = false;
private boolean trouble = false;
private Formatter formatter;
private PrintStream psOut = null;
/** {@collect.stats}
* {@description.open}
* Line separator string. This is the value of the line.separator
* property at the moment that the stream was created.
* {@description.close}
*/
private String lineSeparator;
/** {@collect.stats}
* {@description.open}
* Creates a new PrintWriter, without automatic line flushing.
* {@description.close}
*
* @param out A character-output stream
*/
public PrintWriter (Writer out) {
this(out, false);
}
/** {@collect.stats}
* {@description.open}
* Creates a new PrintWriter.
* {@description.close}
*
* @param out A character-output stream
* @param autoFlush A boolean; if true, the <tt>println</tt>,
* <tt>printf</tt>, or <tt>format</tt> methods will
* flush the output buffer
*/
public PrintWriter(Writer out,
boolean autoFlush) {
super(out);
this.out = out;
this.autoFlush = autoFlush;
lineSeparator = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("line.separator"));
}
/** {@collect.stats}
* {@description.open}
* Creates a new PrintWriter, without automatic line flushing, from an
* existing OutputStream. This convenience constructor creates the
* necessary intermediate OutputStreamWriter, which will convert characters
* into bytes using the default character encoding.
* {@description.close}
*
* @param out An output stream
*
* @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
*/
public PrintWriter(OutputStream out) {
this(out, false);
}
/** {@collect.stats}
* {@description.open}
* Creates a new PrintWriter from an existing OutputStream. This
* convenience constructor creates the necessary intermediate
* OutputStreamWriter, which will convert characters into bytes using the
* default character encoding.
* {@description.close}
*
* @param out An output stream
* @param autoFlush A boolean; if true, the <tt>println</tt>,
* <tt>printf</tt>, or <tt>format</tt> methods will
* flush the output buffer
*
* @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
*/
public PrintWriter(OutputStream out, boolean autoFlush) {
this(new BufferedWriter(new OutputStreamWriter(out)), autoFlush);
// save print stream for error propagation
if (out instanceof java.io.PrintStream) {
psOut = (PrintStream) out;
}
}
/** {@collect.stats}
* {@description.open}
* Creates a new PrintWriter, without automatic line flushing, with the
* specified file name. This convenience constructor creates the necessary
* intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
* which will encode characters using the {@linkplain
* java.nio.charset.Charset#defaultCharset() default charset} for this
* instance of the Java virtual machine.
* {@description.close}
*
* @param fileName
* The name of the file to use as the destination of this writer.
* If the file exists then it will be truncated to zero size;
* otherwise, a new file will be created. The output will be
* written to the file and is buffered.
*
* @throws FileNotFoundException
* If the given string does not denote an existing, writable
* regular file and a new regular file of that name cannot be
* created, or if some other error occurs while opening or
* creating the file
*
* @throws SecurityException
* If a security manager is present and {@link
* SecurityManager#checkWrite checkWrite(fileName)} denies write
* access to the file
*
* @since 1.5
*/
public PrintWriter(String fileName) throws FileNotFoundException {
this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName))),
false);
}
/** {@collect.stats}
* {@description.open}
* Creates a new PrintWriter, without automatic line flushing, with the
* specified file name and charset. This convenience constructor creates
* the necessary intermediate {@link java.io.OutputStreamWriter
* OutputStreamWriter}, which will encode characters using the provided
* charset.
* {@description.close}
*
* @param fileName
* The name of the file to use as the destination of this writer.
* If the file exists then it will be truncated to zero size;
* otherwise, a new file will be created. The output will be
* written to the file and is buffered.
*
* @param csn
* The name of a supported {@linkplain java.nio.charset.Charset
* charset}
*
* @throws FileNotFoundException
* If the given string does not denote an existing, writable
* regular file and a new regular file of that name cannot be
* created, or if some other error occurs while opening or
* creating the file
*
* @throws SecurityException
* If a security manager is present and {@link
* SecurityManager#checkWrite checkWrite(fileName)} denies write
* access to the file
*
* @throws UnsupportedEncodingException
* If the named charset is not supported
*
* @since 1.5
*/
public PrintWriter(String fileName, String csn)
throws FileNotFoundException, UnsupportedEncodingException
{
this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(fileName), csn)),
false);
}
/** {@collect.stats}
* {@description.open}
* Creates a new PrintWriter, without automatic line flushing, with the
* specified file. This convenience constructor creates the necessary
* intermediate {@link java.io.OutputStreamWriter OutputStreamWriter},
* which will encode characters using the {@linkplain
* java.nio.charset.Charset#defaultCharset() default charset} for this
* instance of the Java virtual machine.
* {@description.close}
*
* @param file
* The file to use as the destination of this writer. If the file
* exists then it will be truncated to zero size; otherwise, a new
* file will be created. The output will be written to the file
* and is buffered.
*
* @throws FileNotFoundException
* If the given file object does not denote an existing, writable
* regular file and a new regular file of that name cannot be
* created, or if some other error occurs while opening or
* creating the file
*
* @throws SecurityException
* If a security manager is present and {@link
* SecurityManager#checkWrite checkWrite(file.getPath())}
* denies write access to the file
*
* @since 1.5
*/
public PrintWriter(File file) throws FileNotFoundException {
this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file))),
false);
}
/** {@collect.stats}
* {@description.open}
* Creates a new PrintWriter, without automatic line flushing, with the
* specified file and charset. This convenience constructor creates the
* necessary intermediate {@link java.io.OutputStreamWriter
* OutputStreamWriter}, which will encode characters using the provided
* charset.
* {@description.close}
*
* @param file
* The file to use as the destination of this writer. If the file
* exists then it will be truncated to zero size; otherwise, a new
* file will be created. The output will be written to the file
* and is buffered.
*
* @param csn
* The name of a supported {@linkplain java.nio.charset.Charset
* charset}
*
* @throws FileNotFoundException
* If the given file object does not denote an existing, writable
* regular file and a new regular file of that name cannot be
* created, or if some other error occurs while opening or
* creating the file
*
* @throws SecurityException
* If a security manager is present and {@link
* SecurityManager#checkWrite checkWrite(file.getPath())}
* denies write access to the file
*
* @throws UnsupportedEncodingException
* If the named charset is not supported
*
* @since 1.5
*/
public PrintWriter(File file, String csn)
throws FileNotFoundException, UnsupportedEncodingException
{
this(new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file), csn)),
false);
}
/** {@collect.stats}
* {@description.open}
* Checks to make sure that the stream has not been closed
* {@description.close}
*/
private void ensureOpen() throws IOException {
if (out == null)
throw new IOException("Stream closed");
}
/** {@collect.stats}
* {@description.open}
* Flushes the stream.
* {@description.close}
* @see #checkError()
*/
public void flush() {
try {
synchronized (lock) {
ensureOpen();
out.flush();
}
}
catch (IOException x) {
trouble = true;
}
}
/** {@collect.stats}
* {@description.open}
* Closes the stream and releases any system resources associated
* with it.
* {@description.close}
* {@property.open runtime formal:java.io.Closeable_MultipleClose}
* Closing a previously closed stream has no effect.
* {@property.close}
*
* @see #checkError()
*/
public void close() {
try {
synchronized (lock) {
if (out == null)
return;
out.close();
out = null;
}
}
catch (IOException x) {
trouble = true;
}
}
/** {@collect.stats}
* {@description.open}
* Flushes the stream if it's not closed and checks its error state.
* {@description.close}
*
* @return <code>true</code> if the print stream has encountered an error,
* either on the underlying output stream or during a format
* conversion.
*/
public boolean checkError() {
if (out != null) {
flush();
}
if (out instanceof java.io.PrintWriter) {
PrintWriter pw = (PrintWriter) out;
return pw.checkError();
} else if (psOut != null) {
return psOut.checkError();
}
return trouble;
}
/** {@collect.stats}
* {@description.open}
* Indicates that an error has occurred.
*
* <p> This method will cause subsequent invocations of {@link
* #checkError()} to return <tt>true</tt> until {@link
* #clearError()} is invoked.
* {@description.close}
*/
protected void setError() {
trouble = true;
}
/** {@collect.stats}
* {@description.open}
* Clears the error state of this stream.
*
* <p> This method will cause subsequent invocations of {@link
* #checkError()} to return <tt>false</tt> until another write
* operation fails and invokes {@link #setError()}.
* {@description.close}
*
* @since 1.6
*/
protected void clearError() {
trouble = false;
}
/*
* Exception-catching, synchronized output operations,
* which also implement the write() methods of Writer
*/
/** {@collect.stats}
* {@description.open}
* Writes a single character.
* {@description.close}
* @param c int specifying a character to be written.
*/
public void write(int c) {
try {
synchronized (lock) {
ensureOpen();
out.write(c);
}
}
catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
}
catch (IOException x) {
trouble = true;
}
}
/** {@collect.stats}
* {@description.open}
* Writes A Portion of an array of characters.
* {@description.close}
* @param buf Array of characters
* @param off Offset from which to start writing characters
* @param len Number of characters to write
*/
public void write(char buf[], int off, int len) {
try {
synchronized (lock) {
ensureOpen();
out.write(buf, off, len);
}
}
catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
}
catch (IOException x) {
trouble = true;
}
}
/** {@collect.stats}
* {@description.open}
* Writes an array of characters. This method cannot be inherited from the
* Writer class because it must suppress I/O exceptions.
* {@description.close}
* @param buf Array of characters to be written
*/
public void write(char buf[]) {
write(buf, 0, buf.length);
}
/** {@collect.stats}
* {@description.open}
* Writes a portion of a string.
* {@description.close}
* @param s A String
* @param off Offset from which to start writing characters
* @param len Number of characters to write
*/
public void write(String s, int off, int len) {
try {
synchronized (lock) {
ensureOpen();
out.write(s, off, len);
}
}
catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
}
catch (IOException x) {
trouble = true;
}
}
/** {@collect.stats}
* {@description.open}
* Writes a string. This method cannot be inherited from the Writer class
* because it must suppress I/O exceptions.
* {@description.close}
* @param s String to be written
*/
public void write(String s) {
write(s, 0, s.length());
}
private void newLine() {
try {
synchronized (lock) {
ensureOpen();
out.write(lineSeparator);
if (autoFlush)
out.flush();
}
}
catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
}
catch (IOException x) {
trouble = true;
}
}
/* Methods that do not terminate lines */
/** {@collect.stats}
* {@description.open}
* Prints a boolean value. The string produced by <code>{@link
* java.lang.String#valueOf(boolean)}</code> is translated into bytes
* according to the platform's default character encoding, and these bytes
* are written in exactly the manner of the <code>{@link
* #write(int)}</code> method.
* {@description.close}
*
* @param b The <code>boolean</code> to be printed
*/
public void print(boolean b) {
write(b ? "true" : "false");
}
/** {@collect.stats}
* {@description.open}
* Prints a character. The character is translated into one or more bytes
* according to the platform's default character encoding, and these bytes
* are written in exactly the manner of the <code>{@link
* #write(int)}</code> method.
* {@description.close}
*
* @param c The <code>char</code> to be printed
*/
public void print(char c) {
write(c);
}
/** {@collect.stats}
* {@description.open}
* Prints an integer. The string produced by <code>{@link
* java.lang.String#valueOf(int)}</code> is translated into bytes according
* to the platform's default character encoding, and these bytes are
* written in exactly the manner of the <code>{@link #write(int)}</code>
* method.
* {@description.close}
*
* @param i The <code>int</code> to be printed
* @see java.lang.Integer#toString(int)
*/
public void print(int i) {
write(String.valueOf(i));
}
/** {@collect.stats}
* {@description.open}
* Prints a long integer. The string produced by <code>{@link
* java.lang.String#valueOf(long)}</code> is translated into bytes
* according to the platform's default character encoding, and these bytes
* are written in exactly the manner of the <code>{@link #write(int)}</code>
* method.
* {@description.close}
*
* @param l The <code>long</code> to be printed
* @see java.lang.Long#toString(long)
*/
public void print(long l) {
write(String.valueOf(l));
}
/** {@collect.stats}
* {@description.open}
* Prints a floating-point number. The string produced by <code>{@link
* java.lang.String#valueOf(float)}</code> is translated into bytes
* according to the platform's default character encoding, and these bytes
* are written in exactly the manner of the <code>{@link #write(int)}</code>
* method.
* {@description.close}
*
* @param f The <code>float</code> to be printed
* @see java.lang.Float#toString(float)
*/
public void print(float f) {
write(String.valueOf(f));
}
/** {@collect.stats}
* {@description.open}
* Prints a double-precision floating-point number. The string produced by
* <code>{@link java.lang.String#valueOf(double)}</code> is translated into
* bytes according to the platform's default character encoding, and these
* bytes are written in exactly the manner of the <code>{@link
* #write(int)}</code> method.
* {@description.close}
*
* @param d The <code>double</code> to be printed
* @see java.lang.Double#toString(double)
*/
public void print(double d) {
write(String.valueOf(d));
}
/** {@collect.stats}
* {@description.open}
* Prints an array of characters. The characters are converted into bytes
* according to the platform's default character encoding, and these bytes
* are written in exactly the manner of the <code>{@link #write(int)}</code>
* method.
* {@description.close}
*
* @param s The array of chars to be printed
*
* @throws NullPointerException If <code>s</code> is <code>null</code>
*/
public void print(char s[]) {
write(s);
}
/** {@collect.stats}
* {@description.open}
* Prints a string. If the argument is <code>null</code> then the string
* <code>"null"</code> is printed. Otherwise, the string's characters are
* converted into bytes according to the platform's default character
* encoding, and these bytes are written in exactly the manner of the
* <code>{@link #write(int)}</code> method.
* {@description.close}
*
* @param s The <code>String</code> to be printed
*/
public void print(String s) {
if (s == null) {
s = "null";
}
write(s);
}
/** {@collect.stats}
* {@description.open}
* Prints an object. The string produced by the <code>{@link
* java.lang.String#valueOf(Object)}</code> method is translated into bytes
* according to the platform's default character encoding, and these bytes
* are written in exactly the manner of the <code>{@link #write(int)}</code>
* method.
* {@description.close}
*
* @param obj The <code>Object</code> to be printed
* @see java.lang.Object#toString()
*/
public void print(Object obj) {
write(String.valueOf(obj));
}
/* Methods that do terminate lines */
/** {@collect.stats}
* {@description.open}
* Terminates the current line by writing the line separator string. The
* line separator string is defined by the system property
* <code>line.separator</code>, and is not necessarily a single newline
* character (<code>'\n'</code>).
* {@description.close}
*/
public void println() {
newLine();
}
/** {@collect.stats}
* {@description.open}
* Prints a boolean value and then terminates the line. This method behaves
* as though it invokes <code>{@link #print(boolean)}</code> and then
* <code>{@link #println()}</code>.
* {@description.close}
*
* @param x the <code>boolean</code> value to be printed
*/
public void println(boolean x) {
synchronized (lock) {
print(x);
println();
}
}
/** {@collect.stats}
* {@description.open}
* Prints a character and then terminates the line. This method behaves as
* though it invokes <code>{@link #print(char)}</code> and then <code>{@link
* #println()}</code>.
* {@description.close}
*
* @param x the <code>char</code> value to be printed
*/
public void println(char x) {
synchronized (lock) {
print(x);
println();
}
}
/** {@collect.stats}
* {@description.open}
* Prints an integer and then terminates the line. This method behaves as
* though it invokes <code>{@link #print(int)}</code> and then <code>{@link
* #println()}</code>.
* {@description.close}
*
* @param x the <code>int</code> value to be printed
*/
public void println(int x) {
synchronized (lock) {
print(x);
println();
}
}
/** {@collect.stats}
* {@description.open}
* Prints a long integer and then terminates the line. This method behaves
* as though it invokes <code>{@link #print(long)}</code> and then
* <code>{@link #println()}</code>.
* {@description.close}
*
* @param x the <code>long</code> value to be printed
*/
public void println(long x) {
synchronized (lock) {
print(x);
println();
}
}
/** {@collect.stats}
* {@description.open}
* Prints a floating-point number and then terminates the line. This method
* behaves as though it invokes <code>{@link #print(float)}</code> and then
* <code>{@link #println()}</code>.
* {@description.close}
*
* @param x the <code>float</code> value to be printed
*/
public void println(float x) {
synchronized (lock) {
print(x);
println();
}
}
/** {@collect.stats}
* {@description.open}
* Prints a double-precision floating-point number and then terminates the
* line. This method behaves as though it invokes <code>{@link
* #print(double)}</code> and then <code>{@link #println()}</code>.
* {@description.close}
*
* @param x the <code>double</code> value to be printed
*/
public void println(double x) {
synchronized (lock) {
print(x);
println();
}
}
/** {@collect.stats}
* {@description.open}
* Prints an array of characters and then terminates the line. This method
* behaves as though it invokes <code>{@link #print(char[])}</code> and then
* <code>{@link #println()}</code>.
* {@description.close}
*
* @param x the array of <code>char</code> values to be printed
*/
public void println(char x[]) {
synchronized (lock) {
print(x);
println();
}
}
/** {@collect.stats}
* {@description.open}
* Prints a String and then terminates the line. This method behaves as
* though it invokes <code>{@link #print(String)}</code> and then
* <code>{@link #println()}</code>.
* {@description.close}
*
* @param x the <code>String</code> value to be printed
*/
public void println(String x) {
synchronized (lock) {
print(x);
println();
}
}
/** {@collect.stats}
* {@description.open}
* Prints an Object and then terminates the line. This method calls
* at first String.valueOf(x) to get the printed object's string value,
* then behaves as
* though it invokes <code>{@link #print(String)}</code> and then
* <code>{@link #println()}</code>.
* {@description.close}
*
* @param x The <code>Object</code> to be printed.
*/
public void println(Object x) {
String s = String.valueOf(x);
synchronized (lock) {
print(s);
println();
}
}
/** {@collect.stats}
* {@description.open}
* A convenience method to write a formatted string to this writer using
* the specified format string and arguments. If automatic flushing is
* enabled, calls to this method will flush the output buffer.
*
* <p> An invocation of this method of the form <tt>out.printf(format,
* args)</tt> behaves in exactly the same way as the invocation
*
* <pre>
* out.format(format, args) </pre>
* {@description.close}
*
* @param format
* A format string as described in <a
* href="../util/Formatter.html#syntax">Format string syntax</a>.
*
* @param args
* Arguments referenced by the format specifiers in the format
* string. If there are more arguments than format specifiers, the
* extra arguments are ignored. The number of arguments is
* variable and may be zero. The maximum number of arguments is
* limited by the maximum dimension of a Java array as defined by
* the <a href="http://java.sun.com/docs/books/vmspec/">Java
* Virtual Machine Specification</a>. The behaviour on a
* <tt>null</tt> argument depends on the <a
* href="../util/Formatter.html#syntax">conversion</a>.
*
* @throws IllegalFormatException
* If a format string contains an illegal syntax, a format
* specifier that is incompatible with the given arguments,
* insufficient arguments given the format string, or other
* illegal conditions. For specification of all possible
* formatting errors, see the <a
* href="../util/Formatter.html#detail">Details</a> section of the
* formatter class specification.
*
* @throws NullPointerException
* If the <tt>format</tt> is <tt>null</tt>
*
* @return This writer
*
* @since 1.5
*/
public PrintWriter printf(String format, Object ... args) {
return format(format, args);
}
/** {@collect.stats}
* {@description.open}
* A convenience method to write a formatted string to this writer using
* the specified format string and arguments. If automatic flushing is
* enabled, calls to this method will flush the output buffer.
*
* <p> An invocation of this method of the form <tt>out.printf(l, format,
* args)</tt> behaves in exactly the same way as the invocation
*
* <pre>
* out.format(l, format, args) </pre>
* {@description.close}
*
* @param l
* The {@linkplain java.util.Locale locale} to apply during
* formatting. If <tt>l</tt> is <tt>null</tt> then no localization
* is applied.
*
* @param format
* A format string as described in <a
* href="../util/Formatter.html#syntax">Format string syntax</a>.
*
* @param args
* Arguments referenced by the format specifiers in the format
* string. If there are more arguments than format specifiers, the
* extra arguments are ignored. The number of arguments is
* variable and may be zero. The maximum number of arguments is
* limited by the maximum dimension of a Java array as defined by
* the <a href="http://java.sun.com/docs/books/vmspec/">Java
* Virtual Machine Specification</a>. The behaviour on a
* <tt>null</tt> argument depends on the <a
* href="../util/Formatter.html#syntax">conversion</a>.
*
* @throws IllegalFormatException
* If a format string contains an illegal syntax, a format
* specifier that is incompatible with the given arguments,
* insufficient arguments given the format string, or other
* illegal conditions. For specification of all possible
* formatting errors, see the <a
* href="../util/Formatter.html#detail">Details</a> section of the
* formatter class specification.
*
* @throws NullPointerException
* If the <tt>format</tt> is <tt>null</tt>
*
* @return This writer
*
* @since 1.5
*/
public PrintWriter printf(Locale l, String format, Object ... args) {
return format(l, format, args);
}
/** {@collect.stats}
* {@description.open}
* Writes a formatted string to this writer using the specified format
* string and arguments. If automatic flushing is enabled, calls to this
* method will flush the output buffer.
*
* <p> The locale always used is the one returned by {@link
* java.util.Locale#getDefault() Locale.getDefault()}, regardless of any
* previous invocations of other formatting methods on this object.
* {@description.close}
*
* @param format
* A format string as described in <a
* href="../util/Formatter.html#syntax">Format string syntax</a>.
*
* @param args
* Arguments referenced by the format specifiers in the format
* string. If there are more arguments than format specifiers, the
* extra arguments are ignored. The number of arguments is
* variable and may be zero. The maximum number of arguments is
* limited by the maximum dimension of a Java array as defined by
* the <a href="http://java.sun.com/docs/books/vmspec/">Java
* Virtual Machine Specification</a>. The behaviour on a
* <tt>null</tt> argument depends on the <a
* href="../util/Formatter.html#syntax">conversion</a>.
*
* @throws IllegalFormatException
* If a format string contains an illegal syntax, a format
* specifier that is incompatible with the given arguments,
* insufficient arguments given the format string, or other
* illegal conditions. For specification of all possible
* formatting errors, see the <a
* href="../util/Formatter.html#detail">Details</a> section of the
* Formatter class specification.
*
* @throws NullPointerException
* If the <tt>format</tt> is <tt>null</tt>
*
* @return This writer
*
* @since 1.5
*/
public PrintWriter format(String format, Object ... args) {
try {
synchronized (lock) {
ensureOpen();
if ((formatter == null)
|| (formatter.locale() != Locale.getDefault()))
formatter = new Formatter(this);
formatter.format(Locale.getDefault(), format, args);
if (autoFlush)
out.flush();
}
} catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
} catch (IOException x) {
trouble = true;
}
return this;
}
/** {@collect.stats}
* {@description.open}
* Writes a formatted string to this writer using the specified format
* string and arguments. If automatic flushing is enabled, calls to this
* method will flush the output buffer.
* {@description.close}
*
* @param l
* The {@linkplain java.util.Locale locale} to apply during
* formatting. If <tt>l</tt> is <tt>null</tt> then no localization
* is applied.
*
* @param format
* A format string as described in <a
* href="../util/Formatter.html#syntax">Format string syntax</a>.
*
* @param args
* Arguments referenced by the format specifiers in the format
* string. If there are more arguments than format specifiers, the
* extra arguments are ignored. The number of arguments is
* variable and may be zero. The maximum number of arguments is
* limited by the maximum dimension of a Java array as defined by
* the <a href="http://java.sun.com/docs/books/vmspec/">Java
* Virtual Machine Specification</a>. The behaviour on a
* <tt>null</tt> argument depends on the <a
* href="../util/Formatter.html#syntax">conversion</a>.
*
* @throws IllegalFormatException
* If a format string contains an illegal syntax, a format
* specifier that is incompatible with the given arguments,
* insufficient arguments given the format string, or other
* illegal conditions. For specification of all possible
* formatting errors, see the <a
* href="../util/Formatter.html#detail">Details</a> section of the
* formatter class specification.
*
* @throws NullPointerException
* If the <tt>format</tt> is <tt>null</tt>
*
* @return This writer
*
* @since 1.5
*/
public PrintWriter format(Locale l, String format, Object ... args) {
try {
synchronized (lock) {
ensureOpen();
if ((formatter == null) || (formatter.locale() != l))
formatter = new Formatter(this, l);
formatter.format(l, format, args);
if (autoFlush)
out.flush();
}
} catch (InterruptedIOException x) {
Thread.currentThread().interrupt();
} catch (IOException x) {
trouble = true;
}
return this;
}
/** {@collect.stats}
* {@description.open}
* Appends the specified character sequence to this writer.
*
* <p> An invocation of this method of the form <tt>out.append(csq)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* out.write(csq.toString()) </pre>
*
* <p> Depending on the specification of <tt>toString</tt> for the
* character sequence <tt>csq</tt>, the entire sequence may not be
* appended. For instance, invoking the <tt>toString</tt> method of a
* character buffer will return a subsequence whose content depends upon
* the buffer's position and limit.
* {@description.close}
*
* @param csq
* The character sequence to append. If <tt>csq</tt> is
* <tt>null</tt>, then the four characters <tt>"null"</tt> are
* appended to this writer.
*
* @return This writer
*
* @since 1.5
*/
public PrintWriter append(CharSequence csq) {
if (csq == null)
write("null");
else
write(csq.toString());
return this;
}
/** {@collect.stats}
* {@description.open}
* Appends a subsequence of the specified character sequence to this writer.
*
* <p> An invocation of this method of the form <tt>out.append(csq, start,
* end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
* exactly the same way as the invocation
*
* <pre>
* out.write(csq.subSequence(start, end).toString()) </pre>
* {@description.close}
*
* @param csq
* The character sequence from which a subsequence will be
* appended. If <tt>csq</tt> is <tt>null</tt>, then characters
* will be appended as if <tt>csq</tt> contained the four
* characters <tt>"null"</tt>.
*
* @param start
* The index of the first character in the subsequence
*
* @param end
* The index of the character following the last character in the
* subsequence
*
* @return This writer
*
* @throws IndexOutOfBoundsException
* If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
* is greater than <tt>end</tt>, or <tt>end</tt> is greater than
* <tt>csq.length()</tt>
*
* @since 1.5
*/
public PrintWriter append(CharSequence csq, int start, int end) {
CharSequence cs = (csq == null ? "null" : csq);
write(cs.subSequence(start, end).toString());
return this;
}
/** {@collect.stats}
* {@description.open}
* Appends the specified character to this writer.
*
* <p> An invocation of this method of the form <tt>out.append(c)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* out.write(c) </pre>
* {@description.close}
*
* @param c
* The 16-bit character to append
*
* @return This writer
*
* @since 1.5
*/
public PrintWriter append(char c) {
write(c);
return this;
}
}
|
Java
|
/*
* Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.io.IOException;
/** {@collect.stats}
* {@description.open}
* A <tt>Closeable</tt> is a source or destination of data that can be closed.
* The close method is invoked to release resources that the object is
* holding (such as open files).
* {@description.close}
*
* @since 1.5
*/
public interface Closeable {
/** {@collect.stats}
* {@description.open}
* Closes this stream and releases any system resources associated
* with it.
* {@description.close}
* {@property.open runtime formal:java.io.Closeable_MultipleClose}
* If the stream is already closed then invoking this
* method has no effect.
* {@property.close}
*
* @throws IOException if an I/O error occurs
*/
public void close() throws IOException;
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Indicates that one or more deserialized objects failed validation
* tests. The argument should provide the reason for the failure.
* {@description.close}
*
* @see ObjectInputValidation
* @since JDK1.1
*
* @author unascribed
* @since JDK1.1
*/
public class InvalidObjectException extends ObjectStreamException {
private static final long serialVersionUID = 3233174318281839583L;
/** {@collect.stats}
* {@description.open}
* Constructs an <code>InvalidObjectException</code>.
* {@description.close}
* @param reason Detailed message explaining the reason for the failure.
*
* @see ObjectInputValidation
*/
public InvalidObjectException(String reason) {
super(reason);
}
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* A buffered character-input stream that keeps track of line numbers. This
* class defines methods {@link #setLineNumber(int)} and {@link
* #getLineNumber()} for setting and getting the current line number
* respectively.
*
* <p> By default, line numbering begins at 0. This number increments at every
* <a href="#lt">line terminator</a> as the data is read, and can be changed
* with a call to <tt>setLineNumber(int)</tt>. Note however, that
* <tt>setLineNumber(int)</tt> does not actually change the current position in
* the stream; it only changes the value that will be returned by
* <tt>getLineNumber()</tt>.
*
* <p> A line is considered to be <a name="lt">terminated</a> by any one of a
* line feed ('\n'), a carriage return ('\r'), or a carriage return followed
* immediately by a linefeed.
* {@description.close}
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class LineNumberReader extends BufferedReader {
/** {@collect.stats}
* {@description.open}
* The current line number
* {@description.close}
*/
private int lineNumber = 0;
/** {@collect.stats}
* {@description.open}
* The line number of the mark, if any
* {@description.close}
*/
private int markedLineNumber; // Defaults to 0
/** {@collect.stats}
* {@description.open}
* If the next character is a line feed, skip it
* {@description.close}
*/
private boolean skipLF;
/** {@collect.stats}
* {@description.open}
* The skipLF flag when the mark was set
* {@description.close}
*/
private boolean markedSkipLF;
/** {@collect.stats}
* {@description.open}
* Create a new line-numbering reader, using the default input-buffer
* size.
* {@description.close}
*
* @param in
* A Reader object to provide the underlying stream
*/
public LineNumberReader(Reader in) {
super(in);
}
/** {@collect.stats}
* {@description.open}
* Create a new line-numbering reader, reading characters into a buffer of
* the given size.
* {@description.close}
*
* @param in
* A Reader object to provide the underlying stream
*
* @param sz
* An int specifying the size of the buffer
*/
public LineNumberReader(Reader in, int sz) {
super(in, sz);
}
/** {@collect.stats}
* {@description.open}
* Set the current line number.
* {@description.close}
*
* @param lineNumber
* An int specifying the line number
*
* @see #getLineNumber
*/
public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}
/** {@collect.stats}
* {@description.open}
* Get the current line number.
* {@description.close}
*
* @return The current line number
*
* @see #setLineNumber
*/
public int getLineNumber() {
return lineNumber;
}
/** {@collect.stats}
* {@description.open}
* Read a single character. <a href="#lt">Line terminators</a> are
* compressed into single newline ('\n') characters. Whenever a line
* terminator is read the current line number is incremented.
* {@description.close}
*
* @return The character read, or -1 if the end of the stream has been
* reached
*
* @throws IOException
* If an I/O error occurs
*/
public int read() throws IOException {
synchronized (lock) {
int c = super.read();
if (skipLF) {
if (c == '\n')
c = super.read();
skipLF = false;
}
switch (c) {
case '\r':
skipLF = true;
case '\n': /* Fall through */
lineNumber++;
return '\n';
}
return c;
}
}
/** {@collect.stats}
* {@description.open}
* Read characters into a portion of an array. Whenever a <a
* href="#lt">line terminator</a> is read the current line number is
* incremented.
* {@description.close}
*
* @param cbuf
* Destination buffer
*
* @param off
* Offset at which to start storing characters
*
* @param len
* Maximum number of characters to read
*
* @return The number of bytes read, or -1 if the end of the stream has
* already been reached
*
* @throws IOException
* If an I/O error occurs
*/
public int read(char cbuf[], int off, int len) throws IOException {
synchronized (lock) {
int n = super.read(cbuf, off, len);
for (int i = off; i < off + n; i++) {
int c = cbuf[i];
if (skipLF) {
skipLF = false;
if (c == '\n')
continue;
}
switch (c) {
case '\r':
skipLF = true;
case '\n': /* Fall through */
lineNumber++;
break;
}
}
return n;
}
}
/** {@collect.stats}
* {@description.open}
* Read a line of text. Whenever a <a href="#lt">line terminator</a> is
* read the current line number is incremented.
* {@description.close}
*
* @return A String containing the contents of the line, not including
* any <a href="#lt">line termination characters</a>, or
* <tt>null</tt> if the end of the stream has been reached
*
* @throws IOException
* If an I/O error occurs
*/
public String readLine() throws IOException {
synchronized (lock) {
String l = super.readLine(skipLF);
skipLF = false;
if (l != null)
lineNumber++;
return l;
}
}
/** {@collect.stats}
* {@description.open}
* Maximum skip-buffer size
* {@description.close}
*/
private static final int maxSkipBufferSize = 8192;
/** {@collect.stats}
* {@description.open}
* Skip buffer, null until allocated
* {@description.close}
*/
private char skipBuffer[] = null;
/** {@collect.stats}
* {@description.open}
* Skip characters.
* {@description.close}
*
* @param n
* The number of characters to skip
*
* @return The number of characters actually skipped
*
* @throws IOException
* If an I/O error occurs
*
* @throws IllegalArgumentException
* If <tt>n</tt> is negative
*/
public long skip(long n) throws IOException {
if (n < 0)
throw new IllegalArgumentException("skip() value is negative");
int nn = (int) Math.min(n, maxSkipBufferSize);
synchronized (lock) {
if ((skipBuffer == null) || (skipBuffer.length < nn))
skipBuffer = new char[nn];
long r = n;
while (r > 0) {
int nc = read(skipBuffer, 0, (int) Math.min(r, nn));
if (nc == -1)
break;
r -= nc;
}
return n - r;
}
}
/** {@collect.stats}
* {@description.open}
* Mark the present position in the stream. Subsequent calls to reset()
* will attempt to reposition the stream to this point, and will also reset
* the line number appropriately.
* {@description.close}
*
* @param readAheadLimit
* Limit on the number of characters that may be read while still
* preserving the mark. After reading this many characters,
* attempting to reset the stream may fail.
*
* @throws IOException
* If an I/O error occurs
*/
public void mark(int readAheadLimit) throws IOException {
synchronized (lock) {
super.mark(readAheadLimit);
markedLineNumber = lineNumber;
markedSkipLF = skipLF;
}
}
/** {@collect.stats}
* {@description.open}
* Reset the stream to the most recent mark.
* {@description.close}
*
* @throws IOException
* If the stream has not been marked, or if the mark has been
* invalidated
*/
public void reset() throws IOException {
synchronized (lock) {
super.reset();
lineNumber = markedLineNumber;
skipLF = markedSkipLF;
}
}
}
|
Java
|
/*
* Copyright (c) 1995, 2000, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Signals that an end of file or end of stream has been reached
* unexpectedly during input.
* <p>
* This exception is mainly used by data input streams to signal end of
* stream. Note that many other input operations return a special value on
* end of stream rather than throwing an exception.
* <p>
* {@description.close}
*
* @author Frank Yellin
* @see java.io.DataInputStream
* @see java.io.IOException
* @since JDK1.0
*/
public
class EOFException extends IOException {
/** {@collect.stats}
* {@description.open}
* Constructs an <code>EOFException</code> with <code>null</code>
* as its error detail message.
* {@description.close}
*/
public EOFException() {
super();
}
/** {@collect.stats}
* {@description.open}
* Constructs an <code>EOFException</code> with the specified detail
* message. The string <code>s</code> may later be retrieved by the
* <code>{@link java.lang.Throwable#getMessage}</code> method of class
* <code>java.lang.Throwable</code>.
* {@description.close}
*
* @param s the detail message.
*/
public EOFException(String s) {
super(s);
}
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.nio.charset.Charset;
import java.nio.charset.CharsetEncoder;
import sun.nio.cs.StreamEncoder;
/** {@collect.stats}
* {@description.open}
* An OutputStreamWriter is a bridge from character streams to byte streams:
* Characters written to it are encoded into bytes using a specified {@link
* java.nio.charset.Charset <code>charset</code>}. The charset that it uses
* may be specified by name or may be given explicitly, or the platform's
* default charset may be accepted.
*
* <p> Each invocation of a write() method causes the encoding converter to be
* invoked on the given character(s). The resulting bytes are accumulated in a
* buffer before being written to the underlying output stream. The size of
* this buffer may be specified, but by default it is large enough for most
* purposes. Note that the characters passed to the write() methods are not
* buffered.
*
* <p> For top efficiency, consider wrapping an OutputStreamWriter within a
* BufferedWriter so as to avoid frequent converter invocations. For example:
*
* <pre>
* Writer out
* = new BufferedWriter(new OutputStreamWriter(System.out));
* </pre>
*
* <p> A <i>surrogate pair</i> is a character represented by a sequence of two
* <tt>char</tt> values: A <i>high</i> surrogate in the range '\uD800' to
* '\uDBFF' followed by a <i>low</i> surrogate in the range '\uDC00' to
* '\uDFFF'.
*
* <p> A <i>malformed surrogate element</i> is a high surrogate that is not
* followed by a low surrogate or a low surrogate that is not preceded by a
* high surrogate.
*
* <p> This class always replaces malformed surrogate elements and unmappable
* character sequences with the charset's default <i>substitution sequence</i>.
* The {@linkplain java.nio.charset.CharsetEncoder} class should be used when more
* control over the encoding process is required.
* {@description.close}
*
* @see BufferedWriter
* @see OutputStream
* @see java.nio.charset.Charset
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class OutputStreamWriter extends Writer {
private final StreamEncoder se;
/** {@collect.stats}
* {@description.open}
* Creates an OutputStreamWriter that uses the named charset.
* {@description.close}
*
* @param out
* An OutputStream
*
* @param charsetName
* The name of a supported
* {@link java.nio.charset.Charset </code>charset<code>}
*
* @exception UnsupportedEncodingException
* If the named encoding is not supported
*/
public OutputStreamWriter(OutputStream out, String charsetName)
throws UnsupportedEncodingException
{
super(out);
if (charsetName == null)
throw new NullPointerException("charsetName");
se = StreamEncoder.forOutputStreamWriter(out, this, charsetName);
}
/** {@collect.stats}
* {@description.open}
* Creates an OutputStreamWriter that uses the default character encoding.
* {@description.close}
*
* @param out An OutputStream
*/
public OutputStreamWriter(OutputStream out) {
super(out);
try {
se = StreamEncoder.forOutputStreamWriter(out, this, (String)null);
} catch (UnsupportedEncodingException e) {
throw new Error(e);
}
}
/** {@collect.stats}
* {@description.open}
* Creates an OutputStreamWriter that uses the given charset. </p>
* {@description.close}
*
* @param out
* An OutputStream
*
* @param cs
* A charset
*
* @since 1.4
* @spec JSR-51
*/
public OutputStreamWriter(OutputStream out, Charset cs) {
super(out);
if (cs == null)
throw new NullPointerException("charset");
se = StreamEncoder.forOutputStreamWriter(out, this, cs);
}
/** {@collect.stats}
* {@description.open}
* Creates an OutputStreamWriter that uses the given charset encoder. </p>
* {@description.close}
*
* @param out
* An OutputStream
*
* @param enc
* A charset encoder
*
* @since 1.4
* @spec JSR-51
*/
public OutputStreamWriter(OutputStream out, CharsetEncoder enc) {
super(out);
if (enc == null)
throw new NullPointerException("charset encoder");
se = StreamEncoder.forOutputStreamWriter(out, this, enc);
}
/** {@collect.stats}
* {@description.open}
* Returns the name of the character encoding being used by this stream.
*
* <p> If the encoding has an historical name then that name is returned;
* otherwise the encoding's canonical name is returned.
*
* <p> If this instance was created with the {@link
* #OutputStreamWriter(OutputStream, String)} constructor then the returned
* name, being unique for the encoding, may differ from the name passed to
* the constructor. This method may return <tt>null</tt> if the stream has
* been closed. </p>
* {@description.close}
*
* @return The historical name of this encoding, or possibly
* <code>null</code> if the stream has been closed
*
* @see java.nio.charset.Charset
*
* @revised 1.4
* @spec JSR-51
*/
public String getEncoding() {
return se.getEncoding();
}
/** {@collect.stats}
* {@description.open}
* Flushes the output buffer to the underlying byte stream, without flushing
* the byte stream itself. This method is non-private only so that it may
* be invoked by PrintStream.
* {@description.close}
*/
void flushBuffer() throws IOException {
se.flushBuffer();
}
/** {@collect.stats}
* {@description.open}
* Writes a single character.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public void write(int c) throws IOException {
se.write(c);
}
/** {@collect.stats}
* {@description.open}
* Writes a portion of an array of characters.
* {@description.close}
*
* @param cbuf Buffer of characters
* @param off Offset from which to start writing characters
* @param len Number of characters to write
*
* @exception IOException If an I/O error occurs
*/
public void write(char cbuf[], int off, int len) throws IOException {
se.write(cbuf, off, len);
}
/** {@collect.stats}
* {@description.open}
* Writes a portion of a string.
* {@description.close}
*
* @param str A String
* @param off Offset from which to start writing characters
* @param len Number of characters to write
*
* @exception IOException If an I/O error occurs
*/
public void write(String str, int off, int len) throws IOException {
se.write(str, off, len);
}
/** {@collect.stats}
* {@description.open}
* Flushes the stream.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public void flush() throws IOException {
se.flush();
}
public void close() throws IOException {
se.close();
}
}
|
Java
|
/*
* Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* This class allows an application to create an input stream in
* which the bytes read are supplied by the contents of a string.
* Applications can also read bytes from a byte array by using a
* <code>ByteArrayInputStream</code>.
* <p>
* Only the low eight bits of each character in the string are used by
* this class.
* {@description.close}
*
* @author Arthur van Hoff
* @see java.io.ByteArrayInputStream
* @see java.io.StringReader
* @since JDK1.0
* @deprecated This class does not properly convert characters into bytes. As
* of JDK 1.1, the preferred way to create a stream from a
* string is via the <code>StringReader</code> class.
*/
@Deprecated
public
class StringBufferInputStream extends InputStream {
/** {@collect.stats}
* {@description.open}
* The string from which bytes are read.
* {@description.close}
*/
protected String buffer;
/** {@collect.stats}
* {@description.open}
* The index of the next character to read from the input stream buffer.
* {@description.close}
*
* @see java.io.StringBufferInputStream#buffer
*/
protected int pos;
/** {@collect.stats}
* {@description.open}
* The number of valid characters in the input stream buffer.
* {@description.close}
*
* @see java.io.StringBufferInputStream#buffer
*/
protected int count;
/** {@collect.stats}
* {@description.open}
* Creates a string input stream to read data from the specified string.
* {@description.close}
*
* @param s the underlying input buffer.
*/
public StringBufferInputStream(String s) {
this.buffer = s;
count = s.length();
}
/** {@collect.stats}
* {@description.open}
* Reads the next byte of data from this input stream. The value
* byte is returned as an <code>int</code> in the range
* <code>0</code> to <code>255</code>. If no byte is available
* because the end of the stream has been reached, the value
* <code>-1</code> is returned.
* <p>
* The <code>read</code> method of
* <code>StringBufferInputStream</code> cannot block. It returns the
* low eight bits of the next character in this input stream's buffer.
* {@description.close}
*
* @return the next byte of data, or <code>-1</code> if the end of the
* stream is reached.
*/
public synchronized int read() {
return (pos < count) ? (buffer.charAt(pos++) & 0xFF) : -1;
}
/** {@collect.stats}
* {@description.open}
* Reads up to <code>len</code> bytes of data from this input stream
* into an array of bytes.
* <p>
* The <code>read</code> method of
* <code>StringBufferInputStream</code> cannot block. It copies the
* low eight bits from the characters in this input stream's buffer into
* the byte array argument.
* {@description.close}
*
* @param b the buffer into which the data is read.
* @param off the start offset of the data.
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the stream has been reached.
*/
public synchronized int read(byte b[], int off, int len) {
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
}
if (pos >= count) {
return -1;
}
if (pos + len > count) {
len = count - pos;
}
if (len <= 0) {
return 0;
}
String s = buffer;
int cnt = len;
while (--cnt >= 0) {
b[off++] = (byte)s.charAt(pos++);
}
return len;
}
/** {@collect.stats}
* {@description.open}
* Skips <code>n</code> bytes of input from this input stream. Fewer
* bytes might be skipped if the end of the input stream is reached.
* {@description.close}
*
* @param n the number of bytes to be skipped.
* @return the actual number of bytes skipped.
*/
public synchronized long skip(long n) {
if (n < 0) {
return 0;
}
if (n > count - pos) {
n = count - pos;
}
pos += n;
return n;
}
/** {@collect.stats}
* {@description.open}
* Returns the number of bytes that can be read from the input
* stream without blocking.
* {@description.close}
*
* @return the value of <code>count - pos</code>, which is the
* number of bytes remaining to be read from the input buffer.
*/
public synchronized int available() {
return count - pos;
}
/** {@collect.stats}
* {@description.open}
* Resets the input stream to begin reading from the first character
* of this input stream's underlying buffer.
* {@description.close}
*/
public synchronized void reset() {
pos = 0;
}
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Serializability of a class is enabled by the class implementing the
* java.io.Serializable interface. Classes that do not implement this
* interface will not have any of their state serialized or
* deserialized. All subtypes of a serializable class are themselves
* serializable. The serialization interface has no methods or fields
* and serves only to identify the semantics of being serializable. <p>
* {@description.close}
*
* {@property.open runtime formal:java.io.Serializable_NoArgConstructor}
* To allow subtypes of non-serializable classes to be serialized, the
* subtype may assume responsibility for saving and restoring the
* state of the supertype's public, protected, and (if accessible)
* package fields. The subtype may assume this responsibility only if
* the class it extends has an accessible no-arg constructor to
* initialize the class's state. It is an error to declare a class
* Serializable if this is not the case. The error will be detected at
* runtime. <p>
*
* During deserialization, the fields of non-serializable classes will
* be initialized using the public or protected no-arg constructor of
* the class. A no-arg constructor must be accessible to the subclass
* that is serializable. The fields of serializable subclasses will
* be restored from the stream. <p>
* {@property.close}
*
* {@description.open}
* When traversing a graph, an object may be encountered that does not
* support the Serializable interface. In this case the
* NotSerializableException will be thrown and will identify the class
* of the non-serializable object. <p>
*
* Classes that require special handling during the serialization and
* deserialization process must implement special methods with these exact
* signatures: <p>
*
* <PRE>
* private void writeObject(java.io.ObjectOutputStream out)
* throws IOException
* private void readObject(java.io.ObjectInputStream in)
* throws IOException, ClassNotFoundException;
* private void readObjectNoData()
* throws ObjectStreamException;
* </PRE>
*
* <p>The writeObject method is responsible for writing the state of the
* object for its particular class so that the corresponding
* readObject method can restore it. The default mechanism for saving
* the Object's fields can be invoked by calling
* out.defaultWriteObject. The method does not need to concern
* itself with the state belonging to its superclasses or subclasses.
* State is saved by writing the individual fields to the
* ObjectOutputStream using the writeObject method or by using the
* methods for primitive data types supported by DataOutput.
*
* <p>The readObject method is responsible for reading from the stream and
* restoring the classes fields. It may call in.defaultReadObject to invoke
* the default mechanism for restoring the object's non-static and
* non-transient fields. The defaultReadObject method uses information in
* the stream to assign the fields of the object saved in the stream with the
* correspondingly named fields in the current object. This handles the case
* when the class has evolved to add new fields. The method does not need to
* concern itself with the state belonging to its superclasses or subclasses.
* State is saved by writing the individual fields to the
* ObjectOutputStream using the writeObject method or by using the
* methods for primitive data types supported by DataOutput.
*
* <p>The readObjectNoData method is responsible for initializing the state of
* the object for its particular class in the event that the serialization
* stream does not list the given class as a superclass of the object being
* deserialized. This may occur in cases where the receiving party uses a
* different version of the deserialized instance's class than the sending
* party, and the receiver's version extends classes that are not extended by
* the sender's version. This may also occur if the serialization stream has
* been tampered; hence, readObjectNoData is useful for initializing
* deserialized objects properly despite a "hostile" or incomplete source
* stream.
*
* <p>Serializable classes that need to designate an alternative object to be
* used when writing an object to the stream should implement this
* special method with the exact signature: <p>
*
* <PRE>
* ANY-ACCESS-MODIFIER Object writeReplace() throws ObjectStreamException;
* </PRE><p>
*
* This writeReplace method is invoked by serialization if the method
* exists and it would be accessible from a method defined within the
* class of the object being serialized. Thus, the method can have private,
* protected and package-private access. Subclass access to this method
* follows java accessibility rules. <p>
*
* Classes that need to designate a replacement when an instance of it
* is read from the stream should implement this special method with the
* exact signature.<p>
*
* <PRE>
* ANY-ACCESS-MODIFIER Object readResolve() throws ObjectStreamException;
* </PRE><p>
*
* This readResolve method follows the same invocation rules and
* accessibility rules as writeReplace.<p>
*
* The serialization runtime associates with each serializable class a version
* number, called a serialVersionUID, which is used during deserialization to
* verify that the sender and receiver of a serialized object have loaded
* classes for that object that are compatible with respect to serialization.
* If the receiver has loaded a class for the object that has a different
* serialVersionUID than that of the corresponding sender's class, then
* deserialization will result in an {@link InvalidClassException}. A
* serializable class can declare its own serialVersionUID explicitly by
* declaring a field named <code>"serialVersionUID"</code> that must be static,
* final, and of type <code>long</code>:<p>
*
* <PRE>
* ANY-ACCESS-MODIFIER static final long serialVersionUID = 42L;
* </PRE>
* {@description.close}
*
* {@property.open runtime formal:java.io.Serializable_UID}
* If a serializable class does not explicitly declare a serialVersionUID, then
* the serialization runtime will calculate a default serialVersionUID value
* for that class based on various aspects of the class, as described in the
* Java(TM) Object Serialization Specification. However, it is <em>strongly
* recommended</em> that all serializable classes explicitly declare
* serialVersionUID values, since the default serialVersionUID computation is
* highly sensitive to class details that may vary depending on compiler
* implementations, and can thus result in unexpected
* <code>InvalidClassException</code>s during deserialization. Therefore, to
* guarantee a consistent serialVersionUID value across different java compiler
* implementations, a serializable class must declare an explicit
* serialVersionUID value. It is also strongly advised that explicit
* serialVersionUID declarations use the <code>private</code> modifier where
* possible, since such declarations apply only to the immediately declaring
* class--serialVersionUID fields are not useful as inherited members. Array
* classes cannot declare an explicit serialVersionUID, so they always have
* the default computed value, but the requirement for matching
* serialVersionUID values is waived for array classes.
* {@new.open}
* A serializable class should declare a private serialVersionUID explicitly
* for compatibility.
* {@new.close}
* {@property.close}
*
* @author unascribed
* @see java.io.ObjectOutputStream
* @see java.io.ObjectInputStream
* @see java.io.ObjectOutput
* @see java.io.ObjectInput
* @see java.io.Externalizable
* @since JDK1.1
*/
public interface Serializable {
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Thrown when the Serialization runtime detects one of the following
* problems with a Class.
* <UL>
* <LI> The serial version of the class does not match that of the class
* descriptor read from the stream
* <LI> The class contains unknown datatypes
* <LI> The class does not have an accessible no-arg constructor
* </UL>
* {@description.close}
*
* @author unascribed
* @since JDK1.1
*/
public class InvalidClassException extends ObjectStreamException {
private static final long serialVersionUID = -4333316296251054416L;
/** {@collect.stats}
* {@description.open}
* Name of the invalid class.
* {@description.close}
*
* @serial Name of the invalid class.
*/
public String classname;
/** {@collect.stats}
* {@description.open}
* Report an InvalidClassException for the reason specified.
* {@description.close}
*
* @param reason String describing the reason for the exception.
*/
public InvalidClassException(String reason) {
super(reason);
}
/** {@collect.stats}
* {@description.open}
* Constructs an InvalidClassException object.
* {@description.close}
*
* @param cname a String naming the invalid class.
* @param reason a String describing the reason for the exception.
*/
public InvalidClassException(String cname, String reason) {
super(reason);
classname = cname;
}
/** {@collect.stats}
* {@description.open}
* Produce the message and include the classname, if present.
* {@description.close}
*/
public String getMessage() {
if (classname == null)
return super.getMessage();
else
return classname + "; " + super.getMessage();
}
}
|
Java
|
/*
* Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* This class is an input stream filter that provides the added
* functionality of keeping track of the current line number.
* <p>
* A line is a sequence of bytes ending with a carriage return
* character (<code>'\r'</code>), a newline character
* (<code>'\n'</code>), or a carriage return character followed
* immediately by a linefeed character. In all three cases, the line
* terminating character(s) are returned as a single newline character.
* <p>
* The line number begins at <code>0</code>, and is incremented by
* <code>1</code> when a <code>read</code> returns a newline character.
* {@description.close}
*
* @author Arthur van Hoff
* @see java.io.LineNumberReader
* @since JDK1.0
* @deprecated This class incorrectly assumes that bytes adequately represent
* characters. As of JDK 1.1, the preferred way to operate on
* character streams is via the new character-stream classes, which
* include a class for counting line numbers.
*/
@Deprecated
public
class LineNumberInputStream extends FilterInputStream {
int pushBack = -1;
int lineNumber;
int markLineNumber;
int markPushBack = -1;
/** {@collect.stats}
* {@description.open}
* Constructs a newline number input stream that reads its input
* from the specified input stream.
* {@description.close}
*
* @param in the underlying input stream.
*/
public LineNumberInputStream(InputStream in) {
super(in);
}
/** {@collect.stats}
* {@description.open}
* Reads the next byte of data from this input stream. The value
* byte is returned as an <code>int</code> in the range
* <code>0</code> to <code>255</code>. If no byte is available
* because the end of the stream has been reached, the value
* <code>-1</code> is returned.
* {@description.close}
* {@description.open blocking}
* This method blocks until input data
* is available, the end of the stream is detected, or an exception
* is thrown.
* {@description.close}
* {@description.open}
* <p>
* The <code>read</code> method of
* <code>LineNumberInputStream</code> calls the <code>read</code>
* method of the underlying input stream. It checks for carriage
* returns and newline characters in the input, and modifies the
* current line number as appropriate. A carriage-return character or
* a carriage return followed by a newline character are both
* converted into a single newline character.
* {@description.close}
*
* @return the next byte of data, or <code>-1</code> if the end of this
* stream is reached.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
* @see java.io.LineNumberInputStream#getLineNumber()
*/
public int read() throws IOException {
int c = pushBack;
if (c != -1) {
pushBack = -1;
} else {
c = in.read();
}
switch (c) {
case '\r':
pushBack = in.read();
if (pushBack == '\n') {
pushBack = -1;
}
case '\n':
lineNumber++;
return '\n';
}
return c;
}
/** {@collect.stats}
* {@description.open}
* Reads up to <code>len</code> bytes of data from this input stream
* into an array of bytes.
* {@description.close}
* {@description.open blocking}
* This method blocks until some input is available.
* {@description.close}
* {@description.open}
* <p>
* The <code>read</code> method of
* <code>LineNumberInputStream</code> repeatedly calls the
* <code>read</code> method of zero arguments to fill in the byte array.
* {@description.close}
*
* @param b the buffer into which the data is read.
* @param off the start offset of the data.
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* this stream has been reached.
* @exception IOException if an I/O error occurs.
* @see java.io.LineNumberInputStream#read()
*/
public int read(byte b[], int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
int c = read();
if (c == -1) {
return -1;
}
b[off] = (byte)c;
int i = 1;
try {
for (; i < len ; i++) {
c = read();
if (c == -1) {
break;
}
if (b != null) {
b[off + i] = (byte)c;
}
}
} catch (IOException ee) {
}
return i;
}
/** {@collect.stats}
* {@description.open}
* Skips over and discards <code>n</code> bytes of data from this
* input stream. The <code>skip</code> method may, for a variety of
* reasons, end up skipping over some smaller number of bytes,
* possibly <code>0</code>. The actual number of bytes skipped is
* returned. If <code>n</code> is negative, no bytes are skipped.
* <p>
* The <code>skip</code> method of <code>LineNumberInputStream</code> creates
* a byte array and then repeatedly reads into it until
* <code>n</code> bytes have been read or the end of the stream has
* been reached.
* {@description.close}
*
* @param n the number of bytes to be skipped.
* @return the actual number of bytes skipped.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public long skip(long n) throws IOException {
int chunk = 2048;
long remaining = n;
byte data[];
int nr;
if (n <= 0) {
return 0;
}
data = new byte[chunk];
while (remaining > 0) {
nr = read(data, 0, (int) Math.min(chunk, remaining));
if (nr < 0) {
break;
}
remaining -= nr;
}
return n - remaining;
}
/** {@collect.stats}
* {@description.open}
* Sets the line number to the specified argument.
* {@description.close}
*
* @param lineNumber the new line number.
* @see #getLineNumber
*/
public void setLineNumber(int lineNumber) {
this.lineNumber = lineNumber;
}
/** {@collect.stats}
* {@description.open}
* Returns the current line number.
* {@description.close}
*
* @return the current line number.
* @see #setLineNumber
*/
public int getLineNumber() {
return lineNumber;
}
/** {@collect.stats}
* {@description.open}
* Returns the number of bytes that can be read from this input
* stream without blocking.
* {@description.close}
* {@property.open}
* <p>
* Note that if the underlying input stream is able to supply
* <i>k</i> input characters without blocking, the
* <code>LineNumberInputStream</code> can guarantee only to provide
* <i>k</i>/2 characters without blocking, because the
* <i>k</i> characters from the underlying input stream might
* consist of <i>k</i>/2 pairs of <code>'\r'</code> and
* <code>'\n'</code>, which are converted to just
* <i>k</i>/2 <code>'\n'</code> characters.
* {@property.close}
*
* @return the number of bytes that can be read from this input stream
* without blocking.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public int available() throws IOException {
return (pushBack == -1) ? super.available()/2 : super.available()/2 + 1;
}
/** {@collect.stats}
* {@description.open}
* Marks the current position in this input stream.
* {@description.close}
* {@property.open runtime formal:java.io.InputStream_MarkReset}
* A subsequent
* call to the <code>reset</code> method repositions this stream at
* the last marked position so that subsequent reads re-read the same bytes.
* {@property.close}
* {@description.open}
* <p>
* The <code>mark</code> method of
* <code>LineNumberInputStream</code> remembers the current line
* number in a private variable, and then calls the <code>mark</code>
* method of the underlying input stream.
* {@description.close}
*
* @param readlimit the maximum limit of bytes that can be read before
* the mark position becomes invalid.
* @see java.io.FilterInputStream#in
* @see java.io.LineNumberInputStream#reset()
*/
public void mark(int readlimit) {
markLineNumber = lineNumber;
markPushBack = pushBack;
in.mark(readlimit);
}
/** {@collect.stats}
* {@description.open}
* Repositions this stream to the position at the time the
* <code>mark</code> method was last called on this input stream.
* <p>
* The <code>reset</code> method of
* <code>LineNumberInputStream</code> resets the line number to be
* the line number at the time the <code>mark</code> method was
* called, and then calls the <code>reset</code> method of the
* underlying input stream.
* <p>
* Stream marks are intended to be used in
* situations where you need to read ahead a little to see what's in
* the stream. Often this is most easily done by invoking some
* general parser. If the stream is of the type handled by the
* parser, it just chugs along happily. If the stream is not of
* that type, the parser should toss an exception when it fails,
* which, if it happens within readlimit bytes, allows the outer
* code to reset the stream and try another parser.
* {@description.close}
*
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
* @see java.io.LineNumberInputStream#mark(int)
*/
public void reset() throws IOException {
lineNumber = markLineNumber;
pushBack = markPushBack;
in.reset();
}
}
|
Java
|
/*
* Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.io.*;
/** {@collect.stats}
* {@description.open}
* A piped output stream can be connected to a piped input stream
* to create a communications pipe. The piped output stream is the
* sending end of the pipe. Typically, data is written to a
* <code>PipedOutputStream</code> object by one thread and data is
* read from the connected <code>PipedInputStream</code> by some
* other thread.
* {@description.close}
* {@property.open runtime formal:java.io.PipedStream_SingleThread}
* Attempting to use both objects from a single thread
* is not recommended as it may deadlock the thread.
* {@property.close}
* {@description.open}
* The pipe is said to be <a name=BROKEN> <i>broken</i> </a> if a
* thread that was reading data bytes from the connected piped input
* stream is no longer alive.
* {@description.close}
*
* @author James Gosling
* @see java.io.PipedInputStream
* @since JDK1.0
*/
public
class PipedOutputStream extends OutputStream {
/* REMIND: identification of the read and write sides needs to be
more sophisticated. Either using thread groups (but what about
pipes within a thread?) or using finalization (but it may be a
long time until the next GC). */
private PipedInputStream sink;
/** {@collect.stats}
* {@description.open}
* Creates a piped output stream connected to the specified piped
* input stream. Data bytes written to this stream will then be
* available as input from <code>snk</code>.
* {@description.close}
*
* @param snk The piped input stream to connect to.
* @exception IOException if an I/O error occurs.
*/
public PipedOutputStream(PipedInputStream snk) throws IOException {
connect(snk);
}
/** {@collect.stats}
* {@description.open}
* Creates a piped output stream that is not yet connected to a
* piped input stream. It must be connected to a piped input stream,
* either by the receiver or the sender, before being used.
* {@description.close}
*
* @see java.io.PipedInputStream#connect(java.io.PipedOutputStream)
* @see java.io.PipedOutputStream#connect(java.io.PipedInputStream)
*/
public PipedOutputStream() {
}
/** {@collect.stats}
* {@description.open}
* Connects this piped output stream to a receiver. If this object
* is already connected to some other piped input stream, an
* <code>IOException</code> is thrown.
* <p>
* If <code>snk</code> is an unconnected piped input stream and
* <code>src</code> is an unconnected piped output stream, they may
* be connected by either the call:
* <blockquote><pre>
* src.connect(snk)</pre></blockquote>
* or the call:
* <blockquote><pre>
* snk.connect(src)</pre></blockquote>
* The two calls have the same effect.
* {@description.close}
*
* @param snk the piped input stream to connect to.
* @exception IOException if an I/O error occurs.
*/
public synchronized void connect(PipedInputStream snk) throws IOException {
if (snk == null) {
throw new NullPointerException();
} else if (sink != null || snk.connected) {
throw new IOException("Already connected");
}
sink = snk;
snk.in = -1;
snk.out = 0;
snk.connected = true;
}
/** {@collect.stats}
* {@description.open}
* Writes the specified <code>byte</code> to the piped output stream.
* <p>
* Implements the <code>write</code> method of <code>OutputStream</code>.
* {@description.close}
*
* @param b the <code>byte</code> to be written.
* @exception IOException if the pipe is <a href=#BROKEN> broken</a>,
* {@link #connect(java.io.PipedInputStream) unconnected},
* closed, or if an I/O error occurs.
*/
public void write(int b) throws IOException {
if (sink == null) {
throw new IOException("Pipe not connected");
}
sink.receive(b);
}
/** {@collect.stats}
* {@description.open}
* Writes <code>len</code> bytes from the specified byte array
* starting at offset <code>off</code> to this piped output stream.
* {@description.close}
* {@description.open blocking}
* This method blocks until all the bytes are written to the output
* stream.
* {@description.close}
*
* @param b the data.
* @param off the start offset in the data.
* @param len the number of bytes to write.
* @exception IOException if the pipe is <a href=#BROKEN> broken</a>,
* {@link #connect(java.io.PipedInputStream) unconnected},
* closed, or if an I/O error occurs.
*/
public void write(byte b[], int off, int len) throws IOException {
if (sink == null) {
throw new IOException("Pipe not connected");
} else if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
sink.receive(b, off, len);
}
/** {@collect.stats}
* {@description.open}
* Flushes this output stream and forces any buffered output bytes
* to be written out.
* This will notify any readers that bytes are waiting in the pipe.
* {@description.close}
*
* @exception IOException if an I/O error occurs.
*/
public synchronized void flush() throws IOException {
if (sink != null) {
synchronized (sink) {
sink.notifyAll();
}
}
}
/** {@collect.stats}
* {@description.open}
* Closes this piped output stream and releases any system resources
* associated with this stream.
* {@description.close}
* {@property.open runtime formal:java.io.OutputStream_ManipulateAfterClose}
* This stream may no longer be used for
* writing bytes.
* {@property.close}
*
* @exception IOException if an I/O error occurs.
*/
public void close() throws IOException {
if (sink != null) {
sink.receivedLast();
}
}
}
|
Java
|
/*
* Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* A character stream that collects its output in a string buffer, which can
* then be used to construct a string.
* <p>
* {@description.close}
* {@property.open runtime formal:java.io.Closeable_MeaninglessClose}
* Closing a <tt>StringWriter</tt> has no effect. The methods in this class
* can be called after the stream has been closed without generating an
* <tt>IOException</tt>.
* {@property.close}
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class StringWriter extends Writer {
private StringBuffer buf;
/** {@collect.stats}
* {@description.open}
* Create a new string writer using the default initial string-buffer
* size.
* {@description.close}
*/
public StringWriter() {
buf = new StringBuffer();
lock = buf;
}
/** {@collect.stats}
* {@description.open}
* Create a new string writer using the specified initial string-buffer
* size.
* {@description.close}
*
* @param initialSize
* The number of <tt>char</tt> values that will fit into this buffer
* before it is automatically expanded
*
* @throws IllegalArgumentException
* If <tt>initialSize</tt> is negative
*/
public StringWriter(int initialSize) {
if (initialSize < 0) {
throw new IllegalArgumentException("Negative buffer size");
}
buf = new StringBuffer(initialSize);
lock = buf;
}
/** {@collect.stats}
* {@description.open}
* Write a single character.
* {@description.close}
*/
public void write(int c) {
buf.append((char) c);
}
/** {@collect.stats}
* {@description.open}
* Write a portion of an array of characters.
* {@description.close}
*
* @param cbuf Array of characters
* @param off Offset from which to start writing characters
* @param len Number of characters to write
*/
public void write(char cbuf[], int off, int len) {
if ((off < 0) || (off > cbuf.length) || (len < 0) ||
((off + len) > cbuf.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
buf.append(cbuf, off, len);
}
/** {@collect.stats}
* {@description.open}
* Write a string.
* {@description.close}
*/
public void write(String str) {
buf.append(str);
}
/** {@collect.stats}
* {@description.open}
* Write a portion of a string.
* {@description.close}
*
* @param str String to be written
* @param off Offset from which to start writing characters
* @param len Number of characters to write
*/
public void write(String str, int off, int len) {
buf.append(str.substring(off, off + len));
}
/** {@collect.stats}
* {@description.open}
* Appends the specified character sequence to this writer.
*
* <p> An invocation of this method of the form <tt>out.append(csq)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* out.write(csq.toString()) </pre>
*
* <p> Depending on the specification of <tt>toString</tt> for the
* character sequence <tt>csq</tt>, the entire sequence may not be
* appended. For instance, invoking the <tt>toString</tt> method of a
* character buffer will return a subsequence whose content depends upon
* the buffer's position and limit.
* {@description.close}
*
* @param csq
* The character sequence to append. If <tt>csq</tt> is
* <tt>null</tt>, then the four characters <tt>"null"</tt> are
* appended to this writer.
*
* @return This writer
*
* @since 1.5
*/
public StringWriter append(CharSequence csq) {
if (csq == null)
write("null");
else
write(csq.toString());
return this;
}
/** {@collect.stats}
* {@description.open}
* Appends a subsequence of the specified character sequence to this writer.
*
* <p> An invocation of this method of the form <tt>out.append(csq, start,
* end)</tt> when <tt>csq</tt> is not <tt>null</tt>, behaves in
* exactly the same way as the invocation
*
* <pre>
* out.write(csq.subSequence(start, end).toString()) </pre>
* {@description.close}
*
* @param csq
* The character sequence from which a subsequence will be
* appended. If <tt>csq</tt> is <tt>null</tt>, then characters
* will be appended as if <tt>csq</tt> contained the four
* characters <tt>"null"</tt>.
*
* @param start
* The index of the first character in the subsequence
*
* @param end
* The index of the character following the last character in the
* subsequence
*
* @return This writer
*
* @throws IndexOutOfBoundsException
* If <tt>start</tt> or <tt>end</tt> are negative, <tt>start</tt>
* is greater than <tt>end</tt>, or <tt>end</tt> is greater than
* <tt>csq.length()</tt>
*
* @since 1.5
*/
public StringWriter append(CharSequence csq, int start, int end) {
CharSequence cs = (csq == null ? "null" : csq);
write(cs.subSequence(start, end).toString());
return this;
}
/** {@collect.stats}
* {@description.open}
* Appends the specified character to this writer.
*
* <p> An invocation of this method of the form <tt>out.append(c)</tt>
* behaves in exactly the same way as the invocation
*
* <pre>
* out.write(c) </pre>
* {@description.close}
*
* @param c
* The 16-bit character to append
*
* @return This writer
*
* @since 1.5
*/
public StringWriter append(char c) {
write(c);
return this;
}
/** {@collect.stats}
* {@description.open}
* Return the buffer's current value as a string.
* {@description.close}
*/
public String toString() {
return buf.toString();
}
/** {@collect.stats}
* {@description.open}
* Return the string buffer itself.
* {@description.close}
*
* @return StringBuffer holding the current buffer value.
*/
public StringBuffer getBuffer() {
return buf;
}
/** {@collect.stats}
* {@description.open}
* Flush the stream.
* {@description.close}
*/
public void flush() {
}
/** {@collect.stats}
* {@property.open runtime formal:java.io.Closeable_MeaninglessClose}
* Closing a <tt>StringWriter</tt> has no effect. The methods in this
* class can be called after the stream has been closed without generating
* an <tt>IOException</tt>.
* {@property.close}
*/
public void close() throws IOException {
}
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Reads text from a character-input stream, buffering characters so as to
* provide for the efficient reading of characters, arrays, and lines.
*
* <p> The buffer size may be specified, or the default size may be used. The
* default is large enough for most purposes.
*
* <p> In general, each read request made of a Reader causes a corresponding
* read request to be made of the underlying character or byte stream. It is
* therefore advisable to wrap a BufferedReader around any Reader whose read()
* operations may be costly, such as FileReaders and InputStreamReaders. For
* example,
*
* <pre>
* BufferedReader in
* = new BufferedReader(new FileReader("foo.in"));
* </pre>
*
* will buffer the input from the specified file. Without buffering, each
* invocation of read() or readLine() could cause bytes to be read from the
* file, converted into characters, and then returned, which can be very
* inefficient.
*
* <p> Programs that use DataInputStreams for textual input can be localized by
* replacing each DataInputStream with an appropriate BufferedReader.
* {@description.close}
*
* @see FileReader
* @see InputStreamReader
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class BufferedReader extends Reader {
private Reader in;
private char cb[];
private int nChars, nextChar;
private static final int INVALIDATED = -2;
private static final int UNMARKED = -1;
private int markedChar = UNMARKED;
private int readAheadLimit = 0; /* Valid only when markedChar > 0 */
/** {@collect.stats}
* {@description.open}
* If the next character is a line feed, skip it
* {@description.close}
*/
private boolean skipLF = false;
/** {@collect.stats}
* {@description.open}
* The skipLF flag when the mark was set
* {@description.close}
*/
private boolean markedSkipLF = false;
private static int defaultCharBufferSize = 8192;
private static int defaultExpectedLineLength = 80;
/** {@collect.stats}
* {@description.open}
* Creates a buffering character-input stream that uses an input buffer of
* the specified size.
* {@description.close}
*
* @param in A Reader
* @param sz Input-buffer size
*
* @exception IllegalArgumentException If sz is <= 0
*/
public BufferedReader(Reader in, int sz) {
super(in);
if (sz <= 0)
throw new IllegalArgumentException("Buffer size <= 0");
this.in = in;
cb = new char[sz];
nextChar = nChars = 0;
}
/** {@collect.stats}
* {@description.open}
* Creates a buffering character-input stream that uses a default-sized
* input buffer.
* {@description.close}
*
* @param in A Reader
*/
public BufferedReader(Reader in) {
this(in, defaultCharBufferSize);
}
/** {@collect.stats}
* {@description.open}
* Checks to make sure that the stream has not been closed
* {@description.close}
*/
private void ensureOpen() throws IOException {
if (in == null)
throw new IOException("Stream closed");
}
/** {@collect.stats}
* {@description.open}
* Fills the input buffer, taking the mark into account if it is valid.
* {@description.close}
*/
private void fill() throws IOException {
int dst;
if (markedChar <= UNMARKED) {
/* No mark */
dst = 0;
} else {
/* Marked */
int delta = nextChar - markedChar;
if (delta >= readAheadLimit) {
/* Gone past read-ahead limit: Invalidate mark */
markedChar = INVALIDATED;
readAheadLimit = 0;
dst = 0;
} else {
if (readAheadLimit <= cb.length) {
/* Shuffle in the current buffer */
System.arraycopy(cb, markedChar, cb, 0, delta);
markedChar = 0;
dst = delta;
} else {
/* Reallocate buffer to accommodate read-ahead limit */
char ncb[] = new char[readAheadLimit];
System.arraycopy(cb, markedChar, ncb, 0, delta);
cb = ncb;
markedChar = 0;
dst = delta;
}
nextChar = nChars = delta;
}
}
int n;
do {
n = in.read(cb, dst, cb.length - dst);
} while (n == 0);
if (n > 0) {
nChars = dst + n;
nextChar = dst;
}
}
/** {@collect.stats}
* {@description.open}
* Reads a single character.
* {@description.close}
*
* @return The character read, as an integer in the range
* 0 to 65535 (<tt>0x00-0xffff</tt>), or -1 if the
* end of the stream has been reached
* @exception IOException If an I/O error occurs
*/
public int read() throws IOException {
synchronized (lock) {
ensureOpen();
for (;;) {
if (nextChar >= nChars) {
fill();
if (nextChar >= nChars)
return -1;
}
if (skipLF) {
skipLF = false;
if (cb[nextChar] == '\n') {
nextChar++;
continue;
}
}
return cb[nextChar++];
}
}
}
/** {@collect.stats}
* {@description.open}
* Reads characters into a portion of an array, reading from the underlying
* stream if necessary.
* {@description.close}
*/
private int read1(char[] cbuf, int off, int len) throws IOException {
if (nextChar >= nChars) {
/* If the requested length is at least as large as the buffer, and
if there is no mark/reset activity, and if line feeds are not
being skipped, do not bother to copy the characters into the
local buffer. In this way buffered streams will cascade
harmlessly. */
if (len >= cb.length && markedChar <= UNMARKED && !skipLF) {
return in.read(cbuf, off, len);
}
fill();
}
if (nextChar >= nChars) return -1;
if (skipLF) {
skipLF = false;
if (cb[nextChar] == '\n') {
nextChar++;
if (nextChar >= nChars)
fill();
if (nextChar >= nChars)
return -1;
}
}
int n = Math.min(len, nChars - nextChar);
System.arraycopy(cb, nextChar, cbuf, off, n);
nextChar += n;
return n;
}
/** {@collect.stats}
* {@description.open}
* Reads characters into a portion of an array.
*
* <p> This method implements the general contract of the corresponding
* <code>{@link Reader#read(char[], int, int) read}</code> method of the
* <code>{@link Reader}</code> class. As an additional convenience, it
* attempts to read as many characters as possible by repeatedly invoking
* the <code>read</code> method of the underlying stream. This iterated
* <code>read</code> continues until one of the following conditions becomes
* true: <ul>
*
* <li> The specified number of characters have been read,
*
* <li> The <code>read</code> method of the underlying stream returns
* <code>-1</code>, indicating end-of-file, or
*
* <li> The <code>ready</code> method of the underlying stream
* returns <code>false</code>, indicating that further input requests
* would block.
*
* </ul> If the first <code>read</code> on the underlying stream returns
* <code>-1</code> to indicate end-of-file then this method returns
* <code>-1</code>. Otherwise this method returns the number of characters
* actually read.
*
* <p> Subclasses of this class are encouraged, but not required, to
* attempt to read as many characters as possible in the same fashion.
*
* <p> Ordinarily this method takes characters from this stream's character
* buffer, filling it from the underlying stream as necessary. If,
* however, the buffer is empty, the mark is not valid, and the requested
* length is at least as large as the buffer, then this method will read
* characters directly from the underlying stream into the given array.
* Thus redundant <code>BufferedReader</code>s will not copy data
* unnecessarily.
* {@description.close}
*
* @param cbuf Destination buffer
* @param off Offset at which to start storing characters
* @param len Maximum number of characters to read
*
* @return The number of characters read, or -1 if the end of the
* stream has been reached
*
* @exception IOException If an I/O error occurs
*/
public int read(char cbuf[], int off, int len) throws IOException {
synchronized (lock) {
ensureOpen();
if ((off < 0) || (off > cbuf.length) || (len < 0) ||
((off + len) > cbuf.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
int n = read1(cbuf, off, len);
if (n <= 0) return n;
while ((n < len) && in.ready()) {
int n1 = read1(cbuf, off + n, len - n);
if (n1 <= 0) break;
n += n1;
}
return n;
}
}
/** {@collect.stats}
* {@description.open}
* Reads a line of text. A line is considered to be terminated by any one
* of a line feed ('\n'), a carriage return ('\r'), or a carriage return
* followed immediately by a linefeed.
* {@description.close}
*
* @param ignoreLF If true, the next '\n' will be skipped
*
* @return A String containing the contents of the line, not including
* any line-termination characters, or null if the end of the
* stream has been reached
*
* @see java.io.LineNumberReader#readLine()
*
* @exception IOException If an I/O error occurs
*/
String readLine(boolean ignoreLF) throws IOException {
StringBuffer s = null;
int startChar;
synchronized (lock) {
ensureOpen();
boolean omitLF = ignoreLF || skipLF;
bufferLoop:
for (;;) {
if (nextChar >= nChars)
fill();
if (nextChar >= nChars) { /* EOF */
if (s != null && s.length() > 0)
return s.toString();
else
return null;
}
boolean eol = false;
char c = 0;
int i;
/* Skip a leftover '\n', if necessary */
if (omitLF && (cb[nextChar] == '\n'))
nextChar++;
skipLF = false;
omitLF = false;
charLoop:
for (i = nextChar; i < nChars; i++) {
c = cb[i];
if ((c == '\n') || (c == '\r')) {
eol = true;
break charLoop;
}
}
startChar = nextChar;
nextChar = i;
if (eol) {
String str;
if (s == null) {
str = new String(cb, startChar, i - startChar);
} else {
s.append(cb, startChar, i - startChar);
str = s.toString();
}
nextChar++;
if (c == '\r') {
skipLF = true;
}
return str;
}
if (s == null)
s = new StringBuffer(defaultExpectedLineLength);
s.append(cb, startChar, i - startChar);
}
}
}
/** {@collect.stats}
* {@description.open}
* Reads a line of text. A line is considered to be terminated by any one
* of a line feed ('\n'), a carriage return ('\r'), or a carriage return
* followed immediately by a linefeed.
* {@description.close}
*
* @return A String containing the contents of the line, not including
* any line-termination characters, or null if the end of the
* stream has been reached
*
* @exception IOException If an I/O error occurs
*/
public String readLine() throws IOException {
return readLine(false);
}
/** {@collect.stats}
* {@description.open}
* Skips characters.
* {@description.close}
*
* @param n The number of characters to skip
*
* @return The number of characters actually skipped
*
* @exception IllegalArgumentException If <code>n</code> is negative.
* @exception IOException If an I/O error occurs
*/
public long skip(long n) throws IOException {
if (n < 0L) {
throw new IllegalArgumentException("skip value is negative");
}
synchronized (lock) {
ensureOpen();
long r = n;
while (r > 0) {
if (nextChar >= nChars)
fill();
if (nextChar >= nChars) /* EOF */
break;
if (skipLF) {
skipLF = false;
if (cb[nextChar] == '\n') {
nextChar++;
}
}
long d = nChars - nextChar;
if (r <= d) {
nextChar += r;
r = 0;
break;
}
else {
r -= d;
nextChar = nChars;
}
}
return n - r;
}
}
/** {@collect.stats}
* {@description.open}
* Tells whether this stream is ready to be read. A buffered character
* stream is ready if the buffer is not empty, or if the underlying
* character stream is ready.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public boolean ready() throws IOException {
synchronized (lock) {
ensureOpen();
/*
* If newline needs to be skipped and the next char to be read
* is a newline character, then just skip it right away.
*/
if (skipLF) {
/* Note that in.ready() will return true if and only if the next
* read on the stream will not block.
*/
if (nextChar >= nChars && in.ready()) {
fill();
}
if (nextChar < nChars) {
if (cb[nextChar] == '\n')
nextChar++;
skipLF = false;
}
}
return (nextChar < nChars) || in.ready();
}
}
/** {@collect.stats}
* {@property.open runtime formal:java.io.Reader_MarkReset}
* Tells whether this stream supports the mark() operation, which it does.
* {@property.close}
*/
public boolean markSupported() {
return true;
}
/** {@collect.stats}
* {@description.open}
* Marks the present position in the stream. Subsequent calls to reset()
* will attempt to reposition the stream to this point.
* {@description.close}
* {@property.open runtime formal:java.io.Reader_MarkReset formal:java.io.Reader_UnmarkedReset formal:java.io.Reader_ReadAheadLimit}
* {@property.close}
*
* @param readAheadLimit Limit on the number of characters that may be
* read while still preserving the mark. An attempt
* to reset the stream after reading characters
* up to this limit or beyond may fail.
* A limit value larger than the size of the input
* buffer will cause a new buffer to be allocated
* whose size is no smaller than limit.
* Therefore large values should be used with care.
*
* @exception IllegalArgumentException If readAheadLimit is < 0
* @exception IOException If an I/O error occurs
*/
public void mark(int readAheadLimit) throws IOException {
if (readAheadLimit < 0) {
throw new IllegalArgumentException("Read-ahead limit < 0");
}
synchronized (lock) {
ensureOpen();
this.readAheadLimit = readAheadLimit;
markedChar = nextChar;
markedSkipLF = skipLF;
}
}
/** {@collect.stats}
* {@description.open}
* Resets the stream to the most recent mark.
* {@description.close}
* {@property.open runtime formal:java.io.Reader_MarkReset formal:java.io.Reader_UnmarkedReset formal:java.io.Reader_ReadAheadLimit}
* {@property.close}
*
* @exception IOException If the stream has never been marked,
* or if the mark has been invalidated
*/
public void reset() throws IOException {
synchronized (lock) {
ensureOpen();
if (markedChar < 0)
throw new IOException((markedChar == INVALIDATED)
? "Mark invalid"
: "Stream not marked");
nextChar = markedChar;
skipLF = markedSkipLF;
}
}
public void close() throws IOException {
synchronized (lock) {
if (in == null)
return;
in.close();
in = null;
cb = null;
}
}
}
|
Java
|
/*
* Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Signals that a sync operation has failed.
* {@description.close}
*
* @author Ken Arnold
* @see java.io.FileDescriptor#sync
* @see java.io.IOException
* @since JDK1.1
*/
public class SyncFailedException extends IOException {
/** {@collect.stats}
* {@description.open}
* Constructs an SyncFailedException with a detail message.
* A detail message is a String that describes this particular exception.
* {@description.close}
*
* @param desc a String describing the exception.
*/
public SyncFailedException(String desc) {
super(desc);
}
}
|
Java
|
/*
* Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* A <code>PushbackInputStream</code> adds
* functionality to another input stream, namely
* the ability to "push back" or "unread"
* one byte. This is useful in situations where
* it is convenient for a fragment of code
* to read an indefinite number of data bytes
* that are delimited by a particular byte
* value; after reading the terminating byte,
* the code fragment can "unread" it, so that
* the next read operation on the input stream
* will reread the byte that was pushed back.
* For example, bytes representing the characters
* constituting an identifier might be terminated
* by a byte representing an operator character;
* a method whose job is to read just an identifier
* can read until it sees the operator and
* then push the operator back to be re-read.
* {@description.close}
*
* @author David Connelly
* @author Jonathan Payne
* @since JDK1.0
*/
public
class PushbackInputStream extends FilterInputStream {
/** {@collect.stats}
* {@description.open}
* The pushback buffer.
* {@description.close}
* @since JDK1.1
*/
protected byte[] buf;
/** {@collect.stats}
* {@description.open}
* The position within the pushback buffer from which the next byte will
* be read. When the buffer is empty, <code>pos</code> is equal to
* <code>buf.length</code>; when the buffer is full, <code>pos</code> is
* equal to zero.
* {@description.close}
*
* @since JDK1.1
*/
protected int pos;
/** {@collect.stats}
* {@description.open}
* Check to make sure that this stream has not been closed
* {@description.close}
*/
private void ensureOpen() throws IOException {
if (in == null)
throw new IOException("Stream closed");
}
/** {@collect.stats}
* {@description.open}
* Creates a <code>PushbackInputStream</code>
* with a pushback buffer of the specified <code>size</code>,
* and saves its argument, the input stream
* <code>in</code>, for later use. Initially,
* there is no pushed-back byte (the field
* <code>pushBack</code> is initialized to
* <code>-1</code>).
* {@description.close}
*
* @param in the input stream from which bytes will be read.
* @param size the size of the pushback buffer.
* @exception IllegalArgumentException if size is <= 0
* @since JDK1.1
*/
public PushbackInputStream(InputStream in, int size) {
super(in);
if (size <= 0) {
throw new IllegalArgumentException("size <= 0");
}
this.buf = new byte[size];
this.pos = size;
}
/** {@collect.stats}
* {@description.open}
* Creates a <code>PushbackInputStream</code>
* and saves its argument, the input stream
* <code>in</code>, for later use. Initially,
* there is no pushed-back byte (the field
* <code>pushBack</code> is initialized to
* <code>-1</code>).
* {@new.open}
* This constructor creates the pushback buffer that holds only one byte.
* {@new.close}
* {@description.close}
*
* @param in the input stream from which bytes will be read.
*/
public PushbackInputStream(InputStream in) {
this(in, 1);
}
/** {@collect.stats}
* {@description.open}
* Reads the next byte of data from this input stream. The value
* byte is returned as an <code>int</code> in the range
* <code>0</code> to <code>255</code>. If no byte is available
* because the end of the stream has been reached, the value
* <code>-1</code> is returned.
* {@description.close}
* {@description.open blocking}
* This method blocks until input data
* is available, the end of the stream is detected, or an exception
* is thrown.
* {@description.close}
*
* {@description.open}
* <p> This method returns the most recently pushed-back byte, if there is
* one, and otherwise calls the <code>read</code> method of its underlying
* input stream and returns whatever value that method returns.
* {@description.close}
*
* @return the next byte of data, or <code>-1</code> if the end of the
* stream has been reached.
* @exception IOException if this input stream has been closed by
* invoking its {@link #close()} method,
* or an I/O error occurs.
* @see java.io.InputStream#read()
*/
public int read() throws IOException {
ensureOpen();
if (pos < buf.length) {
return buf[pos++] & 0xff;
}
return super.read();
}
/** {@collect.stats}
* {@description.open}
* Reads up to <code>len</code> bytes of data from this input stream into
* an array of bytes. This method first reads any pushed-back bytes; after
* that, if fewer than <code>len</code> bytes have been read then it
* reads from the underlying input stream.
* {@description.close}
* {@description.open blocking}
* If <code>len</code> is not zero, the method
* blocks until at least 1 byte of input is available; otherwise, no
* bytes are read and <code>0</code> is returned.
* {@description.close}
*
* @param b the buffer into which the data is read.
* @param off the start offset in the destination array <code>b</code>
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the stream has been reached.
* @exception NullPointerException If <code>b</code> is <code>null</code>.
* @exception IndexOutOfBoundsException If <code>off</code> is negative,
* <code>len</code> is negative, or <code>len</code> is greater than
* <code>b.length - off</code>
* @exception IOException if this input stream has been closed by
* invoking its {@link #close()} method,
* or an I/O error occurs.
* @see java.io.InputStream#read(byte[], int, int)
*/
public int read(byte[] b, int off, int len) throws IOException {
ensureOpen();
if (b == null) {
throw new NullPointerException();
} else if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
int avail = buf.length - pos;
if (avail > 0) {
if (len < avail) {
avail = len;
}
System.arraycopy(buf, pos, b, off, avail);
pos += avail;
off += avail;
len -= avail;
}
if (len > 0) {
len = super.read(b, off, len);
if (len == -1) {
return avail == 0 ? -1 : avail;
}
return avail + len;
}
return avail;
}
/** {@collect.stats}
* {@description.open}
* Pushes back a byte by copying it to the front of the pushback buffer.
* After this method returns, the next byte to be read will have the value
* <code>(byte)b</code>.
* {@description.close}
* {@property.open runtime formal:java.io.PushbackInputStream_UnreadAheadLimit}
* {@new.open}
* If the finite size of the internal pushback buffer is full, unread()
* raises a runtime exception. The buffer size is specified when a
* PushbackInputStream object is created.
* {@new.close}
* {@property.close}
*
* @param b the <code>int</code> value whose low-order
* byte is to be pushed back.
* @exception IOException If there is not enough room in the pushback
* buffer for the byte, or this input stream has been closed by
* invoking its {@link #close()} method.
*/
public void unread(int b) throws IOException {
ensureOpen();
if (pos == 0) {
throw new IOException("Push back buffer is full");
}
buf[--pos] = (byte)b;
}
/** {@collect.stats}
* {@description.open}
* Pushes back a portion of an array of bytes by copying it to the front
* of the pushback buffer. After this method returns, the next byte to be
* read will have the value <code>b[off]</code>, the byte after that will
* have the value <code>b[off+1]</code>, and so forth.
* {@description.close}
* {@property.open runtime formal:java.io.PushbackInputStream_UnreadAheadLimit}
* {@new.open}
* If the finite size of the internal pushback buffer is full, unread()
* raises a runtime exception. The buffer size is specified when a
* PushbackInputStream object is created.
* {@new.close}
* {@property.close}
*
* @param b the byte array to push back.
* @param off the start offset of the data.
* @param len the number of bytes to push back.
* @exception IOException If there is not enough room in the pushback
* buffer for the specified number of bytes,
* or this input stream has been closed by
* invoking its {@link #close()} method.
* @since JDK1.1
*/
public void unread(byte[] b, int off, int len) throws IOException {
ensureOpen();
if (len > pos) {
throw new IOException("Push back buffer is full");
}
pos -= len;
System.arraycopy(b, off, buf, pos, len);
}
/** {@collect.stats}
* {@description.open}
* Pushes back an array of bytes by copying it to the front of the
* pushback buffer. After this method returns, the next byte to be read
* will have the value <code>b[0]</code>, the byte after that will have the
* value <code>b[1]</code>, and so forth.
* {@description.close}
* {@property.open runtime formal:java.io.PushbackInputStream_UnreadAheadLimit}
* {@new.open}
* If the finite size of the internal pushback buffer is full, unread()
* raises a runtime exception. The buffer size is specified when a
* PushbackInputStream object is created.
* {@new.close}
* {@property.close}
*
* @param b the byte array to push back
* @exception IOException If there is not enough room in the pushback
* buffer for the specified number of bytes,
* or this input stream has been closed by
* invoking its {@link #close()} method.
* @since JDK1.1
*/
public void unread(byte[] b) throws IOException {
unread(b, 0, b.length);
}
/** {@collect.stats}
* {@description.open}
* Returns an estimate of the number of bytes that can be read (or
* skipped over) from this input stream without blocking by the next
* invocation of a method for this input stream. The next invocation might be
* the same thread or another thread. A single read or skip of this
* many bytes will not block, but may read or skip fewer bytes.
*
* <p> The method returns the sum of the number of bytes that have been
* pushed back and the value returned by {@link
* java.io.FilterInputStream#available available}.
* {@description.close}
*
* @return the number of bytes that can be read (or skipped over) from
* the input stream without blocking.
* @exception IOException if this input stream has been closed by
* invoking its {@link #close()} method,
* or an I/O error occurs.
* @see java.io.FilterInputStream#in
* @see java.io.InputStream#available()
*/
public int available() throws IOException {
ensureOpen();
return (buf.length - pos) + super.available();
}
/** {@collect.stats}
* {@description.open}
* Skips over and discards <code>n</code> bytes of data from this
* input stream. The <code>skip</code> method may, for a variety of
* reasons, end up skipping over some smaller number of bytes,
* possibly zero. If <code>n</code> is negative, no bytes are skipped.
*
* <p> The <code>skip</code> method of <code>PushbackInputStream</code>
* first skips over the bytes in the pushback buffer, if any. It then
* calls the <code>skip</code> method of the underlying input stream if
* more bytes need to be skipped. The actual number of bytes skipped
* is returned.
* {@description.close}
*
* @param n {@inheritDoc}
* @return {@inheritDoc}
* @exception IOException if the stream does not support seek,
* or the stream has been closed by
* invoking its {@link #close()} method,
* or an I/O error occurs.
* @see java.io.FilterInputStream#in
* @see java.io.InputStream#skip(long n)
* @since 1.2
*/
public long skip(long n) throws IOException {
ensureOpen();
if (n <= 0) {
return 0;
}
long pskip = buf.length - pos;
if (pskip > 0) {
if (n < pskip) {
pskip = n;
}
pos += pskip;
n -= pskip;
}
if (n > 0) {
pskip += super.skip(n);
}
return pskip;
}
/** {@collect.stats}
* {@description.open}
* Tests if this input stream supports the <code>mark</code> and
* <code>reset</code> methods, which it does not.
* {@description.close}
*
* @return <code>false</code>, since this class does not support the
* <code>mark</code> and <code>reset</code> methods.
* @see java.io.InputStream#mark(int)
* @see java.io.InputStream#reset()
*/
public boolean markSupported() {
return false;
}
/** {@collect.stats}
* {@description.open}
* Marks the current position in this input stream.
* {@description.close}
*
* {@property.open runtime formal:java.io.InputStream_MarkReset}
* <p> The <code>mark</code> method of <code>PushbackInputStream</code>
* does nothing.
* {@new.open}
* This method does not mark the current position; the first sentence is incorrect.
* {@new.close}
* {@property.close}
*
* @param readlimit the maximum limit of bytes that can be read before
* the mark position becomes invalid.
* @see java.io.InputStream#reset()
*/
public synchronized void mark(int readlimit) {
}
/** {@collect.stats}
* {@description.open}
* Repositions this stream to the position at the time the
* <code>mark</code> method was last called on this input stream.
* {@description.close}
*
* {@property.open runtime formal:java.io.InputStream_MarkReset}
* <p> The method <code>reset</code> for class
* <code>PushbackInputStream</code> does nothing except throw an
* <code>IOException</code>.
* {@property.close}
*
* @exception IOException if this method is invoked.
* @see java.io.InputStream#mark(int)
* @see java.io.IOException
*/
public synchronized void reset() throws IOException {
throw new IOException("mark/reset not supported");
}
/** {@collect.stats}
* {@description.open}
* Closes this input stream and releases any system resources
* associated with the stream.
* {@description.close}
* {@property.open runtime formal:java.io.InputStream_ManipulateAfterClose}
* Once the stream has been closed, further read(), unread(),
* available(), reset(), or skip() invocations will throw an IOException.
* {@property.close}
* {@property.open runtime formal:java.io.Closeable_MultipleClose}
* Closing a previously closed stream has no effect.
* {@property.close}
*
* @exception IOException if an I/O error occurs.
*/
public synchronized void close() throws IOException {
if (in == null)
return;
in.close();
in = null;
buf = null;
}
}
|
Java
|
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Thrown when a serious I/O error has occurred.
* {@description.close}
*
* @author Xueming Shen
* @since 1.6
*/
public class IOError extends Error {
/** {@collect.stats}
* {@description.open}
* Constructs a new instance of IOError with the specified cause. The
* IOError is created with the detail message of
* <tt>(cause==null ? null : cause.toString())</tt> (which typically
* contains the class and detail message of cause).
* {@description.close}
*
* @param cause
* The cause of this error, or <tt>null</tt> if the cause
* is not known
*/
public IOError(Throwable cause) {
super(cause);
}
private static final long serialVersionUID = 67100927991680413L;
}
|
Java
|
/*
* Copyright (c) 1995, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Signals that a malformed string in
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
* format has been read in a data
* input stream or by any class that implements the data input
* interface.
* See the
* <a href="DataInput.html#modified-utf-8"><code>DataInput</code></a>
* class description for the format in
* which modified UTF-8 strings are read and written.
* {@description.close}
*
* @author Frank Yellin
* @see java.io.DataInput
* @see java.io.DataInputStream#readUTF(java.io.DataInput)
* @see java.io.IOException
* @since JDK1.0
*/
public
class UTFDataFormatException extends IOException {
/** {@collect.stats}
* {@description.open}
* Constructs a <code>UTFDataFormatException</code> with
* <code>null</code> as its error detail message.
* {@description.close}
*/
public UTFDataFormatException() {
super();
}
/** {@collect.stats}
* {@description.open}
* Constructs a <code>UTFDataFormatException</code> with the
* specified detail message. The string <code>s</code> can be
* retrieved later by the
* <code>{@link java.lang.Throwable#getMessage}</code>
* method of class <code>java.lang.Throwable</code>.
* {@description.close}
*
* @param s the detail message.
*/
public UTFDataFormatException(String s) {
super(s);
}
}
|
Java
|
/*
* Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.io.ObjectStreamClass.WeakClassKey;
import java.lang.ref.ReferenceQueue;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import static java.io.ObjectStreamClass.processQueue;
import java.io.SerialCallbackContext;
/** {@collect.stats}
* {@description.open}
* An ObjectOutputStream writes primitive data types and graphs of Java objects
* to an OutputStream. The objects can be read (reconstituted) using an
* ObjectInputStream. Persistent storage of objects can be accomplished by
* using a file for the stream. If the stream is a network socket stream, the
* objects can be reconstituted on another host or in another process.
*
* <p>Only objects that support the java.io.Serializable interface can be
* written to streams. The class of each serializable object is encoded
* including the class name and signature of the class, the values of the
* object's fields and arrays, and the closure of any other objects referenced
* from the initial objects.
*
* <p>The method writeObject is used to write an object to the stream. Any
* object, including Strings and arrays, is written with writeObject. Multiple
* objects or primitives can be written to the stream. The objects must be
* read back from the corresponding ObjectInputstream with the same types and
* in the same order as they were written.
*
* <p>Primitive data types can also be written to the stream using the
* appropriate methods from DataOutput. Strings can also be written using the
* writeUTF method.
*
* <p>The default serialization mechanism for an object writes the class of the
* object, the class signature, and the values of all non-transient and
* non-static fields. References to other objects (except in transient or
* static fields) cause those objects to be written also. Multiple references
* to a single object are encoded using a reference sharing mechanism so that
* graphs of objects can be restored to the same shape as when the original was
* written.
*
* <p>For example to write an object that can be read by the example in
* ObjectInputStream:
* <br>
* <pre>
* FileOutputStream fos = new FileOutputStream("t.tmp");
* ObjectOutputStream oos = new ObjectOutputStream(fos);
*
* oos.writeInt(12345);
* oos.writeObject("Today");
* oos.writeObject(new Date());
*
* oos.close();
* </pre>
*
* <p>Classes that require special handling during the serialization and
* deserialization process must implement special methods with these exact
* signatures:
* <br>
* <pre>
* private void readObject(java.io.ObjectInputStream stream)
* throws IOException, ClassNotFoundException;
* private void writeObject(java.io.ObjectOutputStream stream)
* throws IOException
* private void readObjectNoData()
* throws ObjectStreamException;
* </pre>
*
* <p>The writeObject method is responsible for writing the state of the object
* for its particular class so that the corresponding readObject method can
* restore it. The method does not need to concern itself with the state
* belonging to the object's superclasses or subclasses. State is saved by
* writing the individual fields to the ObjectOutputStream using the
* writeObject method or by using the methods for primitive data types
* supported by DataOutput.
*
* <p>Serialization does not write out the fields of any object that does not
* implement the java.io.Serializable interface. Subclasses of Objects that
* are not serializable can be serializable. In this case the non-serializable
* class must have a no-arg constructor to allow its fields to be initialized.
* In this case it is the responsibility of the subclass to save and restore
* the state of the non-serializable class. It is frequently the case that the
* fields of that class are accessible (public, package, or protected) or that
* there are get and set methods that can be used to restore the state.
*
* <p>Serialization of an object can be prevented by implementing writeObject
* and readObject methods that throw the NotSerializableException. The
* exception will be caught by the ObjectOutputStream and abort the
* serialization process.
*
* <p>Implementing the Externalizable interface allows the object to assume
* complete control over the contents and format of the object's serialized
* form. The methods of the Externalizable interface, writeExternal and
* readExternal, are called to save and restore the objects state. When
* implemented by a class they can write and read their own state using all of
* the methods of ObjectOutput and ObjectInput. It is the responsibility of
* the objects to handle any versioning that occurs.
*
* <p>Enum constants are serialized differently than ordinary serializable or
* externalizable objects. The serialized form of an enum constant consists
* solely of its name; field values of the constant are not transmitted. To
* serialize an enum constant, ObjectOutputStream writes the string returned by
* the constant's name method. Like other serializable or externalizable
* objects, enum constants can function as the targets of back references
* appearing subsequently in the serialization stream. The process by which
* enum constants are serialized cannot be customized; any class-specific
* writeObject and writeReplace methods defined by enum types are ignored
* during serialization. Similarly, any serialPersistentFields or
* serialVersionUID field declarations are also ignored--all enum types have a
* fixed serialVersionUID of 0L.
*
* <p>Primitive data, excluding serializable fields and externalizable data, is
* written to the ObjectOutputStream in block-data records. A block data record
* is composed of a header and data. The block data header consists of a marker
* and the number of bytes to follow the header. Consecutive primitive data
* writes are merged into one block-data record. The blocking factor used for
* a block-data record will be 1024 bytes. Each block-data record will be
* filled up to 1024 bytes, or be written whenever there is a termination of
* block-data mode. Calls to the ObjectOutputStream methods writeObject,
* defaultWriteObject and writeFields initially terminate any existing
* block-data record.
* {@description.close}
*
* @author Mike Warres
* @author Roger Riggs
* @see java.io.DataOutput
* @see java.io.ObjectInputStream
* @see java.io.Serializable
* @see java.io.Externalizable
* @see <a href="../../../platform/serialization/spec/output.html">Object Serialization Specification, Section 2, Object Output Classes</a>
* @since JDK1.1
*/
public class ObjectOutputStream
extends OutputStream implements ObjectOutput, ObjectStreamConstants
{
private static class Caches {
/** {@collect.stats}
* {@description.open}
* cache of subclass security audit results
* {@description.close}
*/
static final ConcurrentMap<WeakClassKey,Boolean> subclassAudits =
new ConcurrentHashMap<WeakClassKey,Boolean>();
/** {@collect.stats}
* {@description.open}
* queue for WeakReferences to audited subclasses
* {@description.close}
*/
static final ReferenceQueue<Class<?>> subclassAuditsQueue =
new ReferenceQueue<Class<?>>();
}
/** {@collect.stats}
* {@description.open}
* filter stream for handling block data conversion
* {@description.close}
*/
private final BlockDataOutputStream bout;
/** {@collect.stats}
* {@description.open}
* obj -> wire handle map
* {@description.close}
*/
private final HandleTable handles;
/** {@collect.stats}
* {@description.open}
* obj -> replacement obj map
* {@description.close}
*/
private final ReplaceTable subs;
/** {@collect.stats}
* {@description.open}
* stream protocol version
* {@description.close}
*/
private int protocol = PROTOCOL_VERSION_2;
/** {@collect.stats}
* {@description.open}
* recursion depth
* {@description.close}
*/
private int depth;
/** {@collect.stats}
* {@description.open}
* buffer for writing primitive field values
* {@description.close}
*/
private byte[] primVals;
/** {@collect.stats}
* {@description.open}
* if true, invoke writeObjectOverride() instead of writeObject()
* {@description.close}
*/
private final boolean enableOverride;
/** {@collect.stats}
* {@description.open}
* if true, invoke replaceObject()
* {@description.close}
*/
private boolean enableReplace;
// values below valid only during upcalls to writeObject()/writeExternal()
/** {@collect.stats}
* {@description.open}
* Context during upcalls to class-defined writeObject methods; holds
* object currently being serialized and descriptor for current class.
* Null when not during writeObject upcall.
* {@description.close}
*/
private SerialCallbackContext curContext;
/** {@collect.stats}
* {@description.open}
* current PutField object
* {@description.close}
*/
private PutFieldImpl curPut;
/** {@collect.stats}
* {@description.open}
* custom storage for debug trace info
* {@description.close}
*/
private final DebugTraceInfoStack debugInfoStack;
/** {@collect.stats}
* {@description.open}
* value of "sun.io.serialization.extendedDebugInfo" property,
* as true or false for extended information about exception's place
* {@description.close}
*/
private static final boolean extendedDebugInfo =
java.security.AccessController.doPrivileged(
new sun.security.action.GetBooleanAction(
"sun.io.serialization.extendedDebugInfo")).booleanValue();
/** {@collect.stats}
* {@description.open}
* Creates an ObjectOutputStream that writes to the specified OutputStream.
* This constructor writes the serialization stream header to the
* underlying stream; callers may wish to flush the stream immediately to
* ensure that constructors for receiving ObjectInputStreams will not block
* when reading the header.
*
* <p>If a security manager is installed, this constructor will check for
* the "enableSubclassImplementation" SerializablePermission when invoked
* directly or indirectly by the constructor of a subclass which overrides
* the ObjectOutputStream.putFields or ObjectOutputStream.writeUnshared
* methods.
* {@description.close}
*
* @param out output stream to write to
* @throws IOException if an I/O error occurs while writing stream header
* @throws SecurityException if untrusted subclass illegally overrides
* security-sensitive methods
* @throws NullPointerException if <code>out</code> is <code>null</code>
* @since 1.4
* @see ObjectOutputStream#ObjectOutputStream()
* @see ObjectOutputStream#putFields()
* @see ObjectInputStream#ObjectInputStream(InputStream)
*/
public ObjectOutputStream(OutputStream out) throws IOException {
verifySubclass();
bout = new BlockDataOutputStream(out);
handles = new HandleTable(10, (float) 3.00);
subs = new ReplaceTable(10, (float) 3.00);
enableOverride = false;
writeStreamHeader();
bout.setBlockDataMode(true);
if (extendedDebugInfo) {
debugInfoStack = new DebugTraceInfoStack();
} else {
debugInfoStack = null;
}
}
/** {@collect.stats}
* {@description.open}
* Provide a way for subclasses that are completely reimplementing
* ObjectOutputStream to not have to allocate private data just used by
* this implementation of ObjectOutputStream.
*
* <p>If there is a security manager installed, this method first calls the
* security manager's <code>checkPermission</code> method with a
* <code>SerializablePermission("enableSubclassImplementation")</code>
* permission to ensure it's ok to enable subclassing.
* {@description.close}
*
* @throws SecurityException if a security manager exists and its
* <code>checkPermission</code> method denies enabling
* subclassing.
* @see SecurityManager#checkPermission
* @see java.io.SerializablePermission
*/
protected ObjectOutputStream() throws IOException, SecurityException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
}
bout = null;
handles = null;
subs = null;
enableOverride = true;
debugInfoStack = null;
}
/** {@collect.stats}
* {@description.open}
* Specify stream protocol version to use when writing the stream.
*
* <p>This routine provides a hook to enable the current version of
* Serialization to write in a format that is backwards compatible to a
* previous version of the stream format.
*
* <p>Every effort will be made to avoid introducing additional
* backwards incompatibilities; however, sometimes there is no
* other alternative.
* {@description.close}
*
* @param version use ProtocolVersion from java.io.ObjectStreamConstants.
* @throws IllegalStateException if called after any objects
* have been serialized.
* @throws IllegalArgumentException if invalid version is passed in.
* @throws IOException if I/O errors occur
* @see java.io.ObjectStreamConstants#PROTOCOL_VERSION_1
* @see java.io.ObjectStreamConstants#PROTOCOL_VERSION_2
* @since 1.2
*/
public void useProtocolVersion(int version) throws IOException {
if (handles.size() != 0) {
// REMIND: implement better check for pristine stream?
throw new IllegalStateException("stream non-empty");
}
switch (version) {
case PROTOCOL_VERSION_1:
case PROTOCOL_VERSION_2:
protocol = version;
break;
default:
throw new IllegalArgumentException(
"unknown version: " + version);
}
}
/** {@collect.stats}
* {@description.open}
* Write the specified object to the ObjectOutputStream. The class of the
* object, the signature of the class, and the values of the non-transient
* and non-static fields of the class and all of its supertypes are
* written. Default serialization for a class can be overridden using the
* writeObject and the readObject methods. Objects referenced by this
* object are written transitively so that a complete equivalent graph of
* objects can be reconstructed by an ObjectInputStream.
*
* <p>Exceptions are thrown for problems with the OutputStream and for
* classes that should not be serialized. All exceptions are fatal to the
* OutputStream, which is left in an indeterminate state, and it is up to
* the caller to ignore or recover the stream state.
* {@description.close}
*
* @throws InvalidClassException Something is wrong with a class used by
* serialization.
* @throws NotSerializableException Some object to be serialized does not
* implement the java.io.Serializable interface.
* @throws IOException Any exception thrown by the underlying
* OutputStream.
*/
public final void writeObject(Object obj) throws IOException {
if (enableOverride) {
writeObjectOverride(obj);
return;
}
try {
writeObject0(obj, false);
} catch (IOException ex) {
if (depth == 0) {
writeFatalException(ex);
}
throw ex;
}
}
/** {@collect.stats}
* {@description.open}
* Method used by subclasses to override the default writeObject method.
* This method is called by trusted subclasses of ObjectInputStream that
* constructed ObjectInputStream using the protected no-arg constructor.
* The subclass is expected to provide an override method with the modifier
* "final".
* {@description.close}
*
* @param obj object to be written to the underlying stream
* @throws IOException if there are I/O errors while writing to the
* underlying stream
* @see #ObjectOutputStream()
* @see #writeObject(Object)
* @since 1.2
*/
protected void writeObjectOverride(Object obj) throws IOException {
}
/** {@collect.stats}
* {@description.open}
* Writes an "unshared" object to the ObjectOutputStream. This method is
* identical to writeObject, except that it always writes the given object
* as a new, unique object in the stream (as opposed to a back-reference
* pointing to a previously serialized instance). Specifically:
* <ul>
* <li>An object written via writeUnshared is always serialized in the
* same manner as a newly appearing object (an object that has not
* been written to the stream yet), regardless of whether or not the
* object has been written previously.
*
* <li>If writeObject is used to write an object that has been previously
* written with writeUnshared, the previous writeUnshared operation
* is treated as if it were a write of a separate object. In other
* words, ObjectOutputStream will never generate back-references to
* object data written by calls to writeUnshared.
* </ul>
* While writing an object via writeUnshared does not in itself guarantee a
* unique reference to the object when it is deserialized, it allows a
* single object to be defined multiple times in a stream, so that multiple
* calls to readUnshared by the receiver will not conflict. Note that the
* rules described above only apply to the base-level object written with
* writeUnshared, and not to any transitively referenced sub-objects in the
* object graph to be serialized.
*
* <p>ObjectOutputStream subclasses which override this method can only be
* constructed in security contexts possessing the
* "enableSubclassImplementation" SerializablePermission; any attempt to
* instantiate such a subclass without this permission will cause a
* SecurityException to be thrown.
* {@description.close}
*
* @param obj object to write to stream
* @throws NotSerializableException if an object in the graph to be
* serialized does not implement the Serializable interface
* @throws InvalidClassException if a problem exists with the class of an
* object to be serialized
* @throws IOException if an I/O error occurs during serialization
* @since 1.4
*/
public void writeUnshared(Object obj) throws IOException {
try {
writeObject0(obj, true);
} catch (IOException ex) {
if (depth == 0) {
writeFatalException(ex);
}
throw ex;
}
}
/** {@collect.stats}
* {@description.open}
* Write the non-static and non-transient fields of the current class to
* this stream. This may only be called from the writeObject method of the
* class being serialized. It will throw the NotActiveException if it is
* called otherwise.
* {@description.close}
*
* @throws IOException if I/O errors occur while writing to the underlying
* <code>OutputStream</code>
*/
public void defaultWriteObject() throws IOException {
if ( curContext == null ) {
throw new NotActiveException("not in call to writeObject");
}
Object curObj = curContext.getObj();
ObjectStreamClass curDesc = curContext.getDesc();
bout.setBlockDataMode(false);
defaultWriteFields(curObj, curDesc);
bout.setBlockDataMode(true);
}
/** {@collect.stats}
* {@description.open}
* Retrieve the object used to buffer persistent fields to be written to
* the stream. The fields will be written to the stream when writeFields
* method is called.
* {@description.close}
*
* @return an instance of the class Putfield that holds the serializable
* fields
* @throws IOException if I/O errors occur
* @since 1.2
*/
public ObjectOutputStream.PutField putFields() throws IOException {
if (curPut == null) {
if (curContext == null) {
throw new NotActiveException("not in call to writeObject");
}
Object curObj = curContext.getObj();
ObjectStreamClass curDesc = curContext.getDesc();
curPut = new PutFieldImpl(curDesc);
}
return curPut;
}
/** {@collect.stats}
* {@description.open}
* Write the buffered fields to the stream.
* {@description.close}
*
* @throws IOException if I/O errors occur while writing to the underlying
* stream
* @throws NotActiveException Called when a classes writeObject method was
* not called to write the state of the object.
* @since 1.2
*/
public void writeFields() throws IOException {
if (curPut == null) {
throw new NotActiveException("no current PutField object");
}
bout.setBlockDataMode(false);
curPut.writeFields();
bout.setBlockDataMode(true);
}
/** {@collect.stats}
* {@description.open}
* Reset will disregard the state of any objects already written to the
* stream. The state is reset to be the same as a new ObjectOutputStream.
* The current point in the stream is marked as reset so the corresponding
* ObjectInputStream will be reset at the same point. Objects previously
* written to the stream will not be refered to as already being in the
* stream. They will be written to the stream again.
* {@description.close}
*
* @throws IOException if reset() is invoked while serializing an object.
*/
public void reset() throws IOException {
if (depth != 0) {
throw new IOException("stream active");
}
bout.setBlockDataMode(false);
bout.writeByte(TC_RESET);
clear();
bout.setBlockDataMode(true);
}
/** {@collect.stats}
* {@description.open}
* Subclasses may implement this method to allow class data to be stored in
* the stream. By default this method does nothing. The corresponding
* method in ObjectInputStream is resolveClass. This method is called
* exactly once for each unique class in the stream. The class name and
* signature will have already been written to the stream. This method may
* make free use of the ObjectOutputStream to save any representation of
* the class it deems suitable (for example, the bytes of the class file).
* {@description.close}
* {@property.open}
* The resolveClass method in the corresponding subclass of
* ObjectInputStream must read and use any data or objects written by
* annotateClass.
* {@property.close}
*
* @param cl the class to annotate custom data for
* @throws IOException Any exception thrown by the underlying
* OutputStream.
*/
protected void annotateClass(Class<?> cl) throws IOException {
}
/** {@collect.stats}
* {@description.open}
* Subclasses may implement this method to store custom data in the stream
* along with descriptors for dynamic proxy classes.
*
* <p>This method is called exactly once for each unique proxy class
* descriptor in the stream. The default implementation of this method in
* <code>ObjectOutputStream</code> does nothing.
*
* <p>The corresponding method in <code>ObjectInputStream</code> is
* <code>resolveProxyClass</code>.
* {@description.close}
* {@property.open}
* For a given subclass of
* <code>ObjectOutputStream</code> that overrides this method, the
* <code>resolveProxyClass</code> method in the corresponding subclass of
* <code>ObjectInputStream</code> must read any data or objects written by
* <code>annotateProxyClass</code>.
* {@property.close}
*
* @param cl the proxy class to annotate custom data for
* @throws IOException any exception thrown by the underlying
* <code>OutputStream</code>
* @see ObjectInputStream#resolveProxyClass(String[])
* @since 1.3
*/
protected void annotateProxyClass(Class<?> cl) throws IOException {
}
/** {@collect.stats}
* {@description.open}
* This method will allow trusted subclasses of ObjectOutputStream to
* substitute one object for another during serialization. Replacing
* objects is disabled until enableReplaceObject is called. The
* enableReplaceObject method checks that the stream requesting to do
* replacement can be trusted. The first occurrence of each object written
* into the serialization stream is passed to replaceObject. Subsequent
* references to the object are replaced by the object returned by the
* original call to replaceObject. To ensure that the private state of
* objects is not unintentionally exposed, only trusted streams may use
* replaceObject.
*
* <p>The ObjectOutputStream.writeObject method takes a parameter of type
* Object (as opposed to type Serializable) to allow for cases where
* non-serializable objects are replaced by serializable ones.
* {@description.close}
*
* {@property.open}
* <p>When a subclass is replacing objects it must insure that either a
* complementary substitution must be made during deserialization or that
* the substituted object is compatible with every field where the
* reference will be stored. Objects whose type is not a subclass of the
* type of the field or array element abort the serialization by raising an
* exception and the object is not be stored.
* {@property.close}
*
* {@description.open}
* <p>This method is called only once when each object is first
* encountered. All subsequent references to the object will be redirected
* to the new object. This method should return the object to be
* substituted or the original object.
*
* <p>Null can be returned as the object to be substituted, but may cause
* NullReferenceException in classes that contain references to the
* original object since they may be expecting an object instead of
* null.
* {@description.close}
*
* @param obj the object to be replaced
* @return the alternate object that replaced the specified one
* @throws IOException Any exception thrown by the underlying
* OutputStream.
*/
protected Object replaceObject(Object obj) throws IOException {
return obj;
}
/** {@collect.stats}
* {@description.open}
* Enable the stream to do replacement of objects in the stream. When
* enabled, the replaceObject method is called for every object being
* serialized.
*
* <p>If <code>enable</code> is true, and there is a security manager
* installed, this method first calls the security manager's
* <code>checkPermission</code> method with a
* <code>SerializablePermission("enableSubstitution")</code> permission to
* ensure it's ok to enable the stream to do replacement of objects in the
* stream.
* {@description.close}
*
* @param enable boolean parameter to enable replacement of objects
* @return the previous setting before this method was invoked
* @throws SecurityException if a security manager exists and its
* <code>checkPermission</code> method denies enabling the stream
* to do replacement of objects in the stream.
* @see SecurityManager#checkPermission
* @see java.io.SerializablePermission
*/
protected boolean enableReplaceObject(boolean enable)
throws SecurityException
{
if (enable == enableReplace) {
return enable;
}
if (enable) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(SUBSTITUTION_PERMISSION);
}
}
enableReplace = enable;
return !enableReplace;
}
/** {@collect.stats}
* {@description.open}
* The writeStreamHeader method is provided so subclasses can append or
* prepend their own header to the stream. It writes the magic number and
* version to the stream.
* {@description.close}
*
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
protected void writeStreamHeader() throws IOException {
bout.writeShort(STREAM_MAGIC);
bout.writeShort(STREAM_VERSION);
}
/** {@collect.stats}
* {@description.open}
* Write the specified class descriptor to the ObjectOutputStream. Class
* descriptors are used to identify the classes of objects written to the
* stream.
* {@description.close}
* {@property.open}
* Subclasses of ObjectOutputStream may override this method to
* customize the way in which class descriptors are written to the
* serialization stream. The corresponding method in ObjectInputStream,
* <code>readClassDescriptor</code>, should then be overridden to
* reconstitute the class descriptor from its custom stream representation.
* {@property.close}
* {@description.open}
* By default, this method writes class descriptors according to the format
* defined in the Object Serialization specification.
*
* <p>Note that this method will only be called if the ObjectOutputStream
* is not using the old serialization stream format (set by calling
* ObjectOutputStream's <code>useProtocolVersion</code> method). If this
* serialization stream is using the old format
* (<code>PROTOCOL_VERSION_1</code>), the class descriptor will be written
* internally in a manner that cannot be overridden or customized.
* {@description.close}
*
* @param desc class descriptor to write to the stream
* @throws IOException If an I/O error has occurred.
* @see java.io.ObjectInputStream#readClassDescriptor()
* @see #useProtocolVersion(int)
* @see java.io.ObjectStreamConstants#PROTOCOL_VERSION_1
* @since 1.3
*/
protected void writeClassDescriptor(ObjectStreamClass desc)
throws IOException
{
desc.writeNonProxy(this);
}
/** {@collect.stats}
* {@description.open}
* Writes a byte.
* {@description.close}
* {@description.open blocking}
* This method will block until the byte is actually
* written.
* {@description.close}
*
* @param val the byte to be written to the stream
* @throws IOException If an I/O error has occurred.
*/
public void write(int val) throws IOException {
bout.write(val);
}
/** {@collect.stats}
* {@description.open}
* Writes an array of bytes.
* {@description.close}
* {@description.open blocking}
* This method will block until the bytes are
* actually written.
* {@description.close}
*
* @param buf the data to be written
* @throws IOException If an I/O error has occurred.
*/
public void write(byte[] buf) throws IOException {
bout.write(buf, 0, buf.length, false);
}
/** {@collect.stats}
* {@description.open}
* Writes a sub array of bytes.
* {@description.close}
*
* @param buf the data to be written
* @param off the start offset in the data
* @param len the number of bytes that are written
* @throws IOException If an I/O error has occurred.
*/
public void write(byte[] buf, int off, int len) throws IOException {
if (buf == null) {
throw new NullPointerException();
}
int endoff = off + len;
if (off < 0 || len < 0 || endoff > buf.length || endoff < 0) {
throw new IndexOutOfBoundsException();
}
bout.write(buf, off, len, false);
}
/** {@collect.stats}
* {@description.open}
* Flushes the stream. This will write any buffered output bytes and flush
* through to the underlying stream.
* {@description.close}
*
* @throws IOException If an I/O error has occurred.
*/
public void flush() throws IOException {
bout.flush();
}
/** {@collect.stats}
* {@description.open}
* Drain any buffered data in ObjectOutputStream. Similar to flush but
* does not propagate the flush to the underlying stream.
* {@description.close}
*
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
protected void drain() throws IOException {
bout.drain();
}
/** {@collect.stats}
* {@description.open}
* Closes the stream.
* {@description.close}
* {@property.open runtime formal:java.io.ObjectOutput_Close}
* This method must be called to release any resources
* associated with the stream.
* {@property.close}
*
* @throws IOException If an I/O error has occurred.
*/
public void close() throws IOException {
flush();
clear();
bout.close();
}
/** {@collect.stats}
* {@description.open}
* Writes a boolean.
* {@description.close}
*
* @param val the boolean to be written
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
public void writeBoolean(boolean val) throws IOException {
bout.writeBoolean(val);
}
/** {@collect.stats}
* {@description.open}
* Writes an 8 bit byte.
* {@description.close}
*
* @param val the byte value to be written
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
public void writeByte(int val) throws IOException {
bout.writeByte(val);
}
/** {@collect.stats}
* {@description.open}
* Writes a 16 bit short.
* {@description.close}
*
* @param val the short value to be written
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
public void writeShort(int val) throws IOException {
bout.writeShort(val);
}
/** {@collect.stats}
* {@description.open}
* Writes a 16 bit char.
* {@description.close}
*
* @param val the char value to be written
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
public void writeChar(int val) throws IOException {
bout.writeChar(val);
}
/** {@collect.stats}
* {@description.open}
* Writes a 32 bit int.
* {@description.close}
*
* @param val the integer value to be written
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
public void writeInt(int val) throws IOException {
bout.writeInt(val);
}
/** {@collect.stats}
* {@description.open}
* Writes a 64 bit long.
* {@description.close}
*
* @param val the long value to be written
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
public void writeLong(long val) throws IOException {
bout.writeLong(val);
}
/** {@collect.stats}
* {@description.open}
* Writes a 32 bit float.
* {@description.close}
*
* @param val the float value to be written
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
public void writeFloat(float val) throws IOException {
bout.writeFloat(val);
}
/** {@collect.stats}
* {@description.open}
* Writes a 64 bit double.
* {@description.close}
*
* @param val the double value to be written
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
public void writeDouble(double val) throws IOException {
bout.writeDouble(val);
}
/** {@collect.stats}
* {@description.open}
* Writes a String as a sequence of bytes.
* {@description.close}
*
* @param str the String of bytes to be written
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
public void writeBytes(String str) throws IOException {
bout.writeBytes(str);
}
/** {@collect.stats}
* {@description.open}
* Writes a String as a sequence of chars.
* {@description.close}
*
* @param str the String of chars to be written
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
public void writeChars(String str) throws IOException {
bout.writeChars(str);
}
/** {@collect.stats}
* {@description.open}
* Primitive data write of this String in
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
* format. Note that there is a
* significant difference between writing a String into the stream as
* primitive data or as an Object. A String instance written by writeObject
* is written into the stream as a String initially. Future writeObject()
* calls write references to the string into the stream.
* {@description.close}
*
* @param str the String to be written
* @throws IOException if I/O errors occur while writing to the underlying
* stream
*/
public void writeUTF(String str) throws IOException {
bout.writeUTF(str);
}
/** {@collect.stats}
* {@description.open}
* Provide programmatic access to the persistent fields to be written
* to ObjectOutput.
* {@description.close}
*
* @since 1.2
*/
public static abstract class PutField {
/** {@collect.stats}
* {@description.open}
* Put the value of the named boolean field into the persistent field.
* {@description.close}
*
* @param name the name of the serializable field
* @param val the value to assign to the field
* @throws IllegalArgumentException if <code>name</code> does not
* match the name of a serializable field for the class whose fields
* are being written, or if the type of the named field is not
* <code>boolean</code>
*/
public abstract void put(String name, boolean val);
/** {@collect.stats}
* {@description.open}
* Put the value of the named byte field into the persistent field.
* {@description.close}
*
* @param name the name of the serializable field
* @param val the value to assign to the field
* @throws IllegalArgumentException if <code>name</code> does not
* match the name of a serializable field for the class whose fields
* are being written, or if the type of the named field is not
* <code>byte</code>
*/
public abstract void put(String name, byte val);
/** {@collect.stats}
* {@description.open}
* Put the value of the named char field into the persistent field.
* {@description.close}
*
* @param name the name of the serializable field
* @param val the value to assign to the field
* @throws IllegalArgumentException if <code>name</code> does not
* match the name of a serializable field for the class whose fields
* are being written, or if the type of the named field is not
* <code>char</code>
*/
public abstract void put(String name, char val);
/** {@collect.stats}
* {@description.open}
* Put the value of the named short field into the persistent field.
* {@description.close}
*
* @param name the name of the serializable field
* @param val the value to assign to the field
* @throws IllegalArgumentException if <code>name</code> does not
* match the name of a serializable field for the class whose fields
* are being written, or if the type of the named field is not
* <code>short</code>
*/
public abstract void put(String name, short val);
/** {@collect.stats}
* {@description.open}
* Put the value of the named int field into the persistent field.
* {@description.close}
*
* @param name the name of the serializable field
* @param val the value to assign to the field
* @throws IllegalArgumentException if <code>name</code> does not
* match the name of a serializable field for the class whose fields
* are being written, or if the type of the named field is not
* <code>int</code>
*/
public abstract void put(String name, int val);
/** {@collect.stats}
* {@description.open}
* Put the value of the named long field into the persistent field.
* {@description.close}
*
* @param name the name of the serializable field
* @param val the value to assign to the field
* @throws IllegalArgumentException if <code>name</code> does not
* match the name of a serializable field for the class whose fields
* are being written, or if the type of the named field is not
* <code>long</code>
*/
public abstract void put(String name, long val);
/** {@collect.stats}
* {@description.open}
* Put the value of the named float field into the persistent field.
* {@description.close}
*
* @param name the name of the serializable field
* @param val the value to assign to the field
* @throws IllegalArgumentException if <code>name</code> does not
* match the name of a serializable field for the class whose fields
* are being written, or if the type of the named field is not
* <code>float</code>
*/
public abstract void put(String name, float val);
/** {@collect.stats}
* {@description.open}
* Put the value of the named double field into the persistent field.
* {@description.close}
*
* @param name the name of the serializable field
* @param val the value to assign to the field
* @throws IllegalArgumentException if <code>name</code> does not
* match the name of a serializable field for the class whose fields
* are being written, or if the type of the named field is not
* <code>double</code>
*/
public abstract void put(String name, double val);
/** {@collect.stats}
* {@description.open}
* Put the value of the named Object field into the persistent field.
* {@description.close}
*
* @param name the name of the serializable field
* @param val the value to assign to the field
* (which may be <code>null</code>)
* @throws IllegalArgumentException if <code>name</code> does not
* match the name of a serializable field for the class whose fields
* are being written, or if the type of the named field is not a
* reference type
*/
public abstract void put(String name, Object val);
/** {@collect.stats}
* {@description.open}
* Write the data and fields to the specified ObjectOutput stream,
* which must be the same stream that produced this
* <code>PutField</code> object.
* {@description.close}
*
* @param out the stream to write the data and fields to
* @throws IOException if I/O errors occur while writing to the
* underlying stream
* @throws IllegalArgumentException if the specified stream is not
* the same stream that produced this <code>PutField</code>
* object
* @deprecated This method does not write the values contained by this
* <code>PutField</code> object in a proper format, and may
* result in corruption of the serialization stream. The
* correct way to write <code>PutField</code> data is by
* calling the {@link java.io.ObjectOutputStream#writeFields()}
* method.
*/
@Deprecated
public abstract void write(ObjectOutput out) throws IOException;
}
/** {@collect.stats}
* {@description.open}
* Returns protocol version in use.
* {@description.close}
*/
int getProtocolVersion() {
return protocol;
}
/** {@collect.stats}
* {@description.open}
* Writes string without allowing it to be replaced in stream. Used by
* ObjectStreamClass to write class descriptor type strings.
* {@description.close}
*/
void writeTypeString(String str) throws IOException {
int handle;
if (str == null) {
writeNull();
} else if ((handle = handles.lookup(str)) != -1) {
writeHandle(handle);
} else {
writeString(str, false);
}
}
/** {@collect.stats}
* {@description.open}
* Verifies that this (possibly subclass) instance can be constructed
* without violating security constraints:
* {@description.close}
* {@property.open uncheckable}
* the subclass must not override
* security-sensitive non-final methods, or else the
* "enableSubclassImplementation" SerializablePermission is checked.
* {@property.close}
*/
private void verifySubclass() {
Class cl = getClass();
if (cl == ObjectOutputStream.class) {
return;
}
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
return;
}
processQueue(Caches.subclassAuditsQueue, Caches.subclassAudits);
WeakClassKey key = new WeakClassKey(cl, Caches.subclassAuditsQueue);
Boolean result = Caches.subclassAudits.get(key);
if (result == null) {
result = Boolean.valueOf(auditSubclass(cl));
Caches.subclassAudits.putIfAbsent(key, result);
}
if (result.booleanValue()) {
return;
}
sm.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
}
/** {@collect.stats}
* {@description.open}
* Performs reflective checks on given subclass to verify that it doesn't
* override security-sensitive non-final methods. Returns true if subclass
* is "safe", false otherwise.
* {@description.close}
*/
private static boolean auditSubclass(final Class subcl) {
Boolean result = AccessController.doPrivileged(
new PrivilegedAction<Boolean>() {
public Boolean run() {
for (Class cl = subcl;
cl != ObjectOutputStream.class;
cl = cl.getSuperclass())
{
try {
cl.getDeclaredMethod(
"writeUnshared", new Class[] { Object.class });
return Boolean.FALSE;
} catch (NoSuchMethodException ex) {
}
try {
cl.getDeclaredMethod("putFields", (Class[]) null);
return Boolean.FALSE;
} catch (NoSuchMethodException ex) {
}
}
return Boolean.TRUE;
}
}
);
return result.booleanValue();
}
/** {@collect.stats}
* {@description.open}
* Clears internal data structures.
* {@description.close}
*/
private void clear() {
subs.clear();
handles.clear();
}
/** {@collect.stats}
* {@description.open}
* Underlying writeObject/writeUnshared implementation.
* {@description.close}
*/
private void writeObject0(Object obj, boolean unshared)
throws IOException
{
boolean oldMode = bout.setBlockDataMode(false);
depth++;
try {
// handle previously written and non-replaceable objects
int h;
if ((obj = subs.lookup(obj)) == null) {
writeNull();
return;
} else if (!unshared && (h = handles.lookup(obj)) != -1) {
writeHandle(h);
return;
} else if (obj instanceof Class) {
writeClass((Class) obj, unshared);
return;
} else if (obj instanceof ObjectStreamClass) {
writeClassDesc((ObjectStreamClass) obj, unshared);
return;
}
// check for replacement object
Object orig = obj;
Class cl = obj.getClass();
ObjectStreamClass desc;
for (;;) {
// REMIND: skip this check for strings/arrays?
Class repCl;
desc = ObjectStreamClass.lookup(cl, true);
if (!desc.hasWriteReplaceMethod() ||
(obj = desc.invokeWriteReplace(obj)) == null ||
(repCl = obj.getClass()) == cl)
{
break;
}
cl = repCl;
}
if (enableReplace) {
Object rep = replaceObject(obj);
if (rep != obj && rep != null) {
cl = rep.getClass();
desc = ObjectStreamClass.lookup(cl, true);
}
obj = rep;
}
// if object replaced, run through original checks a second time
if (obj != orig) {
subs.assign(orig, obj);
if (obj == null) {
writeNull();
return;
} else if (!unshared && (h = handles.lookup(obj)) != -1) {
writeHandle(h);
return;
} else if (obj instanceof Class) {
writeClass((Class) obj, unshared);
return;
} else if (obj instanceof ObjectStreamClass) {
writeClassDesc((ObjectStreamClass) obj, unshared);
return;
}
}
// remaining cases
if (obj instanceof String) {
writeString((String) obj, unshared);
} else if (cl.isArray()) {
writeArray(obj, desc, unshared);
} else if (obj instanceof Enum) {
writeEnum((Enum) obj, desc, unshared);
} else if (obj instanceof Serializable) {
writeOrdinaryObject(obj, desc, unshared);
} else {
if (extendedDebugInfo) {
throw new NotSerializableException(
cl.getName() + "\n" + debugInfoStack.toString());
} else {
throw new NotSerializableException(cl.getName());
}
}
} finally {
depth--;
bout.setBlockDataMode(oldMode);
}
}
/** {@collect.stats}
* {@description.open}
* Writes null code to stream.
* {@description.close}
*/
private void writeNull() throws IOException {
bout.writeByte(TC_NULL);
}
/** {@collect.stats}
* {@description.open}
* Writes given object handle to stream.
* {@description.close}
*/
private void writeHandle(int handle) throws IOException {
bout.writeByte(TC_REFERENCE);
bout.writeInt(baseWireHandle + handle);
}
/** {@collect.stats}
* {@description.open}
* Writes representation of given class to stream.
* {@description.close}
*/
private void writeClass(Class cl, boolean unshared) throws IOException {
bout.writeByte(TC_CLASS);
writeClassDesc(ObjectStreamClass.lookup(cl, true), false);
handles.assign(unshared ? null : cl);
}
/** {@collect.stats}
* {@description.open}
* Writes representation of given class descriptor to stream.
* {@description.close}
*/
private void writeClassDesc(ObjectStreamClass desc, boolean unshared)
throws IOException
{
int handle;
if (desc == null) {
writeNull();
} else if (!unshared && (handle = handles.lookup(desc)) != -1) {
writeHandle(handle);
} else if (desc.isProxy()) {
writeProxyDesc(desc, unshared);
} else {
writeNonProxyDesc(desc, unshared);
}
}
/** {@collect.stats}
* {@description.open}
* Writes class descriptor representing a dynamic proxy class to stream.
* {@description.close}
*/
private void writeProxyDesc(ObjectStreamClass desc, boolean unshared)
throws IOException
{
bout.writeByte(TC_PROXYCLASSDESC);
handles.assign(unshared ? null : desc);
Class cl = desc.forClass();
Class[] ifaces = cl.getInterfaces();
bout.writeInt(ifaces.length);
for (int i = 0; i < ifaces.length; i++) {
bout.writeUTF(ifaces[i].getName());
}
bout.setBlockDataMode(true);
annotateProxyClass(cl);
bout.setBlockDataMode(false);
bout.writeByte(TC_ENDBLOCKDATA);
writeClassDesc(desc.getSuperDesc(), false);
}
/** {@collect.stats}
* {@description.open}
* Writes class descriptor representing a standard (i.e., not a dynamic
* proxy) class to stream.
* {@description.close}
*/
private void writeNonProxyDesc(ObjectStreamClass desc, boolean unshared)
throws IOException
{
bout.writeByte(TC_CLASSDESC);
handles.assign(unshared ? null : desc);
if (protocol == PROTOCOL_VERSION_1) {
// do not invoke class descriptor write hook with old protocol
desc.writeNonProxy(this);
} else {
writeClassDescriptor(desc);
}
Class cl = desc.forClass();
bout.setBlockDataMode(true);
annotateClass(cl);
bout.setBlockDataMode(false);
bout.writeByte(TC_ENDBLOCKDATA);
writeClassDesc(desc.getSuperDesc(), false);
}
/** {@collect.stats}
* {@description.open}
* Writes given string to stream, using standard or long UTF format
* depending on string length.
* {@description.close}
*/
private void writeString(String str, boolean unshared) throws IOException {
handles.assign(unshared ? null : str);
long utflen = bout.getUTFLength(str);
if (utflen <= 0xFFFF) {
bout.writeByte(TC_STRING);
bout.writeUTF(str, utflen);
} else {
bout.writeByte(TC_LONGSTRING);
bout.writeLongUTF(str, utflen);
}
}
/** {@collect.stats}
* {@description.open}
* Writes given array object to stream.
* {@description.close}
*/
private void writeArray(Object array,
ObjectStreamClass desc,
boolean unshared)
throws IOException
{
bout.writeByte(TC_ARRAY);
writeClassDesc(desc, false);
handles.assign(unshared ? null : array);
Class ccl = desc.forClass().getComponentType();
if (ccl.isPrimitive()) {
if (ccl == Integer.TYPE) {
int[] ia = (int[]) array;
bout.writeInt(ia.length);
bout.writeInts(ia, 0, ia.length);
} else if (ccl == Byte.TYPE) {
byte[] ba = (byte[]) array;
bout.writeInt(ba.length);
bout.write(ba, 0, ba.length, true);
} else if (ccl == Long.TYPE) {
long[] ja = (long[]) array;
bout.writeInt(ja.length);
bout.writeLongs(ja, 0, ja.length);
} else if (ccl == Float.TYPE) {
float[] fa = (float[]) array;
bout.writeInt(fa.length);
bout.writeFloats(fa, 0, fa.length);
} else if (ccl == Double.TYPE) {
double[] da = (double[]) array;
bout.writeInt(da.length);
bout.writeDoubles(da, 0, da.length);
} else if (ccl == Short.TYPE) {
short[] sa = (short[]) array;
bout.writeInt(sa.length);
bout.writeShorts(sa, 0, sa.length);
} else if (ccl == Character.TYPE) {
char[] ca = (char[]) array;
bout.writeInt(ca.length);
bout.writeChars(ca, 0, ca.length);
} else if (ccl == Boolean.TYPE) {
boolean[] za = (boolean[]) array;
bout.writeInt(za.length);
bout.writeBooleans(za, 0, za.length);
} else {
throw new InternalError();
}
} else {
Object[] objs = (Object[]) array;
int len = objs.length;
bout.writeInt(len);
if (extendedDebugInfo) {
debugInfoStack.push(
"array (class \"" + array.getClass().getName() +
"\", size: " + len + ")");
}
try {
for (int i = 0; i < len; i++) {
if (extendedDebugInfo) {
debugInfoStack.push(
"element of array (index: " + i + ")");
}
try {
writeObject0(objs[i], false);
} finally {
if (extendedDebugInfo) {
debugInfoStack.pop();
}
}
}
} finally {
if (extendedDebugInfo) {
debugInfoStack.pop();
}
}
}
}
/** {@collect.stats}
* {@description.open}
* Writes given enum constant to stream.
* {@description.close}
*/
private void writeEnum(Enum en,
ObjectStreamClass desc,
boolean unshared)
throws IOException
{
bout.writeByte(TC_ENUM);
ObjectStreamClass sdesc = desc.getSuperDesc();
writeClassDesc((sdesc.forClass() == Enum.class) ? desc : sdesc, false);
handles.assign(unshared ? null : en);
writeString(en.name(), false);
}
/** {@collect.stats}
* {@description.open}
* Writes representation of a "ordinary" (i.e., not a String, Class,
* ObjectStreamClass, array, or enum constant) serializable object to the
* stream.
* {@description.close}
*/
private void writeOrdinaryObject(Object obj,
ObjectStreamClass desc,
boolean unshared)
throws IOException
{
if (extendedDebugInfo) {
debugInfoStack.push(
(depth == 1 ? "root " : "") + "object (class \"" +
obj.getClass().getName() + "\", " + obj.toString() + ")");
}
try {
desc.checkSerialize();
bout.writeByte(TC_OBJECT);
writeClassDesc(desc, false);
handles.assign(unshared ? null : obj);
if (desc.isExternalizable() && !desc.isProxy()) {
writeExternalData((Externalizable) obj);
} else {
writeSerialData(obj, desc);
}
} finally {
if (extendedDebugInfo) {
debugInfoStack.pop();
}
}
}
/** {@collect.stats}
* {@description.open}
* Writes externalizable data of given object by invoking its
* writeExternal() method.
* {@description.close}
*/
private void writeExternalData(Externalizable obj) throws IOException {
PutFieldImpl oldPut = curPut;
curPut = null;
SerialCallbackContext oldContext = curContext;
if (extendedDebugInfo) {
debugInfoStack.push("writeExternal data");
}
try {
curContext = null;
if (protocol == PROTOCOL_VERSION_1) {
obj.writeExternal(this);
} else {
bout.setBlockDataMode(true);
obj.writeExternal(this);
bout.setBlockDataMode(false);
bout.writeByte(TC_ENDBLOCKDATA);
}
} finally {
curContext = oldContext;
if (extendedDebugInfo) {
debugInfoStack.pop();
}
}
curPut = oldPut;
}
/** {@collect.stats}
* {@description.open}
* Writes instance data for each serializable class of given object, from
* superclass to subclass.
* {@description.close}
*/
private void writeSerialData(Object obj, ObjectStreamClass desc)
throws IOException
{
ObjectStreamClass.ClassDataSlot[] slots = desc.getClassDataLayout();
for (int i = 0; i < slots.length; i++) {
ObjectStreamClass slotDesc = slots[i].desc;
if (slotDesc.hasWriteObjectMethod()) {
PutFieldImpl oldPut = curPut;
curPut = null;
SerialCallbackContext oldContext = curContext;
if (extendedDebugInfo) {
debugInfoStack.push(
"custom writeObject data (class \"" +
slotDesc.getName() + "\")");
}
try {
curContext = new SerialCallbackContext(obj, slotDesc);
bout.setBlockDataMode(true);
slotDesc.invokeWriteObject(obj, this);
bout.setBlockDataMode(false);
bout.writeByte(TC_ENDBLOCKDATA);
} finally {
curContext.setUsed();
curContext = oldContext;
if (extendedDebugInfo) {
debugInfoStack.pop();
}
}
curPut = oldPut;
} else {
defaultWriteFields(obj, slotDesc);
}
}
}
/** {@collect.stats}
* {@description.open}
* Fetches and writes values of serializable fields of given object to
* stream. The given class descriptor specifies which field values to
* write, and in which order they should be written.
* {@description.close}
*/
private void defaultWriteFields(Object obj, ObjectStreamClass desc)
throws IOException
{
// REMIND: perform conservative isInstance check here?
desc.checkDefaultSerialize();
int primDataSize = desc.getPrimDataSize();
if (primVals == null || primVals.length < primDataSize) {
primVals = new byte[primDataSize];
}
desc.getPrimFieldValues(obj, primVals);
bout.write(primVals, 0, primDataSize, false);
ObjectStreamField[] fields = desc.getFields(false);
Object[] objVals = new Object[desc.getNumObjFields()];
int numPrimFields = fields.length - objVals.length;
desc.getObjFieldValues(obj, objVals);
for (int i = 0; i < objVals.length; i++) {
if (extendedDebugInfo) {
debugInfoStack.push(
"field (class \"" + desc.getName() + "\", name: \"" +
fields[numPrimFields + i].getName() + "\", type: \"" +
fields[numPrimFields + i].getType() + "\")");
}
try {
writeObject0(objVals[i],
fields[numPrimFields + i].isUnshared());
} finally {
if (extendedDebugInfo) {
debugInfoStack.pop();
}
}
}
}
/** {@collect.stats}
* {@description.open}
* Attempts to write to stream fatal IOException that has caused
* serialization to abort.
* {@description.close}
*/
private void writeFatalException(IOException ex) throws IOException {
/*
* Note: the serialization specification states that if a second
* IOException occurs while attempting to serialize the original fatal
* exception to the stream, then a StreamCorruptedException should be
* thrown (section 2.1). However, due to a bug in previous
* implementations of serialization, StreamCorruptedExceptions were
* rarely (if ever) actually thrown--the "root" exceptions from
* underlying streams were thrown instead. This historical behavior is
* followed here for consistency.
*/
clear();
boolean oldMode = bout.setBlockDataMode(false);
try {
bout.writeByte(TC_EXCEPTION);
writeObject0(ex, false);
clear();
} finally {
bout.setBlockDataMode(oldMode);
}
}
/** {@collect.stats}
* {@description.open}
* Converts specified span of float values into byte values.
* {@description.close}
*/
// REMIND: remove once hotspot inlines Float.floatToIntBits
private static native void floatsToBytes(float[] src, int srcpos,
byte[] dst, int dstpos,
int nfloats);
/** {@collect.stats}
* {@description.open}
* Converts specified span of double values into byte values.
* {@description.close}
*/
// REMIND: remove once hotspot inlines Double.doubleToLongBits
private static native void doublesToBytes(double[] src, int srcpos,
byte[] dst, int dstpos,
int ndoubles);
/** {@collect.stats}
* {@description.open}
* Default PutField implementation.
* {@description.close}
*/
private class PutFieldImpl extends PutField {
/** {@collect.stats}
* {@description.open}
* class descriptor describing serializable fields
* {@description.close}
*/
private final ObjectStreamClass desc;
/** {@collect.stats}
* {@description.open}
* primitive field values
* {@description.close}
*/
private final byte[] primVals;
/** {@collect.stats}
* {@description.open}
* object field values
* {@description.close}
*/
private final Object[] objVals;
/** {@collect.stats}
* {@description.open}
* Creates PutFieldImpl object for writing fields defined in given
* class descriptor.
* {@description.close}
*/
PutFieldImpl(ObjectStreamClass desc) {
this.desc = desc;
primVals = new byte[desc.getPrimDataSize()];
objVals = new Object[desc.getNumObjFields()];
}
public void put(String name, boolean val) {
Bits.putBoolean(primVals, getFieldOffset(name, Boolean.TYPE), val);
}
public void put(String name, byte val) {
primVals[getFieldOffset(name, Byte.TYPE)] = val;
}
public void put(String name, char val) {
Bits.putChar(primVals, getFieldOffset(name, Character.TYPE), val);
}
public void put(String name, short val) {
Bits.putShort(primVals, getFieldOffset(name, Short.TYPE), val);
}
public void put(String name, int val) {
Bits.putInt(primVals, getFieldOffset(name, Integer.TYPE), val);
}
public void put(String name, float val) {
Bits.putFloat(primVals, getFieldOffset(name, Float.TYPE), val);
}
public void put(String name, long val) {
Bits.putLong(primVals, getFieldOffset(name, Long.TYPE), val);
}
public void put(String name, double val) {
Bits.putDouble(primVals, getFieldOffset(name, Double.TYPE), val);
}
public void put(String name, Object val) {
objVals[getFieldOffset(name, Object.class)] = val;
}
// deprecated in ObjectOutputStream.PutField
public void write(ObjectOutput out) throws IOException {
/*
* Applications should *not* use this method to write PutField
* data, as it will lead to stream corruption if the PutField
* object writes any primitive data (since block data mode is not
* unset/set properly, as is done in OOS.writeFields()). This
* broken implementation is being retained solely for behavioral
* compatibility, in order to support applications which use
* OOS.PutField.write() for writing only non-primitive data.
*
* Serialization of unshared objects is not implemented here since
* it is not necessary for backwards compatibility; also, unshared
* semantics may not be supported by the given ObjectOutput
* instance. Applications which write unshared objects using the
* PutField API must use OOS.writeFields().
*/
if (ObjectOutputStream.this != out) {
throw new IllegalArgumentException("wrong stream");
}
out.write(primVals, 0, primVals.length);
ObjectStreamField[] fields = desc.getFields(false);
int numPrimFields = fields.length - objVals.length;
// REMIND: warn if numPrimFields > 0?
for (int i = 0; i < objVals.length; i++) {
if (fields[numPrimFields + i].isUnshared()) {
throw new IOException("cannot write unshared object");
}
out.writeObject(objVals[i]);
}
}
/** {@collect.stats}
* {@description.open}
* Writes buffered primitive data and object fields to stream.
* {@description.close}
*/
void writeFields() throws IOException {
bout.write(primVals, 0, primVals.length, false);
ObjectStreamField[] fields = desc.getFields(false);
int numPrimFields = fields.length - objVals.length;
for (int i = 0; i < objVals.length; i++) {
if (extendedDebugInfo) {
debugInfoStack.push(
"field (class \"" + desc.getName() + "\", name: \"" +
fields[numPrimFields + i].getName() + "\", type: \"" +
fields[numPrimFields + i].getType() + "\")");
}
try {
writeObject0(objVals[i],
fields[numPrimFields + i].isUnshared());
} finally {
if (extendedDebugInfo) {
debugInfoStack.pop();
}
}
}
}
/** {@collect.stats}
* {@description.open}
* Returns offset of field with given name and type. A specified type
* of null matches all types, Object.class matches all non-primitive
* types, and any other non-null type matches assignable types only.
* Throws IllegalArgumentException if no matching field found.
* {@description.close}
*/
private int getFieldOffset(String name, Class type) {
ObjectStreamField field = desc.getField(name, type);
if (field == null) {
throw new IllegalArgumentException("no such field " + name +
" with type " + type);
}
return field.getOffset();
}
}
/** {@collect.stats}
* {@description.open}
* Buffered output stream with two modes: in default mode, outputs data in
* same format as DataOutputStream; in "block data" mode, outputs data
* bracketed by block data markers (see object serialization specification
* for details).
* {@description.close}
*/
private static class BlockDataOutputStream
extends OutputStream implements DataOutput
{
/** {@collect.stats}
* {@description.open}
* maximum data block length
* {@description.close}
*/
private static final int MAX_BLOCK_SIZE = 1024;
/** {@collect.stats}
* {@description.open}
* maximum data block header length
* {@description.close}
*/
private static final int MAX_HEADER_SIZE = 5;
/** {@collect.stats}
* {@description.open}
* (tunable) length of char buffer (for writing strings)
* {@description.close}
*/
private static final int CHAR_BUF_SIZE = 256;
/** {@collect.stats}
* {@description.open}
* buffer for writing general/block data
* {@description.close}
*/
private final byte[] buf = new byte[MAX_BLOCK_SIZE];
/** {@collect.stats}
* {@description.open}
* buffer for writing block data headers
* {@description.close}
*/
private final byte[] hbuf = new byte[MAX_HEADER_SIZE];
/** {@collect.stats}
* {@description.open}
* char buffer for fast string writes
* {@description.close}
*/
private final char[] cbuf = new char[CHAR_BUF_SIZE];
/** {@collect.stats}
* {@description.open}
* block data mode
* {@description.close}
*/
private boolean blkmode = false;
/** {@collect.stats}
* {@description.open}
* current offset into buf
* {@description.close}
*/
private int pos = 0;
/** {@collect.stats}
* {@description.open}
* underlying output stream
* {@description.close}
*/
private final OutputStream out;
/** {@collect.stats}
* {@description.open}
* loopback stream (for data writes that span data blocks)
* {@description.close}
*/
private final DataOutputStream dout;
/** {@collect.stats}
* {@description.open}
* Creates new BlockDataOutputStream on top of given underlying stream.
* Block data mode is turned off by default.
* {@description.close}
*/
BlockDataOutputStream(OutputStream out) {
this.out = out;
dout = new DataOutputStream(this);
}
/** {@collect.stats}
* {@description.open}
* Sets block data mode to the given mode (true == on, false == off)
* and returns the previous mode value. If the new mode is the same as
* the old mode, no action is taken. If the new mode differs from the
* old mode, any buffered data is flushed before switching to the new
* mode.
* {@description.close}
*/
boolean setBlockDataMode(boolean mode) throws IOException {
if (blkmode == mode) {
return blkmode;
}
drain();
blkmode = mode;
return !blkmode;
}
/** {@collect.stats}
* {@description.open}
* Returns true if the stream is currently in block data mode, false
* otherwise.
* {@description.close}
*/
boolean getBlockDataMode() {
return blkmode;
}
/* ----------------- generic output stream methods ----------------- */
/*
* The following methods are equivalent to their counterparts in
* OutputStream, except that they partition written data into data
* blocks when in block data mode.
*/
public void write(int b) throws IOException {
if (pos >= MAX_BLOCK_SIZE) {
drain();
}
buf[pos++] = (byte) b;
}
public void write(byte[] b) throws IOException {
write(b, 0, b.length, false);
}
public void write(byte[] b, int off, int len) throws IOException {
write(b, off, len, false);
}
public void flush() throws IOException {
drain();
out.flush();
}
public void close() throws IOException {
flush();
out.close();
}
/** {@collect.stats}
* {@description.open}
* Writes specified span of byte values from given array. If copy is
* true, copies the values to an intermediate buffer before writing
* them to underlying stream (to avoid exposing a reference to the
* original byte array).
* {@description.close}
*/
void write(byte[] b, int off, int len, boolean copy)
throws IOException
{
if (!(copy || blkmode)) { // write directly
drain();
out.write(b, off, len);
return;
}
while (len > 0) {
if (pos >= MAX_BLOCK_SIZE) {
drain();
}
if (len >= MAX_BLOCK_SIZE && !copy && pos == 0) {
// avoid unnecessary copy
writeBlockHeader(MAX_BLOCK_SIZE);
out.write(b, off, MAX_BLOCK_SIZE);
off += MAX_BLOCK_SIZE;
len -= MAX_BLOCK_SIZE;
} else {
int wlen = Math.min(len, MAX_BLOCK_SIZE - pos);
System.arraycopy(b, off, buf, pos, wlen);
pos += wlen;
off += wlen;
len -= wlen;
}
}
}
/** {@collect.stats}
* {@description.open}
* Writes all buffered data from this stream to the underlying stream,
* but does not flush underlying stream.
* {@description.close}
*/
void drain() throws IOException {
if (pos == 0) {
return;
}
if (blkmode) {
writeBlockHeader(pos);
}
out.write(buf, 0, pos);
pos = 0;
}
/** {@collect.stats}
* {@description.open}
* Writes block data header. Data blocks shorter than 256 bytes are
* prefixed with a 2-byte header; all others start with a 5-byte
* header.
* {@description.close}
*/
private void writeBlockHeader(int len) throws IOException {
if (len <= 0xFF) {
hbuf[0] = TC_BLOCKDATA;
hbuf[1] = (byte) len;
out.write(hbuf, 0, 2);
} else {
hbuf[0] = TC_BLOCKDATALONG;
Bits.putInt(hbuf, 1, len);
out.write(hbuf, 0, 5);
}
}
/* ----------------- primitive data output methods ----------------- */
/*
* The following methods are equivalent to their counterparts in
* DataOutputStream, except that they partition written data into data
* blocks when in block data mode.
*/
public void writeBoolean(boolean v) throws IOException {
if (pos >= MAX_BLOCK_SIZE) {
drain();
}
Bits.putBoolean(buf, pos++, v);
}
public void writeByte(int v) throws IOException {
if (pos >= MAX_BLOCK_SIZE) {
drain();
}
buf[pos++] = (byte) v;
}
public void writeChar(int v) throws IOException {
if (pos + 2 <= MAX_BLOCK_SIZE) {
Bits.putChar(buf, pos, (char) v);
pos += 2;
} else {
dout.writeChar(v);
}
}
public void writeShort(int v) throws IOException {
if (pos + 2 <= MAX_BLOCK_SIZE) {
Bits.putShort(buf, pos, (short) v);
pos += 2;
} else {
dout.writeShort(v);
}
}
public void writeInt(int v) throws IOException {
if (pos + 4 <= MAX_BLOCK_SIZE) {
Bits.putInt(buf, pos, v);
pos += 4;
} else {
dout.writeInt(v);
}
}
public void writeFloat(float v) throws IOException {
if (pos + 4 <= MAX_BLOCK_SIZE) {
Bits.putFloat(buf, pos, v);
pos += 4;
} else {
dout.writeFloat(v);
}
}
public void writeLong(long v) throws IOException {
if (pos + 8 <= MAX_BLOCK_SIZE) {
Bits.putLong(buf, pos, v);
pos += 8;
} else {
dout.writeLong(v);
}
}
public void writeDouble(double v) throws IOException {
if (pos + 8 <= MAX_BLOCK_SIZE) {
Bits.putDouble(buf, pos, v);
pos += 8;
} else {
dout.writeDouble(v);
}
}
public void writeBytes(String s) throws IOException {
int endoff = s.length();
int cpos = 0;
int csize = 0;
for (int off = 0; off < endoff; ) {
if (cpos >= csize) {
cpos = 0;
csize = Math.min(endoff - off, CHAR_BUF_SIZE);
s.getChars(off, off + csize, cbuf, 0);
}
if (pos >= MAX_BLOCK_SIZE) {
drain();
}
int n = Math.min(csize - cpos, MAX_BLOCK_SIZE - pos);
int stop = pos + n;
while (pos < stop) {
buf[pos++] = (byte) cbuf[cpos++];
}
off += n;
}
}
public void writeChars(String s) throws IOException {
int endoff = s.length();
for (int off = 0; off < endoff; ) {
int csize = Math.min(endoff - off, CHAR_BUF_SIZE);
s.getChars(off, off + csize, cbuf, 0);
writeChars(cbuf, 0, csize);
off += csize;
}
}
public void writeUTF(String s) throws IOException {
writeUTF(s, getUTFLength(s));
}
/* -------------- primitive data array output methods -------------- */
/*
* The following methods write out spans of primitive data values.
* Though equivalent to calling the corresponding primitive write
* methods repeatedly, these methods are optimized for writing groups
* of primitive data values more efficiently.
*/
void writeBooleans(boolean[] v, int off, int len) throws IOException {
int endoff = off + len;
while (off < endoff) {
if (pos >= MAX_BLOCK_SIZE) {
drain();
}
int stop = Math.min(endoff, off + (MAX_BLOCK_SIZE - pos));
while (off < stop) {
Bits.putBoolean(buf, pos++, v[off++]);
}
}
}
void writeChars(char[] v, int off, int len) throws IOException {
int limit = MAX_BLOCK_SIZE - 2;
int endoff = off + len;
while (off < endoff) {
if (pos <= limit) {
int avail = (MAX_BLOCK_SIZE - pos) >> 1;
int stop = Math.min(endoff, off + avail);
while (off < stop) {
Bits.putChar(buf, pos, v[off++]);
pos += 2;
}
} else {
dout.writeChar(v[off++]);
}
}
}
void writeShorts(short[] v, int off, int len) throws IOException {
int limit = MAX_BLOCK_SIZE - 2;
int endoff = off + len;
while (off < endoff) {
if (pos <= limit) {
int avail = (MAX_BLOCK_SIZE - pos) >> 1;
int stop = Math.min(endoff, off + avail);
while (off < stop) {
Bits.putShort(buf, pos, v[off++]);
pos += 2;
}
} else {
dout.writeShort(v[off++]);
}
}
}
void writeInts(int[] v, int off, int len) throws IOException {
int limit = MAX_BLOCK_SIZE - 4;
int endoff = off + len;
while (off < endoff) {
if (pos <= limit) {
int avail = (MAX_BLOCK_SIZE - pos) >> 2;
int stop = Math.min(endoff, off + avail);
while (off < stop) {
Bits.putInt(buf, pos, v[off++]);
pos += 4;
}
} else {
dout.writeInt(v[off++]);
}
}
}
void writeFloats(float[] v, int off, int len) throws IOException {
int limit = MAX_BLOCK_SIZE - 4;
int endoff = off + len;
while (off < endoff) {
if (pos <= limit) {
int avail = (MAX_BLOCK_SIZE - pos) >> 2;
int chunklen = Math.min(endoff - off, avail);
floatsToBytes(v, off, buf, pos, chunklen);
off += chunklen;
pos += chunklen << 2;
} else {
dout.writeFloat(v[off++]);
}
}
}
void writeLongs(long[] v, int off, int len) throws IOException {
int limit = MAX_BLOCK_SIZE - 8;
int endoff = off + len;
while (off < endoff) {
if (pos <= limit) {
int avail = (MAX_BLOCK_SIZE - pos) >> 3;
int stop = Math.min(endoff, off + avail);
while (off < stop) {
Bits.putLong(buf, pos, v[off++]);
pos += 8;
}
} else {
dout.writeLong(v[off++]);
}
}
}
void writeDoubles(double[] v, int off, int len) throws IOException {
int limit = MAX_BLOCK_SIZE - 8;
int endoff = off + len;
while (off < endoff) {
if (pos <= limit) {
int avail = (MAX_BLOCK_SIZE - pos) >> 3;
int chunklen = Math.min(endoff - off, avail);
doublesToBytes(v, off, buf, pos, chunklen);
off += chunklen;
pos += chunklen << 3;
} else {
dout.writeDouble(v[off++]);
}
}
}
/** {@collect.stats}
* {@description.open}
* Returns the length in bytes of the UTF encoding of the given string.
* {@description.close}
*/
long getUTFLength(String s) {
int len = s.length();
long utflen = 0;
for (int off = 0; off < len; ) {
int csize = Math.min(len - off, CHAR_BUF_SIZE);
s.getChars(off, off + csize, cbuf, 0);
for (int cpos = 0; cpos < csize; cpos++) {
char c = cbuf[cpos];
if (c >= 0x0001 && c <= 0x007F) {
utflen++;
} else if (c > 0x07FF) {
utflen += 3;
} else {
utflen += 2;
}
}
off += csize;
}
return utflen;
}
/** {@collect.stats}
* {@description.open}
* Writes the given string in UTF format. This method is used in
* situations where the UTF encoding length of the string is already
* known; specifying it explicitly avoids a prescan of the string to
* determine its UTF length.
* {@description.close}
*/
void writeUTF(String s, long utflen) throws IOException {
if (utflen > 0xFFFFL) {
throw new UTFDataFormatException();
}
writeShort((int) utflen);
if (utflen == (long) s.length()) {
writeBytes(s);
} else {
writeUTFBody(s);
}
}
/** {@collect.stats}
* {@description.open}
* Writes given string in "long" UTF format. "Long" UTF format is
* identical to standard UTF, except that it uses an 8 byte header
* (instead of the standard 2 bytes) to convey the UTF encoding length.
* {@description.close}
*/
void writeLongUTF(String s) throws IOException {
writeLongUTF(s, getUTFLength(s));
}
/** {@collect.stats}
* {@description.open}
* Writes given string in "long" UTF format, where the UTF encoding
* length of the string is already known.
* {@description.close}
*/
void writeLongUTF(String s, long utflen) throws IOException {
writeLong(utflen);
if (utflen == (long) s.length()) {
writeBytes(s);
} else {
writeUTFBody(s);
}
}
/** {@collect.stats}
* {@description.open}
* Writes the "body" (i.e., the UTF representation minus the 2-byte or
* 8-byte length header) of the UTF encoding for the given string.
* {@description.close}
*/
private void writeUTFBody(String s) throws IOException {
int limit = MAX_BLOCK_SIZE - 3;
int len = s.length();
for (int off = 0; off < len; ) {
int csize = Math.min(len - off, CHAR_BUF_SIZE);
s.getChars(off, off + csize, cbuf, 0);
for (int cpos = 0; cpos < csize; cpos++) {
char c = cbuf[cpos];
if (pos <= limit) {
if (c <= 0x007F && c != 0) {
buf[pos++] = (byte) c;
} else if (c > 0x07FF) {
buf[pos + 2] = (byte) (0x80 | ((c >> 0) & 0x3F));
buf[pos + 1] = (byte) (0x80 | ((c >> 6) & 0x3F));
buf[pos + 0] = (byte) (0xE0 | ((c >> 12) & 0x0F));
pos += 3;
} else {
buf[pos + 1] = (byte) (0x80 | ((c >> 0) & 0x3F));
buf[pos + 0] = (byte) (0xC0 | ((c >> 6) & 0x1F));
pos += 2;
}
} else { // write one byte at a time to normalize block
if (c <= 0x007F && c != 0) {
write(c);
} else if (c > 0x07FF) {
write(0xE0 | ((c >> 12) & 0x0F));
write(0x80 | ((c >> 6) & 0x3F));
write(0x80 | ((c >> 0) & 0x3F));
} else {
write(0xC0 | ((c >> 6) & 0x1F));
write(0x80 | ((c >> 0) & 0x3F));
}
}
}
off += csize;
}
}
}
/** {@collect.stats}
* {@description.open}
* Lightweight identity hash table which maps objects to integer handles,
* assigned in ascending order.
* {@description.close}
*/
private static class HandleTable {
/* number of mappings in table/next available handle */
private int size;
/* size threshold determining when to expand hash spine */
private int threshold;
/* factor for computing size threshold */
private final float loadFactor;
/* maps hash value -> candidate handle value */
private int[] spine;
/* maps handle value -> next candidate handle value */
private int[] next;
/* maps handle value -> associated object */
private Object[] objs;
/** {@collect.stats}
* {@description.open}
* Creates new HandleTable with given capacity and load factor.
* {@description.close}
*/
HandleTable(int initialCapacity, float loadFactor) {
this.loadFactor = loadFactor;
spine = new int[initialCapacity];
next = new int[initialCapacity];
objs = new Object[initialCapacity];
threshold = (int) (initialCapacity * loadFactor);
clear();
}
/** {@collect.stats}
* {@description.open}
* Assigns next available handle to given object, and returns handle
* value. Handles are assigned in ascending order starting at 0.
* {@description.close}
*/
int assign(Object obj) {
if (size >= next.length) {
growEntries();
}
if (size >= threshold) {
growSpine();
}
insert(obj, size);
return size++;
}
/** {@collect.stats}
* {@description.open}
* Looks up and returns handle associated with given object, or -1 if
* no mapping found.
* {@description.close}
*/
int lookup(Object obj) {
if (size == 0) {
return -1;
}
int index = hash(obj) % spine.length;
for (int i = spine[index]; i >= 0; i = next[i]) {
if (objs[i] == obj) {
return i;
}
}
return -1;
}
/** {@collect.stats}
* {@description.open}
* Resets table to its initial (empty) state.
* {@description.close}
*/
void clear() {
Arrays.fill(spine, -1);
Arrays.fill(objs, 0, size, null);
size = 0;
}
/** {@collect.stats}
* {@description.open}
* Returns the number of mappings currently in table.
* {@description.close}
*/
int size() {
return size;
}
/** {@collect.stats}
* {@description.open}
* Inserts mapping object -> handle mapping into table. Assumes table
* is large enough to accommodate new mapping.
* {@description.close}
*/
private void insert(Object obj, int handle) {
int index = hash(obj) % spine.length;
objs[handle] = obj;
next[handle] = spine[index];
spine[index] = handle;
}
/** {@collect.stats}
* {@description.open}
* Expands the hash "spine" -- equivalent to increasing the number of
* buckets in a conventional hash table.
* {@description.close}
*/
private void growSpine() {
spine = new int[(spine.length << 1) + 1];
threshold = (int) (spine.length * loadFactor);
Arrays.fill(spine, -1);
for (int i = 0; i < size; i++) {
insert(objs[i], i);
}
}
/** {@collect.stats}
* {@description.open}
* Increases hash table capacity by lengthening entry arrays.
* {@description.close}
*/
private void growEntries() {
int newLength = (next.length << 1) + 1;
int[] newNext = new int[newLength];
System.arraycopy(next, 0, newNext, 0, size);
next = newNext;
Object[] newObjs = new Object[newLength];
System.arraycopy(objs, 0, newObjs, 0, size);
objs = newObjs;
}
/** {@collect.stats}
* {@description.open}
* Returns hash value for given object.
* {@description.close}
*/
private int hash(Object obj) {
return System.identityHashCode(obj) & 0x7FFFFFFF;
}
}
/** {@collect.stats}
* {@description.open}
* Lightweight identity hash table which maps objects to replacement
* objects.
* {@description.close}
*/
private static class ReplaceTable {
/* maps object -> index */
private final HandleTable htab;
/* maps index -> replacement object */
private Object[] reps;
/** {@collect.stats}
* {@description.open}
* Creates new ReplaceTable with given capacity and load factor.
* {@description.close}
*/
ReplaceTable(int initialCapacity, float loadFactor) {
htab = new HandleTable(initialCapacity, loadFactor);
reps = new Object[initialCapacity];
}
/** {@collect.stats}
* {@description.open}
* Enters mapping from object to replacement object.
* {@description.close}
*/
void assign(Object obj, Object rep) {
int index = htab.assign(obj);
while (index >= reps.length) {
grow();
}
reps[index] = rep;
}
/** {@collect.stats}
* {@description.open}
* Looks up and returns replacement for given object. If no
* replacement is found, returns the lookup object itself.
* {@description.close}
*/
Object lookup(Object obj) {
int index = htab.lookup(obj);
return (index >= 0) ? reps[index] : obj;
}
/** {@collect.stats}
* {@description.open}
* Resets table to its initial (empty) state.
* {@description.close}
*/
void clear() {
Arrays.fill(reps, 0, htab.size(), null);
htab.clear();
}
/** {@collect.stats}
* {@description.open}
* Returns the number of mappings currently in table.
* {@description.close}
*/
int size() {
return htab.size();
}
/** {@collect.stats}
* {@description.open}
* Increases table capacity.
* {@description.close}
*/
private void grow() {
Object[] newReps = new Object[(reps.length << 1) + 1];
System.arraycopy(reps, 0, newReps, 0, reps.length);
reps = newReps;
}
}
/** {@collect.stats}
* {@description.open}
* Stack to keep debug information about the state of the
* serialization process, for embedding in exception messages.
* {@description.close}
*/
private static class DebugTraceInfoStack {
private final List<String> stack;
DebugTraceInfoStack() {
stack = new ArrayList<String>();
}
/** {@collect.stats}
* {@description.open}
* Removes all of the elements from enclosed list.
* {@description.close}
*/
void clear() {
stack.clear();
}
/** {@collect.stats}
* {@description.open}
* Removes the object at the top of enclosed list.
* {@description.close}
*/
void pop() {
stack.remove(stack.size()-1);
}
/** {@collect.stats}
* {@description.open}
* Pushes a String onto the top of enclosed list.
* {@description.close}
*/
void push(String entry) {
stack.add("\t- " + entry);
}
/** {@collect.stats}
* {@description.open}
* Returns a string representation of this object
* {@description.close}
*/
public String toString() {
StringBuilder buffer = new StringBuilder();
if (!stack.isEmpty()) {
for(int i = stack.size(); i > 0; i-- ) {
buffer.append(stack.get(i-1) + ((i != 1) ? "\n" : ""));
}
}
return buffer.toString();
}
}
}
|
Java
|
/*
* Copyright (c) 1996, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.io.ObjectOutput;
import java.io.ObjectInput;
/** {@collect.stats}
* {@property.open}
* Only the identity of the class of an Externalizable instance is
* written in the serialization stream and it is the responsibility
* of the class to save and restore the contents of its instances.
*
* The writeExternal and readExternal methods of the Externalizable
* interface are implemented by a class to give the class complete
* control over the format and contents of the stream for an object
* and its supertypes. These methods must explicitly
* coordinate with the supertype to save its state. These methods supersede
* customized implementations of writeObject and readObject methods.<br>
*
* Object Serialization uses the Serializable and Externalizable
* interfaces. Object persistence mechanisms can use them as well. Each
* object to be stored is tested for the Externalizable interface. If
* the object supports Externalizable, the writeExternal method is called. If the
* object does not support Externalizable and does implement
* Serializable, the object is saved using
* ObjectOutputStream. <br> When an Externalizable object is
* reconstructed, an instance is created using the public no-arg
* constructor, then the readExternal method called. Serializable
* objects are restored by reading them from an ObjectInputStream.<br>
* {@property.close}
*
* {@description.open}
* An Externalizable instance can designate a substitution object via
* the writeReplace and readResolve methods documented in the Serializable
* interface.<br>
* {@description.close}
*
* @author unascribed
* @see java.io.ObjectOutputStream
* @see java.io.ObjectInputStream
* @see java.io.ObjectOutput
* @see java.io.ObjectInput
* @see java.io.Serializable
* @since JDK1.1
*/
public interface Externalizable extends java.io.Serializable {
/** {@collect.stats}
* {@description.open}
* The object implements the writeExternal method to save its contents
* by calling the methods of DataOutput for its primitive values or
* calling the writeObject method of ObjectOutput for objects, strings,
* and arrays.
* {@description.close}
*
* @serialData Overriding methods should use this tag to describe
* the data layout of this Externalizable object.
* List the sequence of element types and, if possible,
* relate the element to a public/protected field and/or
* method of this Externalizable class.
*
* @param out the stream to write the object to
* @exception IOException Includes any I/O exceptions that may occur
*/
void writeExternal(ObjectOutput out) throws IOException;
/** {@collect.stats}
* {@description.open}
* The object implements the readExternal method to restore its
* contents by calling the methods of DataInput for primitive
* types and readObject for objects, strings and arrays. The
* readExternal method must read the values in the same sequence
* and with the same types as were written by writeExternal.
* {@description.close}
*
* @param in the stream to read data from in order to restore the object
* @exception IOException if I/O errors occur
* @exception ClassNotFoundException If the class for an object being
* restored cannot be found.
*/
void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
}
|
Java
|
/*
* Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* The <code>DataOutput</code> interface provides
* for converting data from any of the Java
* primitive types to a series of bytes and
* writing these bytes to a binary stream.
* There is also a facility for converting
* a <code>String</code> into
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
* format and writing the resulting series
* of bytes.
* <p>
* For all the methods in this interface that
* write bytes, it is generally true that if
* a byte cannot be written for any reason,
* an <code>IOException</code> is thrown.
* {@description.close}
*
* @author Frank Yellin
* @see java.io.DataInput
* @see java.io.DataOutputStream
* @since JDK1.0
*/
public
interface DataOutput {
/** {@collect.stats}
* {@description.open}
* Writes to the output stream the eight
* low-order bits of the argument <code>b</code>.
* The 24 high-order bits of <code>b</code>
* are ignored.
* {@description.close}
*
* @param b the byte to be written.
* @throws IOException if an I/O error occurs.
*/
void write(int b) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes to the output stream all the bytes in array <code>b</code>.
* If <code>b</code> is <code>null</code>,
* a <code>NullPointerException</code> is thrown.
* If <code>b.length</code> is zero, then
* no bytes are written. Otherwise, the byte
* <code>b[0]</code> is written first, then
* <code>b[1]</code>, and so on; the last byte
* written is <code>b[b.length-1]</code>.
* {@description.close}
*
* @param b the data.
* @throws IOException if an I/O error occurs.
*/
void write(byte b[]) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes <code>len</code> bytes from array
* <code>b</code>, in order, to
* the output stream. If <code>b</code>
* is <code>null</code>, a <code>NullPointerException</code>
* is thrown. If <code>off</code> is negative,
* or <code>len</code> is negative, or <code>off+len</code>
* is greater than the length of the array
* <code>b</code>, then an <code>IndexOutOfBoundsException</code>
* is thrown. If <code>len</code> is zero,
* then no bytes are written. Otherwise, the
* byte <code>b[off]</code> is written first,
* then <code>b[off+1]</code>, and so on; the
* last byte written is <code>b[off+len-1]</code>.
* {@description.close}
*
* @param b the data.
* @param off the start offset in the data.
* @param len the number of bytes to write.
* @throws IOException if an I/O error occurs.
*/
void write(byte b[], int off, int len) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes a <code>boolean</code> value to this output stream.
* If the argument <code>v</code>
* is <code>true</code>, the value <code>(byte)1</code>
* is written; if <code>v</code> is <code>false</code>,
* the value <code>(byte)0</code> is written.
* The byte written by this method may
* be read by the <code>readBoolean</code>
* method of interface <code>DataInput</code>,
* which will then return a <code>boolean</code>
* equal to <code>v</code>.
* {@description.close}
*
* @param v the boolean to be written.
* @throws IOException if an I/O error occurs.
*/
void writeBoolean(boolean v) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes to the output stream the eight low-
* order bits of the argument <code>v</code>.
* The 24 high-order bits of <code>v</code>
* are ignored. (This means that <code>writeByte</code>
* does exactly the same thing as <code>write</code>
* for an integer argument.) The byte written
* by this method may be read by the <code>readByte</code>
* method of interface <code>DataInput</code>,
* which will then return a <code>byte</code>
* equal to <code>(byte)v</code>.
* {@description.close}
*
* @param v the byte value to be written.
* @throws IOException if an I/O error occurs.
*/
void writeByte(int v) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes two bytes to the output
* stream to represent the value of the argument.
* The byte values to be written, in the order
* shown, are: <p>
* <pre><code>
* (byte)(0xff & (v >> 8))
* (byte)(0xff & v)
* </code> </pre> <p>
* The bytes written by this method may be
* read by the <code>readShort</code> method
* of interface <code>DataInput</code> , which
* will then return a <code>short</code> equal
* to <code>(short)v</code>.
* {@description.close}
*
* @param v the <code>short</code> value to be written.
* @throws IOException if an I/O error occurs.
*/
void writeShort(int v) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes a <code>char</code> value, which
* is comprised of two bytes, to the
* output stream.
* The byte values to be written, in the order
* shown, are:
* <p><pre><code>
* (byte)(0xff & (v >> 8))
* (byte)(0xff & v)
* </code></pre><p>
* The bytes written by this method may be
* read by the <code>readChar</code> method
* of interface <code>DataInput</code> , which
* will then return a <code>char</code> equal
* to <code>(char)v</code>.
* {@description.close}
*
* @param v the <code>char</code> value to be written.
* @throws IOException if an I/O error occurs.
*/
void writeChar(int v) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes an <code>int</code> value, which is
* comprised of four bytes, to the output stream.
* The byte values to be written, in the order
* shown, are:
* <p><pre><code>
* (byte)(0xff & (v >> 24))
* (byte)(0xff & (v >> 16))
* (byte)(0xff & (v >>    8))
* (byte)(0xff & v)
* </code></pre><p>
* The bytes written by this method may be read
* by the <code>readInt</code> method of interface
* <code>DataInput</code> , which will then
* return an <code>int</code> equal to <code>v</code>.
* {@description.close}
*
* @param v the <code>int</code> value to be written.
* @throws IOException if an I/O error occurs.
*/
void writeInt(int v) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes a <code>long</code> value, which is
* comprised of eight bytes, to the output stream.
* The byte values to be written, in the order
* shown, are:
* <p><pre><code>
* (byte)(0xff & (v >> 56))
* (byte)(0xff & (v >> 48))
* (byte)(0xff & (v >> 40))
* (byte)(0xff & (v >> 32))
* (byte)(0xff & (v >> 24))
* (byte)(0xff & (v >> 16))
* (byte)(0xff & (v >> 8))
* (byte)(0xff & v)
* </code></pre><p>
* The bytes written by this method may be
* read by the <code>readLong</code> method
* of interface <code>DataInput</code> , which
* will then return a <code>long</code> equal
* to <code>v</code>.
* {@description.close}
*
* @param v the <code>long</code> value to be written.
* @throws IOException if an I/O error occurs.
*/
void writeLong(long v) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes a <code>float</code> value,
* which is comprised of four bytes, to the output stream.
* It does this as if it first converts this
* <code>float</code> value to an <code>int</code>
* in exactly the manner of the <code>Float.floatToIntBits</code>
* method and then writes the <code>int</code>
* value in exactly the manner of the <code>writeInt</code>
* method. The bytes written by this method
* may be read by the <code>readFloat</code>
* method of interface <code>DataInput</code>,
* which will then return a <code>float</code>
* equal to <code>v</code>.
* {@description.close}
*
* @param v the <code>float</code> value to be written.
* @throws IOException if an I/O error occurs.
*/
void writeFloat(float v) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes a <code>double</code> value,
* which is comprised of eight bytes, to the output stream.
* It does this as if it first converts this
* <code>double</code> value to a <code>long</code>
* in exactly the manner of the <code>Double.doubleToLongBits</code>
* method and then writes the <code>long</code>
* value in exactly the manner of the <code>writeLong</code>
* method. The bytes written by this method
* may be read by the <code>readDouble</code>
* method of interface <code>DataInput</code>,
* which will then return a <code>double</code>
* equal to <code>v</code>.
* {@description.close}
*
* @param v the <code>double</code> value to be written.
* @throws IOException if an I/O error occurs.
*/
void writeDouble(double v) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes a string to the output stream.
* For every character in the string
* <code>s</code>, taken in order, one byte
* is written to the output stream. If
* <code>s</code> is <code>null</code>, a <code>NullPointerException</code>
* is thrown.<p> If <code>s.length</code>
* is zero, then no bytes are written. Otherwise,
* the character <code>s[0]</code> is written
* first, then <code>s[1]</code>, and so on;
* the last character written is <code>s[s.length-1]</code>.
* For each character, one byte is written,
* the low-order byte, in exactly the manner
* of the <code>writeByte</code> method . The
* high-order eight bits of each character
* in the string are ignored.
* {@description.close}
*
* @param s the string of bytes to be written.
* @throws IOException if an I/O error occurs.
*/
void writeBytes(String s) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes every character in the string <code>s</code>,
* to the output stream, in order,
* two bytes per character. If <code>s</code>
* is <code>null</code>, a <code>NullPointerException</code>
* is thrown. If <code>s.length</code>
* is zero, then no characters are written.
* Otherwise, the character <code>s[0]</code>
* is written first, then <code>s[1]</code>,
* and so on; the last character written is
* <code>s[s.length-1]</code>. For each character,
* two bytes are actually written, high-order
* byte first, in exactly the manner of the
* <code>writeChar</code> method.
* {@description.close}
*
* @param s the string value to be written.
* @throws IOException if an I/O error occurs.
*/
void writeChars(String s) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes two bytes of length information
* to the output stream, followed
* by the
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
* representation
* of every character in the string <code>s</code>.
* If <code>s</code> is <code>null</code>,
* a <code>NullPointerException</code> is thrown.
* Each character in the string <code>s</code>
* is converted to a group of one, two, or
* three bytes, depending on the value of the
* character.<p>
* If a character <code>c</code>
* is in the range <code>\u0001</code> through
* <code>\u007f</code>, it is represented
* by one byte:<p>
* <pre>(byte)c </pre> <p>
* If a character <code>c</code> is <code>\u0000</code>
* or is in the range <code>\u0080</code>
* through <code>\u07ff</code>, then it is
* represented by two bytes, to be written
* in the order shown:<p> <pre><code>
* (byte)(0xc0 | (0x1f & (c >> 6)))
* (byte)(0x80 | (0x3f & c))
* </code></pre> <p> If a character
* <code>c</code> is in the range <code>\u0800</code>
* through <code>uffff</code>, then it is
* represented by three bytes, to be written
* in the order shown:<p> <pre><code>
* (byte)(0xe0 | (0x0f & (c >> 12)))
* (byte)(0x80 | (0x3f & (c >> 6)))
* (byte)(0x80 | (0x3f & c))
* </code></pre> <p> First,
* the total number of bytes needed to represent
* all the characters of <code>s</code> is
* calculated. If this number is larger than
* <code>65535</code>, then a <code>UTFDataFormatException</code>
* is thrown. Otherwise, this length is written
* to the output stream in exactly the manner
* of the <code>writeShort</code> method;
* after this, the one-, two-, or three-byte
* representation of each character in the
* string <code>s</code> is written.<p> The
* bytes written by this method may be read
* by the <code>readUTF</code> method of interface
* <code>DataInput</code> , which will then
* return a <code>String</code> equal to <code>s</code>.
* {@description.close}
*
* @param s the string value to be written.
* @throws IOException if an I/O error occurs.
*/
void writeUTF(String s) throws IOException;
}
|
Java
|
/*
* Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* A data input stream lets an application read primitive Java data
* types from an underlying input stream in a machine-independent
* way. An application uses a data output stream to write data that
* can later be read by a data input stream.
* {@description.close}
* {@property.open}
* <p>
* DataInputStream is not necessarily safe for multithreaded access.
* Thread safety is optional and is the responsibility of users of
* methods in this class.
* {@property.close}
*
* @author Arthur van Hoff
* @see java.io.DataOutputStream
* @since JDK1.0
*/
public
class DataInputStream extends FilterInputStream implements DataInput {
/** {@collect.stats}
* {@description.open}
* Creates a DataInputStream that uses the specified
* underlying InputStream.
* {@description.close}
*
* @param in the specified input stream
*/
public DataInputStream(InputStream in) {
super(in);
}
/** {@collect.stats}
* {@description.open}
* working arrays initialized on demand by readUTF
* {@description.close}
*/
private byte bytearr[] = new byte[80];
private char chararr[] = new char[80];
/** {@collect.stats}
* {@description.open}
* Reads some number of bytes from the contained input stream and
* stores them into the buffer array <code>b</code>. The number of
* bytes actually read is returned as an integer. This method blocks
* until input data is available, end of file is detected, or an
* exception is thrown.
*
* <p>If <code>b</code> is null, a <code>NullPointerException</code> is
* thrown. If the length of <code>b</code> is zero, then no bytes are
* read and <code>0</code> is returned; otherwise, there is an attempt
* to read at least one byte. If no byte is available because the
* stream is at end of file, the value <code>-1</code> is returned;
* otherwise, at least one byte is read and stored into <code>b</code>.
*
* <p>The first byte read is stored into element <code>b[0]</code>, the
* next one into <code>b[1]</code>, and so on. The number of bytes read
* is, at most, equal to the length of <code>b</code>. Let <code>k</code>
* be the number of bytes actually read; these bytes will be stored in
* elements <code>b[0]</code> through <code>b[k-1]</code>, leaving
* elements <code>b[k]</code> through <code>b[b.length-1]</code>
* unaffected.
*
* <p>The <code>read(b)</code> method has the same effect as:
* <blockquote><pre>
* read(b, 0, b.length)
* </pre></blockquote>
* {@description.close}
*
* @param b the buffer into which the data is read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end
* of the stream has been reached.
* @exception IOException if the first byte cannot be read for any reason
* other than end of file, the stream has been closed and the underlying
* input stream does not support reading after close, or another I/O
* error occurs.
* @see java.io.FilterInputStream#in
* @see java.io.InputStream#read(byte[], int, int)
*/
public final int read(byte b[]) throws IOException {
return in.read(b, 0, b.length);
}
/** {@collect.stats}
* {@description.open}
* Reads up to <code>len</code> bytes of data from the contained
* input stream into an array of bytes. An attempt is made to read
* as many as <code>len</code> bytes, but a smaller number may be read,
* possibly zero. The number of bytes actually read is returned as an
* integer.
* {@description.close}
*
* {@description.open blocking}
* <p> This method blocks until input data is available, end of file is
* detected, or an exception is thrown.
* {@description.close}
*
* {@description.open}
* <p> If <code>len</code> is zero, then no bytes are read and
* <code>0</code> is returned; otherwise, there is an attempt to read at
* least one byte. If no byte is available because the stream is at end of
* file, the value <code>-1</code> is returned; otherwise, at least one
* byte is read and stored into <code>b</code>.
*
* <p> The first byte read is stored into element <code>b[off]</code>, the
* next one into <code>b[off+1]</code>, and so on. The number of bytes read
* is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
* bytes actually read; these bytes will be stored in elements
* <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
* leaving elements <code>b[off+</code><i>k</i><code>]</code> through
* <code>b[off+len-1]</code> unaffected.
*
* <p> In every case, elements <code>b[0]</code> through
* <code>b[off]</code> and elements <code>b[off+len]</code> through
* <code>b[b.length-1]</code> are unaffected.
* {@description.close}
*
* @param b the buffer into which the data is read.
* @param off the start offset in the destination array <code>b</code>
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end
* of the stream has been reached.
* @exception NullPointerException If <code>b</code> is <code>null</code>.
* @exception IndexOutOfBoundsException If <code>off</code> is negative,
* <code>len</code> is negative, or <code>len</code> is greater than
* <code>b.length - off</code>
* @exception IOException if the first byte cannot be read for any reason
* other than end of file, the stream has been closed and the underlying
* input stream does not support reading after close, or another I/O
* error occurs.
* @see java.io.FilterInputStream#in
* @see java.io.InputStream#read(byte[], int, int)
*/
public final int read(byte b[], int off, int len) throws IOException {
return in.read(b, off, len);
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readFully</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @param b the buffer into which the data is read.
* @exception EOFException if this input stream reaches the end before
* reading all the bytes.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public final void readFully(byte b[]) throws IOException {
readFully(b, 0, b.length);
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readFully</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @param b the buffer into which the data is read.
* @param off the start offset of the data.
* @param len the number of bytes to read.
* @exception EOFException if this input stream reaches the end before
* reading all the bytes.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public final void readFully(byte b[], int off, int len) throws IOException {
if (len < 0)
throw new IndexOutOfBoundsException();
int n = 0;
while (n < len) {
int count = in.read(b, off + n, len - n);
if (count < 0)
throw new EOFException();
n += count;
}
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>skipBytes</code>
* method of <code>DataInput</code>.
* <p>
* Bytes for this operation are read from the contained
* input stream.
* {@description.close}
*
* @param n the number of bytes to be skipped.
* @return the actual number of bytes skipped.
* @exception IOException if the contained input stream does not support
* seek, or the stream has been closed and
* the contained input stream does not support
* reading after close, or another I/O error occurs.
*/
public final int skipBytes(int n) throws IOException {
int total = 0;
int cur = 0;
while ((total<n) && ((cur = (int) in.skip(n-total)) > 0)) {
total += cur;
}
return total;
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readBoolean</code>
* method of <code>DataInput</code>.
* <p>
* Bytes for this operation are read from the contained
* input stream.
* {@description.close}
*
* @return the <code>boolean</code> value read.
* @exception EOFException if this input stream has reached the end.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public final boolean readBoolean() throws IOException {
int ch = in.read();
if (ch < 0)
throw new EOFException();
return (ch != 0);
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readByte</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @return the next byte of this input stream as a signed 8-bit
* <code>byte</code>.
* @exception EOFException if this input stream has reached the end.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public final byte readByte() throws IOException {
int ch = in.read();
if (ch < 0)
throw new EOFException();
return (byte)(ch);
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readUnsignedByte</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @return the next byte of this input stream, interpreted as an
* unsigned 8-bit number.
* @exception EOFException if this input stream has reached the end.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public final int readUnsignedByte() throws IOException {
int ch = in.read();
if (ch < 0)
throw new EOFException();
return ch;
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readShort</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @return the next two bytes of this input stream, interpreted as a
* signed 16-bit number.
* @exception EOFException if this input stream reaches the end before
* reading two bytes.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public final short readShort() throws IOException {
int ch1 = in.read();
int ch2 = in.read();
if ((ch1 | ch2) < 0)
throw new EOFException();
return (short)((ch1 << 8) + (ch2 << 0));
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readUnsignedShort</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @return the next two bytes of this input stream, interpreted as an
* unsigned 16-bit integer.
* @exception EOFException if this input stream reaches the end before
* reading two bytes.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public final int readUnsignedShort() throws IOException {
int ch1 = in.read();
int ch2 = in.read();
if ((ch1 | ch2) < 0)
throw new EOFException();
return (ch1 << 8) + (ch2 << 0);
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readChar</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @return the next two bytes of this input stream, interpreted as a
* <code>char</code>.
* @exception EOFException if this input stream reaches the end before
* reading two bytes.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public final char readChar() throws IOException {
int ch1 = in.read();
int ch2 = in.read();
if ((ch1 | ch2) < 0)
throw new EOFException();
return (char)((ch1 << 8) + (ch2 << 0));
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readInt</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @return the next four bytes of this input stream, interpreted as an
* <code>int</code>.
* @exception EOFException if this input stream reaches the end before
* reading four bytes.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public final int readInt() throws IOException {
int ch1 = in.read();
int ch2 = in.read();
int ch3 = in.read();
int ch4 = in.read();
if ((ch1 | ch2 | ch3 | ch4) < 0)
throw new EOFException();
return ((ch1 << 24) + (ch2 << 16) + (ch3 << 8) + (ch4 << 0));
}
private byte readBuffer[] = new byte[8];
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readLong</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @return the next eight bytes of this input stream, interpreted as a
* <code>long</code>.
* @exception EOFException if this input stream reaches the end before
* reading eight bytes.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public final long readLong() throws IOException {
readFully(readBuffer, 0, 8);
return (((long)readBuffer[0] << 56) +
((long)(readBuffer[1] & 255) << 48) +
((long)(readBuffer[2] & 255) << 40) +
((long)(readBuffer[3] & 255) << 32) +
((long)(readBuffer[4] & 255) << 24) +
((readBuffer[5] & 255) << 16) +
((readBuffer[6] & 255) << 8) +
((readBuffer[7] & 255) << 0));
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readFloat</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @return the next four bytes of this input stream, interpreted as a
* <code>float</code>.
* @exception EOFException if this input stream reaches the end before
* reading four bytes.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @see java.io.DataInputStream#readInt()
* @see java.lang.Float#intBitsToFloat(int)
*/
public final float readFloat() throws IOException {
return Float.intBitsToFloat(readInt());
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readDouble</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @return the next eight bytes of this input stream, interpreted as a
* <code>double</code>.
* @exception EOFException if this input stream reaches the end before
* reading eight bytes.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @see java.io.DataInputStream#readLong()
* @see java.lang.Double#longBitsToDouble(long)
*/
public final double readDouble() throws IOException {
return Double.longBitsToDouble(readLong());
}
private char lineBuffer[];
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readLine</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @deprecated This method does not properly convert bytes to characters.
* As of JDK 1.1, the preferred way to read lines of text is via the
* <code>BufferedReader.readLine()</code> method. Programs that use the
* <code>DataInputStream</code> class to read lines can be converted to use
* the <code>BufferedReader</code> class by replacing code of the form:
* <blockquote><pre>
* DataInputStream d = new DataInputStream(in);
* </pre></blockquote>
* with:
* <blockquote><pre>
* BufferedReader d
* = new BufferedReader(new InputStreamReader(in));
* </pre></blockquote>
*
* @return the next line of text from this input stream.
* @exception IOException if an I/O error occurs.
* @see java.io.BufferedReader#readLine()
* @see java.io.FilterInputStream#in
*/
@Deprecated
public final String readLine() throws IOException {
char buf[] = lineBuffer;
if (buf == null) {
buf = lineBuffer = new char[128];
}
int room = buf.length;
int offset = 0;
int c;
loop: while (true) {
switch (c = in.read()) {
case -1:
case '\n':
break loop;
case '\r':
int c2 = in.read();
if ((c2 != '\n') && (c2 != -1)) {
if (!(in instanceof PushbackInputStream)) {
this.in = new PushbackInputStream(in);
}
((PushbackInputStream)in).unread(c2);
}
break loop;
default:
if (--room < 0) {
buf = new char[offset + 128];
room = buf.length - offset - 1;
System.arraycopy(lineBuffer, 0, buf, 0, offset);
lineBuffer = buf;
}
buf[offset++] = (char) c;
break;
}
}
if ((c == -1) && (offset == 0)) {
return null;
}
return String.copyValueOf(buf, 0, offset);
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>readUTF</code>
* method of <code>DataInput</code>.
* <p>
* Bytes
* for this operation are read from the contained
* input stream.
* {@description.close}
*
* @return a Unicode string.
* @exception EOFException if this input stream reaches the end before
* reading all the bytes.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @exception UTFDataFormatException if the bytes do not represent a valid
* modified UTF-8 encoding of a string.
* @see java.io.DataInputStream#readUTF(java.io.DataInput)
*/
public final String readUTF() throws IOException {
return readUTF(this);
}
/** {@collect.stats}
* {@description.open}
* Reads from the
* stream <code>in</code> a representation
* of a Unicode character string encoded in
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a> format;
* this string of characters is then returned as a <code>String</code>.
* The details of the modified UTF-8 representation
* are exactly the same as for the <code>readUTF</code>
* method of <code>DataInput</code>.
* {@description.close}
*
* @param in a data input stream.
* @return a Unicode string.
* @exception EOFException if the input stream reaches the end
* before all the bytes.
* @exception IOException the stream has been closed and the contained
* input stream does not support reading after close, or
* another I/O error occurs.
* @exception UTFDataFormatException if the bytes do not represent a
* valid modified UTF-8 encoding of a Unicode string.
* @see java.io.DataInputStream#readUnsignedShort()
*/
public final static String readUTF(DataInput in) throws IOException {
int utflen = in.readUnsignedShort();
byte[] bytearr = null;
char[] chararr = null;
if (in instanceof DataInputStream) {
DataInputStream dis = (DataInputStream)in;
if (dis.bytearr.length < utflen){
dis.bytearr = new byte[utflen*2];
dis.chararr = new char[utflen*2];
}
chararr = dis.chararr;
bytearr = dis.bytearr;
} else {
bytearr = new byte[utflen];
chararr = new char[utflen];
}
int c, char2, char3;
int count = 0;
int chararr_count=0;
in.readFully(bytearr, 0, utflen);
while (count < utflen) {
c = (int) bytearr[count] & 0xff;
if (c > 127) break;
count++;
chararr[chararr_count++]=(char)c;
}
while (count < utflen) {
c = (int) bytearr[count] & 0xff;
switch (c >> 4) {
case 0: case 1: case 2: case 3: case 4: case 5: case 6: case 7:
/* 0xxxxxxx*/
count++;
chararr[chararr_count++]=(char)c;
break;
case 12: case 13:
/* 110x xxxx 10xx xxxx*/
count += 2;
if (count > utflen)
throw new UTFDataFormatException(
"malformed input: partial character at end");
char2 = (int) bytearr[count-1];
if ((char2 & 0xC0) != 0x80)
throw new UTFDataFormatException(
"malformed input around byte " + count);
chararr[chararr_count++]=(char)(((c & 0x1F) << 6) |
(char2 & 0x3F));
break;
case 14:
/* 1110 xxxx 10xx xxxx 10xx xxxx */
count += 3;
if (count > utflen)
throw new UTFDataFormatException(
"malformed input: partial character at end");
char2 = (int) bytearr[count-2];
char3 = (int) bytearr[count-1];
if (((char2 & 0xC0) != 0x80) || ((char3 & 0xC0) != 0x80))
throw new UTFDataFormatException(
"malformed input around byte " + (count-1));
chararr[chararr_count++]=(char)(((c & 0x0F) << 12) |
((char2 & 0x3F) << 6) |
((char3 & 0x3F) << 0));
break;
default:
/* 10xx xxxx, 1111 xxxx */
throw new UTFDataFormatException(
"malformed input around byte " + count);
}
}
// The number of chars produced may be less than utflen
return new String(chararr, 0, chararr_count);
}
}
|
Java
|
/*
* Copyright (c) 2002, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.util.Iterator;
import java.util.Map;
import java.util.LinkedHashMap;
import java.util.Set;
class ExpiringCache {
private long millisUntilExpiration;
private Map map;
// Clear out old entries every few queries
private int queryCount;
private int queryOverflow = 300;
private int MAX_ENTRIES = 200;
static class Entry {
private long timestamp;
private String val;
Entry(long timestamp, String val) {
this.timestamp = timestamp;
this.val = val;
}
long timestamp() { return timestamp; }
void setTimestamp(long timestamp) { this.timestamp = timestamp; }
String val() { return val; }
void setVal(String val) { this.val = val; }
}
ExpiringCache() {
this(30000);
}
ExpiringCache(long millisUntilExpiration) {
this.millisUntilExpiration = millisUntilExpiration;
map = new LinkedHashMap() {
protected boolean removeEldestEntry(Map.Entry eldest) {
return size() > MAX_ENTRIES;
}
};
}
synchronized String get(String key) {
if (++queryCount >= queryOverflow) {
cleanup();
}
Entry entry = entryFor(key);
if (entry != null) {
return entry.val();
}
return null;
}
synchronized void put(String key, String val) {
if (++queryCount >= queryOverflow) {
cleanup();
}
Entry entry = entryFor(key);
if (entry != null) {
entry.setTimestamp(System.currentTimeMillis());
entry.setVal(val);
} else {
map.put(key, new Entry(System.currentTimeMillis(), val));
}
}
synchronized void clear() {
map.clear();
}
private Entry entryFor(String key) {
Entry entry = (Entry) map.get(key);
if (entry != null) {
long delta = System.currentTimeMillis() - entry.timestamp();
if (delta < 0 || delta >= millisUntilExpiration) {
map.remove(key);
entry = null;
}
}
return entry;
}
private void cleanup() {
Set keySet = map.keySet();
// Avoid ConcurrentModificationExceptions
String[] keys = new String[keySet.size()];
int i = 0;
for (Iterator iter = keySet.iterator(); iter.hasNext(); ) {
String key = (String) iter.next();
keys[i++] = key;
}
for (int j = 0; j < keys.length; j++) {
entryFor(keys[j]);
}
queryCount = 0;
}
}
|
Java
|
/*
* Copyright (c) 1994, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* A <code>ByteArrayInputStream</code> contains
* an internal buffer that contains bytes that
* may be read from the stream. An internal
* counter keeps track of the next byte to
* be supplied by the <code>read</code> method.
* {@description.close}
* {@property.open runtime formal:java.io.Closeable_MeaninglessClose}
* <p>
* Closing a <tt>ByteArrayInputStream</tt> has no effect. The methods in
* this class can be called after the stream has been closed without
* generating an <tt>IOException</tt>.
* {@property.close}
*
* @author Arthur van Hoff
* @see java.io.StringBufferInputStream
* @since JDK1.0
*/
public
class ByteArrayInputStream extends InputStream {
/** {@collect.stats}
* {@property.open internal}
* An array of bytes that was provided
* by the creator of the stream. Elements <code>buf[0]</code>
* through <code>buf[count-1]</code> are the
* only bytes that can ever be read from the
* stream; element <code>buf[pos]</code> is
* the next byte to be read.
* {@property.close}
*/
protected byte buf[];
/** {@collect.stats}
* {@description.open}
* The index of the next character to read from the input stream buffer.
* This value should always be nonnegative
* and not larger than the value of <code>count</code>.
* The next byte to be read from the input stream buffer
* will be <code>buf[pos]</code>.
* {@description.close}
*/
protected int pos;
/** {@collect.stats}
* {@description.open}
* The currently marked position in the stream.
* {@description.close}
* {@property.open runtime formal:java.io.InputStream_MarkReset}
* ByteArrayInputStream objects are marked at position zero by
* default when constructed. They may be marked at another
* position within the buffer by the <code>mark()</code> method.
* The current buffer position is set to this point by the
* <code>reset()</code> method.
* {@property.close}
* {@property.open runtime formal:java.io.InputStream_UnmarkedReset}
* <p>
* If no mark has been set, then the value of mark is the offset
* passed to the constructor (or 0 if the offset was not supplied).
* {@property.close}
*
* @since JDK1.1
*/
protected int mark = 0;
/** {@collect.stats}
* {@description.open}
* The index one greater than the last valid character in the input
* stream buffer.
* {@description.close}
* {@property.open internal}
* This value should always be nonnegative
* and not larger than the length of <code>buf</code>.
* It is one greater than the position of
* the last byte within <code>buf</code> that
* can ever be read from the input stream buffer.
* {@property.close}
*/
protected int count;
/** {@collect.stats}
* {@description.open}
* Creates a <code>ByteArrayInputStream</code>
* so that it uses <code>buf</code> as its
* buffer array.
* The buffer array is not copied.
* The initial value of <code>pos</code>
* is <code>0</code> and the initial value
* of <code>count</code> is the length of
* <code>buf</code>.
* {@description.close}
*
* @param buf the input buffer.
*/
public ByteArrayInputStream(byte buf[]) {
this.buf = buf;
this.pos = 0;
this.count = buf.length;
}
/** {@collect.stats}
* {@description.open}
* Creates <code>ByteArrayInputStream</code>
* that uses <code>buf</code> as its
* buffer array. The initial value of <code>pos</code>
* is <code>offset</code> and the initial value
* of <code>count</code> is the minimum of <code>offset+length</code>
* and <code>buf.length</code>.
* The buffer array is not copied. The buffer's mark is
* set to the specified offset.
* {@description.close}
*
* @param buf the input buffer.
* @param offset the offset in the buffer of the first byte to read.
* @param length the maximum number of bytes to read from the buffer.
*/
public ByteArrayInputStream(byte buf[], int offset, int length) {
this.buf = buf;
this.pos = offset;
this.count = Math.min(offset + length, buf.length);
this.mark = offset;
}
/** {@collect.stats}
* {@description.open}
* Reads the next byte of data from this input stream. The value
* byte is returned as an <code>int</code> in the range
* <code>0</code> to <code>255</code>. If no byte is available
* because the end of the stream has been reached, the value
* <code>-1</code> is returned.
* {@description.close}
* {@description.open blocking}
* <p>
* This <code>read</code> method
* cannot block.
* {@description.close}
*
* @return the next byte of data, or <code>-1</code> if the end of the
* stream has been reached.
*/
public synchronized int read() {
return (pos < count) ? (buf[pos++] & 0xff) : -1;
}
/** {@collect.stats}
* {@description.open}
* Reads up to <code>len</code> bytes of data into an array of bytes
* from this input stream.
* If <code>pos</code> equals <code>count</code>,
* then <code>-1</code> is returned to indicate
* end of file. Otherwise, the number <code>k</code>
* of bytes read is equal to the smaller of
* <code>len</code> and <code>count-pos</code>.
* If <code>k</code> is positive, then bytes
* <code>buf[pos]</code> through <code>buf[pos+k-1]</code>
* are copied into <code>b[off]</code> through
* <code>b[off+k-1]</code> in the manner performed
* by <code>System.arraycopy</code>. The
* value <code>k</code> is added into <code>pos</code>
* and <code>k</code> is returned.
* {@description.close}
* {@description.open blocking}
* <p>
* This <code>read</code> method cannot block.
* {@description.close}
*
* @param b the buffer into which the data is read.
* @param off the start offset in the destination array <code>b</code>
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the stream has been reached.
* @exception NullPointerException If <code>b</code> is <code>null</code>.
* @exception IndexOutOfBoundsException If <code>off</code> is negative,
* <code>len</code> is negative, or <code>len</code> is greater than
* <code>b.length - off</code>
*/
public synchronized int read(byte b[], int off, int len) {
if (b == null) {
throw new NullPointerException();
} else if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
}
if (pos >= count) {
return -1;
}
if (pos + len > count) {
len = count - pos;
}
if (len <= 0) {
return 0;
}
System.arraycopy(buf, pos, b, off, len);
pos += len;
return len;
}
/** {@collect.stats}
* {@description.open}
* Skips <code>n</code> bytes of input from this input stream. Fewer
* bytes might be skipped if the end of the input stream is reached.
* The actual number <code>k</code>
* of bytes to be skipped is equal to the smaller
* of <code>n</code> and <code>count-pos</code>.
* The value <code>k</code> is added into <code>pos</code>
* and <code>k</code> is returned.
* {@description.close}
*
* @param n the number of bytes to be skipped.
* @return the actual number of bytes skipped.
*/
public synchronized long skip(long n) {
if (pos + n > count) {
n = count - pos;
}
if (n < 0) {
return 0;
}
pos += n;
return n;
}
/** {@collect.stats}
* {@description.open}
* Returns the number of remaining bytes that can be read (or skipped over)
* from this input stream.
* <p>
* The value returned is <code>count - pos</code>,
* which is the number of bytes remaining to be read from the input buffer.
* {@description.close}
*
* @return the number of remaining bytes that can be read (or skipped
* over) from this input stream without blocking.
*/
public synchronized int available() {
return count - pos;
}
/** {@collect.stats}
* {@description.open}
* Tests if this <code>InputStream</code> supports mark/reset.
* {@description.close}
* {@property.open runtime formal:java.io.InputStream_MarkReset}
* The
* <code>markSupported</code> method of <code>ByteArrayInputStream</code>
* always returns <code>true</code>.
* {@property.close}
*
* @since JDK1.1
*/
public boolean markSupported() {
return true;
}
/** {@collect.stats}
* {@description.open}
* Set the current marked position in the stream.
* ByteArrayInputStream objects are marked at position zero by
* default when constructed. They may be marked at another
* position within the buffer by this method.
* {@description.close}
* {@property.open runtime formal:java.io.InputStream_UnmarkedReset}
* <p>
* If no mark has been set, then the value of the mark is the
* offset passed to the constructor (or 0 if the offset was not
* supplied).
* {@property.close}
*
* {@property.open runtime formal:java.io.InputStream_ReadAheadLimit}
* <p> Note: The <code>readAheadLimit</code> for this class
* has no meaning.
* {@property.close}
*
* @since JDK1.1
*/
public void mark(int readAheadLimit) {
mark = pos;
}
/** {@collect.stats}
* {@description.open}
* Resets the buffer to the marked position.
* {@description.close}
* {@property.open runtime formal:java.io.InputStream_UnmarkedReset}
* The marked position
* is 0 unless another position was marked or an offset was specified
* in the constructor.
* {@property.close}
*/
public synchronized void reset() {
pos = mark;
}
/** {@collect.stats}
* {@description.open}
* Closing a <tt>ByteArrayInputStream</tt> has no effect.
* {@description.close}
* {@property.open runtime formal:java.io.Closeable_MeaninglessClose}
* The methods in
* this class can be called after the stream has been closed without
* generating an <tt>IOException</tt>.
* <p>
* {@property.close}
*/
public void close() throws IOException {
}
}
|
Java
|
/*
* Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.io.ObjectStreamClass.WeakClassKey;
import java.lang.ref.ReferenceQueue;
import java.lang.reflect.Array;
import java.lang.reflect.Modifier;
import java.lang.reflect.Proxy;
import java.security.AccessControlContext;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;
import static java.io.ObjectStreamClass.processQueue;
/** {@collect.stats}
* {@description.open}
* An ObjectInputStream deserializes primitive data and objects previously
* written using an ObjectOutputStream.
*
* <p>ObjectOutputStream and ObjectInputStream can provide an application with
* persistent storage for graphs of objects when used with a FileOutputStream
* and FileInputStream respectively. ObjectInputStream is used to recover
* those objects previously serialized. Other uses include passing objects
* between hosts using a socket stream or for marshaling and unmarshaling
* arguments and parameters in a remote communication system.
*
* <p>ObjectInputStream ensures that the types of all objects in the graph
* created from the stream match the classes present in the Java Virtual
* Machine. Classes are loaded as required using the standard mechanisms.
*
* <p>Only objects that support the java.io.Serializable or
* java.io.Externalizable interface can be read from streams.
*
* <p>The method <code>readObject</code> is used to read an object from the
* stream. Java's safe casting should be used to get the desired type. In
* Java, strings and arrays are objects and are treated as objects during
* serialization. When read they need to be cast to the expected type.
*
* <p>Primitive data types can be read from the stream using the appropriate
* method on DataInput.
*
* <p>The default deserialization mechanism for objects restores the contents
* of each field to the value and type it had when it was written. Fields
* declared as transient or static are ignored by the deserialization process.
* References to other objects cause those objects to be read from the stream
* as necessary. Graphs of objects are restored correctly using a reference
* sharing mechanism. New objects are always allocated when deserializing,
* which prevents existing objects from being overwritten.
*
* <p>Reading an object is analogous to running the constructors of a new
* object. Memory is allocated for the object and initialized to zero (NULL).
* No-arg constructors are invoked for the non-serializable classes and then
* the fields of the serializable classes are restored from the stream starting
* with the serializable class closest to java.lang.object and finishing with
* the object's most specific class.
*
* <p>For example to read from a stream as written by the example in
* ObjectOutputStream:
* <br>
* <pre>
* FileInputStream fis = new FileInputStream("t.tmp");
* ObjectInputStream ois = new ObjectInputStream(fis);
*
* int i = ois.readInt();
* String today = (String) ois.readObject();
* Date date = (Date) ois.readObject();
*
* ois.close();
* </pre>
*
* <p>Classes control how they are serialized by implementing either the
* java.io.Serializable or java.io.Externalizable interfaces.
*
* <p>Implementing the Serializable interface allows object serialization to
* save and restore the entire state of the object and it allows classes to
* evolve between the time the stream is written and the time it is read. It
* automatically traverses references between objects, saving and restoring
* entire graphs.
*
* <p>Serializable classes that require special handling during the
* serialization and deserialization process should implement the following
* methods:<p>
*
* <pre>
* private void writeObject(java.io.ObjectOutputStream stream)
* throws IOException;
* private void readObject(java.io.ObjectInputStream stream)
* throws IOException, ClassNotFoundException;
* private void readObjectNoData()
* throws ObjectStreamException;
* </pre>
*
* <p>The readObject method is responsible for reading and restoring the state
* of the object for its particular class using data written to the stream by
* the corresponding writeObject method. The method does not need to concern
* itself with the state belonging to its superclasses or subclasses. State is
* restored by reading data from the ObjectInputStream for the individual
* fields and making assignments to the appropriate fields of the object.
* Reading primitive data types is supported by DataInput.
*
* <p>Any attempt to read object data which exceeds the boundaries of the
* custom data written by the corresponding writeObject method will cause an
* OptionalDataException to be thrown with an eof field value of true.
* Non-object reads which exceed the end of the allotted data will reflect the
* end of data in the same way that they would indicate the end of the stream:
* bytewise reads will return -1 as the byte read or number of bytes read, and
* primitive reads will throw EOFExceptions. If there is no corresponding
* writeObject method, then the end of default serialized data marks the end of
* the allotted data.
*
* <p>Primitive and object read calls issued from within a readExternal method
* behave in the same manner--if the stream is already positioned at the end of
* data written by the corresponding writeExternal method, object reads will
* throw OptionalDataExceptions with eof set to true, bytewise reads will
* return -1, and primitive reads will throw EOFExceptions. Note that this
* behavior does not hold for streams written with the old
* <code>ObjectStreamConstants.PROTOCOL_VERSION_1</code> protocol, in which the
* end of data written by writeExternal methods is not demarcated, and hence
* cannot be detected.
*
* <p>The readObjectNoData method is responsible for initializing the state of
* the object for its particular class in the event that the serialization
* stream does not list the given class as a superclass of the object being
* deserialized. This may occur in cases where the receiving party uses a
* different version of the deserialized instance's class than the sending
* party, and the receiver's version extends classes that are not extended by
* the sender's version. This may also occur if the serialization stream has
* been tampered; hence, readObjectNoData is useful for initializing
* deserialized objects properly despite a "hostile" or incomplete source
* stream.
*
* <p>Serialization does not read or assign values to the fields of any object
* that does not implement the java.io.Serializable interface. Subclasses of
* Objects that are not serializable can be serializable. In this case the
* non-serializable class must have a no-arg constructor to allow its fields to
* be initialized. In this case it is the responsibility of the subclass to
* save and restore the state of the non-serializable class. It is frequently
* the case that the fields of that class are accessible (public, package, or
* protected) or that there are get and set methods that can be used to restore
* the state.
*
* <p>Any exception that occurs while deserializing an object will be caught by
* the ObjectInputStream and abort the reading process.
*
* <p>Implementing the Externalizable interface allows the object to assume
* complete control over the contents and format of the object's serialized
* form. The methods of the Externalizable interface, writeExternal and
* readExternal, are called to save and restore the objects state. When
* implemented by a class they can write and read their own state using all of
* the methods of ObjectOutput and ObjectInput. It is the responsibility of
* the objects to handle any versioning that occurs.
*
* <p>Enum constants are deserialized differently than ordinary serializable or
* externalizable objects. The serialized form of an enum constant consists
* solely of its name; field values of the constant are not transmitted. To
* deserialize an enum constant, ObjectInputStream reads the constant name from
* the stream; the deserialized constant is then obtained by calling the static
* method <code>Enum.valueOf(Class, String)</code> with the enum constant's
* base type and the received constant name as arguments. Like other
* serializable or externalizable objects, enum constants can function as the
* targets of back references appearing subsequently in the serialization
* stream. The process by which enum constants are deserialized cannot be
* customized: any class-specific readObject, readObjectNoData, and readResolve
* methods defined by enum types are ignored during deserialization.
* Similarly, any serialPersistentFields or serialVersionUID field declarations
* are also ignored--all enum types have a fixed serialVersionUID of 0L.
* {@description.close}
*
* @author Mike Warres
* @author Roger Riggs
* @see java.io.DataInput
* @see java.io.ObjectOutputStream
* @see java.io.Serializable
* @see <a href="../../../platform/serialization/spec/input.html"> Object Serialization Specification, Section 3, Object Input Classes</a>
* @since JDK1.1
*/
public class ObjectInputStream
extends InputStream implements ObjectInput, ObjectStreamConstants
{
/** {@collect.stats}
* {@description.open}
* handle value representing null
* {@description.close}
*/
private static final int NULL_HANDLE = -1;
/** {@collect.stats}
* {@description.open}
* marker for unshared objects in internal handle table
* {@description.close}
*/
private static final Object unsharedMarker = new Object();
/** {@collect.stats}
* {@description.open}
* table mapping primitive type names to corresponding class objects
* {@description.close}
*/
private static final HashMap primClasses = new HashMap(8, 1.0F);
static {
primClasses.put("boolean", boolean.class);
primClasses.put("byte", byte.class);
primClasses.put("char", char.class);
primClasses.put("short", short.class);
primClasses.put("int", int.class);
primClasses.put("long", long.class);
primClasses.put("float", float.class);
primClasses.put("double", double.class);
primClasses.put("void", void.class);
}
private static class Caches {
/** {@collect.stats}
* {@description.open}
* cache of subclass security audit results
* {@description.close}
*/
static final ConcurrentMap<WeakClassKey,Boolean> subclassAudits =
new ConcurrentHashMap<WeakClassKey,Boolean>();
/** {@collect.stats}
* {@description.open}
* queue for WeakReferences to audited subclasses
* {@description.close}
*/
static final ReferenceQueue<Class<?>> subclassAuditsQueue =
new ReferenceQueue<Class<?>>();
}
/** {@collect.stats}
* {@description.open}
* filter stream for handling block data conversion
* {@description.close}
*/
private final BlockDataInputStream bin;
/** {@collect.stats}
* {@description.open}
* validation callback list
* {@description.close}
*/
private final ValidationList vlist;
/** {@collect.stats}
* {@description.open}
* recursion depth
* {@description.close}
*/
private int depth;
/** {@collect.stats}
* {@description.open}
* whether stream is closed
* {@description.close}
*/
private boolean closed;
/** {@collect.stats}
* {@description.open}
* wire handle -> obj/exception map
* {@description.close}
*/
private final HandleTable handles;
/** {@collect.stats}
* {@description.open}
* scratch field for passing handle values up/down call stack
* {@description.close}
*/
private int passHandle = NULL_HANDLE;
/** {@collect.stats}
* {@description.open}
* flag set when at end of field value block with no TC_ENDBLOCKDATA
* {@description.close}
*/
private boolean defaultDataEnd = false;
/** {@collect.stats}
* {@description.open}
* buffer for reading primitive field values
* {@description.close}
*/
private byte[] primVals;
/** {@collect.stats}
* {@description.open}
* if true, invoke readObjectOverride() instead of readObject()
* {@description.close}
*/
private final boolean enableOverride;
/** {@collect.stats}
* {@description.open}
* if true, invoke resolveObject()
* {@description.close}
*/
private boolean enableResolve;
/** {@collect.stats}
* {@description.open}
* Context during upcalls to class-defined readObject methods; holds
* object currently being deserialized and descriptor for current class.
* Null when not during readObject upcall.
* {@description.close}
*/
private SerialCallbackContext curContext;
/** {@collect.stats}
* {@description.open}
* Creates an ObjectInputStream that reads from the specified InputStream.
* A serialization stream header is read from the stream and verified.
* {@description.close}
* {@description.open blocking}
* This constructor will block until the corresponding ObjectOutputStream
* has written and flushed the header.
* {@description.close}
*
* {@description.open}
* <p>If a security manager is installed, this constructor will check for
* the "enableSubclassImplementation" SerializablePermission when invoked
* directly or indirectly by the constructor of a subclass which overrides
* the ObjectInputStream.readFields or ObjectInputStream.readUnshared
* methods.
* {@description.close}
*
* @param in input stream to read from
* @throws StreamCorruptedException if the stream header is incorrect
* @throws IOException if an I/O error occurs while reading stream header
* @throws SecurityException if untrusted subclass illegally overrides
* security-sensitive methods
* @throws NullPointerException if <code>in</code> is <code>null</code>
* @see ObjectInputStream#ObjectInputStream()
* @see ObjectInputStream#readFields()
* @see ObjectOutputStream#ObjectOutputStream(OutputStream)
*/
public ObjectInputStream(InputStream in) throws IOException {
verifySubclass();
bin = new BlockDataInputStream(in);
handles = new HandleTable(10);
vlist = new ValidationList();
enableOverride = false;
readStreamHeader();
bin.setBlockDataMode(true);
}
/** {@collect.stats}
* {@description.open}
* Provide a way for subclasses that are completely reimplementing
* ObjectInputStream to not have to allocate private data just used by this
* implementation of ObjectInputStream.
*
* <p>If there is a security manager installed, this method first calls the
* security manager's <code>checkPermission</code> method with the
* <code>SerializablePermission("enableSubclassImplementation")</code>
* permission to ensure it's ok to enable subclassing.
* {@description.close}
*
* @throws SecurityException if a security manager exists and its
* <code>checkPermission</code> method denies enabling
* subclassing.
* @see SecurityManager#checkPermission
* @see java.io.SerializablePermission
*/
protected ObjectInputStream() throws IOException, SecurityException {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
}
bin = null;
handles = null;
vlist = null;
enableOverride = true;
}
/** {@collect.stats}
* {@description.open}
* Read an object from the ObjectInputStream. The class of the object, the
* signature of the class, and the values of the non-transient and
* non-static fields of the class and all of its supertypes are read.
* Default deserializing for a class can be overriden using the writeObject
* and readObject methods. Objects referenced by this object are read
* transitively so that a complete equivalent graph of objects is
* reconstructed by readObject.
*
* <p>The root object is completely restored when all of its fields and the
* objects it references are completely restored. At this point the object
* validation callbacks are executed in order based on their registered
* priorities. The callbacks are registered by objects (in the readObject
* special methods) as they are individually restored.
*
* <p>Exceptions are thrown for problems with the InputStream and for
* classes that should not be deserialized. All exceptions are fatal to
* the InputStream and leave it in an indeterminate state; it is up to the
* caller to ignore or recover the stream state.
* {@description.close}
*
* @throws ClassNotFoundException Class of a serialized object cannot be
* found.
* @throws InvalidClassException Something is wrong with a class used by
* serialization.
* @throws StreamCorruptedException Control information in the
* stream is inconsistent.
* @throws OptionalDataException Primitive data was found in the
* stream instead of objects.
* @throws IOException Any of the usual Input/Output related exceptions.
*/
public final Object readObject()
throws IOException, ClassNotFoundException
{
if (enableOverride) {
return readObjectOverride();
}
// if nested read, passHandle contains handle of enclosing object
int outerHandle = passHandle;
try {
Object obj = readObject0(false);
handles.markDependency(outerHandle, passHandle);
ClassNotFoundException ex = handles.lookupException(passHandle);
if (ex != null) {
throw ex;
}
if (depth == 0) {
vlist.doCallbacks();
}
return obj;
} finally {
passHandle = outerHandle;
if (closed && depth == 0) {
clear();
}
}
}
/** {@collect.stats}
* {@description.open}
* This method is called by trusted subclasses of ObjectOutputStream that
* constructed ObjectOutputStream using the protected no-arg constructor.
* The subclass is expected to provide an override method with the modifier
* "final".
* {@description.close}
*
* @return the Object read from the stream.
* @throws ClassNotFoundException Class definition of a serialized object
* cannot be found.
* @throws OptionalDataException Primitive data was found in the stream
* instead of objects.
* @throws IOException if I/O errors occurred while reading from the
* underlying stream
* @see #ObjectInputStream()
* @see #readObject()
* @since 1.2
*/
protected Object readObjectOverride()
throws IOException, ClassNotFoundException
{
return null;
}
/** {@collect.stats}
* {@description.open}
* Reads an "unshared" object from the ObjectInputStream. This method is
* identical to readObject, except that it prevents subsequent calls to
* readObject and readUnshared from returning additional references to the
* deserialized instance obtained via this call. Specifically:
* <ul>
* <li>If readUnshared is called to deserialize a back-reference (the
* stream representation of an object which has been written
* previously to the stream), an ObjectStreamException will be
* thrown.
*
* <li>If readUnshared returns successfully, then any subsequent attempts
* to deserialize back-references to the stream handle deserialized
* by readUnshared will cause an ObjectStreamException to be thrown.
* </ul>
* Deserializing an object via readUnshared invalidates the stream handle
* associated with the returned object. Note that this in itself does not
* always guarantee that the reference returned by readUnshared is unique;
* the deserialized object may define a readResolve method which returns an
* object visible to other parties, or readUnshared may return a Class
* object or enum constant obtainable elsewhere in the stream or through
* external means. If the deserialized object defines a readResolve method
* and the invocation of that method returns an array, then readUnshared
* returns a shallow clone of that array; this guarantees that the returned
* array object is unique and cannot be obtained a second time from an
* invocation of readObject or readUnshared on the ObjectInputStream,
* even if the underlying data stream has been manipulated.
*
* <p>ObjectInputStream subclasses which override this method can only be
* constructed in security contexts possessing the
* "enableSubclassImplementation" SerializablePermission; any attempt to
* instantiate such a subclass without this permission will cause a
* SecurityException to be thrown.
* {@description.close}
*
* @return reference to deserialized object
* @throws ClassNotFoundException if class of an object to deserialize
* cannot be found
* @throws StreamCorruptedException if control information in the stream
* is inconsistent
* @throws ObjectStreamException if object to deserialize has already
* appeared in stream
* @throws OptionalDataException if primitive data is next in stream
* @throws IOException if an I/O error occurs during deserialization
* @since 1.4
*/
public Object readUnshared() throws IOException, ClassNotFoundException {
// if nested read, passHandle contains handle of enclosing object
int outerHandle = passHandle;
try {
Object obj = readObject0(true);
handles.markDependency(outerHandle, passHandle);
ClassNotFoundException ex = handles.lookupException(passHandle);
if (ex != null) {
throw ex;
}
if (depth == 0) {
vlist.doCallbacks();
}
return obj;
} finally {
passHandle = outerHandle;
if (closed && depth == 0) {
clear();
}
}
}
/** {@collect.stats}
* {@description.open}
* Read the non-static and non-transient fields of the current class from
* this stream. This may only be called from the readObject method of the
* class being deserialized. It will throw the NotActiveException if it is
* called otherwise.
* {@description.close}
*
* @throws ClassNotFoundException if the class of a serialized object
* could not be found.
* @throws IOException if an I/O error occurs.
* @throws NotActiveException if the stream is not currently reading
* objects.
*/
public void defaultReadObject()
throws IOException, ClassNotFoundException
{
if (curContext == null) {
throw new NotActiveException("not in call to readObject");
}
Object curObj = curContext.getObj();
ObjectStreamClass curDesc = curContext.getDesc();
bin.setBlockDataMode(false);
defaultReadFields(curObj, curDesc);
bin.setBlockDataMode(true);
if (!curDesc.hasWriteObjectData()) {
/*
* Fix for 4360508: since stream does not contain terminating
* TC_ENDBLOCKDATA tag, set flag so that reading code elsewhere
* knows to simulate end-of-custom-data behavior.
*/
defaultDataEnd = true;
}
ClassNotFoundException ex = handles.lookupException(passHandle);
if (ex != null) {
throw ex;
}
}
/** {@collect.stats}
* {@description.open}
* Reads the persistent fields from the stream and makes them available by
* name.
* {@description.close}
*
* @return the <code>GetField</code> object representing the persistent
* fields of the object being deserialized
* @throws ClassNotFoundException if the class of a serialized object
* could not be found.
* @throws IOException if an I/O error occurs.
* @throws NotActiveException if the stream is not currently reading
* objects.
* @since 1.2
*/
public ObjectInputStream.GetField readFields()
throws IOException, ClassNotFoundException
{
if (curContext == null) {
throw new NotActiveException("not in call to readObject");
}
Object curObj = curContext.getObj();
ObjectStreamClass curDesc = curContext.getDesc();
bin.setBlockDataMode(false);
GetFieldImpl getField = new GetFieldImpl(curDesc);
getField.readFields();
bin.setBlockDataMode(true);
if (!curDesc.hasWriteObjectData()) {
/*
* Fix for 4360508: since stream does not contain terminating
* TC_ENDBLOCKDATA tag, set flag so that reading code elsewhere
* knows to simulate end-of-custom-data behavior.
*/
defaultDataEnd = true;
}
return getField;
}
/** {@collect.stats}
* {@description.open}
* Register an object to be validated before the graph is returned. While
* similar to resolveObject these validations are called after the entire
* graph has been reconstituted.
* {@description.close}
* {@property.open static}
* Typically, a readObject method will
* register the object with the stream so that when all of the objects are
* restored a final set of validations can be performed.
* {@property.close}
*
* @param obj the object to receive the validation callback.
* @param prio controls the order of callbacks;zero is a good default.
* Use higher numbers to be called back earlier, lower numbers for
* later callbacks. Within a priority, callbacks are processed in
* no particular order.
* @throws NotActiveException The stream is not currently reading objects
* so it is invalid to register a callback.
* @throws InvalidObjectException The validation object is null.
*/
public void registerValidation(ObjectInputValidation obj, int prio)
throws NotActiveException, InvalidObjectException
{
if (depth == 0) {
throw new NotActiveException("stream inactive");
}
vlist.register(obj, prio);
}
/** {@collect.stats}
* {@description.open}
* Load the local class equivalent of the specified stream class
* description. Subclasses may implement this method to allow classes to
* be fetched from an alternate source.
*
* <p>The corresponding method in <code>ObjectOutputStream</code> is
* <code>annotateClass</code>. This method will be invoked only once for
* each unique class in the stream. This method can be implemented by
* subclasses to use an alternate loading mechanism but must return a
* <code>Class</code> object. Once returned, if the class is not an array
* class, its serialVersionUID is compared to the serialVersionUID of the
* serialized class, and if there is a mismatch, the deserialization fails
* and an {@link InvalidClassException} is thrown.
*
* <p>The default implementation of this method in
* <code>ObjectInputStream</code> returns the result of calling
* <pre>
* Class.forName(desc.getName(), false, loader)
* </pre>
* where <code>loader</code> is determined as follows: if there is a
* method on the current thread's stack whose declaring class was
* defined by a user-defined class loader (and was not a generated to
* implement reflective invocations), then <code>loader</code> is class
* loader corresponding to the closest such method to the currently
* executing frame; otherwise, <code>loader</code> is
* <code>null</code>. If this call results in a
* <code>ClassNotFoundException</code> and the name of the passed
* <code>ObjectStreamClass</code> instance is the Java language keyword
* for a primitive type or void, then the <code>Class</code> object
* representing that primitive type or void will be returned
* (e.g., an <code>ObjectStreamClass</code> with the name
* <code>"int"</code> will be resolved to <code>Integer.TYPE</code>).
* Otherwise, the <code>ClassNotFoundException</code> will be thrown to
* the caller of this method.
* {@description.close}
*
* @param desc an instance of class <code>ObjectStreamClass</code>
* @return a <code>Class</code> object corresponding to <code>desc</code>
* @throws IOException any of the usual Input/Output exceptions.
* @throws ClassNotFoundException if class of a serialized object cannot
* be found.
*/
protected Class<?> resolveClass(ObjectStreamClass desc)
throws IOException, ClassNotFoundException
{
String name = desc.getName();
try {
return Class.forName(name, false, latestUserDefinedLoader());
} catch (ClassNotFoundException ex) {
Class cl = (Class) primClasses.get(name);
if (cl != null) {
return cl;
} else {
throw ex;
}
}
}
/** {@collect.stats}
* {@description.open}
* Returns a proxy class that implements the interfaces named in a proxy
* class descriptor; subclasses may implement this method to read custom
* data from the stream along with the descriptors for dynamic proxy
* classes, allowing them to use an alternate loading mechanism for the
* interfaces and the proxy class.
*
* <p>This method is called exactly once for each unique proxy class
* descriptor in the stream.
*
* <p>The corresponding method in <code>ObjectOutputStream</code> is
* <code>annotateProxyClass</code>. For a given subclass of
* <code>ObjectInputStream</code> that overrides this method, the
* <code>annotateProxyClass</code> method in the corresponding subclass of
* <code>ObjectOutputStream</code> must write any data or objects read by
* this method.
*
* <p>The default implementation of this method in
* <code>ObjectInputStream</code> returns the result of calling
* <code>Proxy.getProxyClass</code> with the list of <code>Class</code>
* objects for the interfaces that are named in the <code>interfaces</code>
* parameter. The <code>Class</code> object for each interface name
* <code>i</code> is the value returned by calling
* <pre>
* Class.forName(i, false, loader)
* </pre>
* where <code>loader</code> is that of the first non-<code>null</code>
* class loader up the execution stack, or <code>null</code> if no
* non-<code>null</code> class loaders are on the stack (the same class
* loader choice used by the <code>resolveClass</code> method). Unless any
* of the resolved interfaces are non-public, this same value of
* <code>loader</code> is also the class loader passed to
* <code>Proxy.getProxyClass</code>; if non-public interfaces are present,
* their class loader is passed instead (if more than one non-public
* interface class loader is encountered, an
* <code>IllegalAccessError</code> is thrown).
* If <code>Proxy.getProxyClass</code> throws an
* <code>IllegalArgumentException</code>, <code>resolveProxyClass</code>
* will throw a <code>ClassNotFoundException</code> containing the
* <code>IllegalArgumentException</code>.
* {@description.close}
*
* @param interfaces the list of interface names that were
* deserialized in the proxy class descriptor
* @return a proxy class for the specified interfaces
* @throws IOException any exception thrown by the underlying
* <code>InputStream</code>
* @throws ClassNotFoundException if the proxy class or any of the
* named interfaces could not be found
* @see ObjectOutputStream#annotateProxyClass(Class)
* @since 1.3
*/
protected Class<?> resolveProxyClass(String[] interfaces)
throws IOException, ClassNotFoundException
{
ClassLoader latestLoader = latestUserDefinedLoader();
ClassLoader nonPublicLoader = null;
boolean hasNonPublicInterface = false;
// define proxy in class loader of non-public interface(s), if any
Class[] classObjs = new Class[interfaces.length];
for (int i = 0; i < interfaces.length; i++) {
Class cl = Class.forName(interfaces[i], false, latestLoader);
if ((cl.getModifiers() & Modifier.PUBLIC) == 0) {
if (hasNonPublicInterface) {
if (nonPublicLoader != cl.getClassLoader()) {
throw new IllegalAccessError(
"conflicting non-public interface class loaders");
}
} else {
nonPublicLoader = cl.getClassLoader();
hasNonPublicInterface = true;
}
}
classObjs[i] = cl;
}
try {
return Proxy.getProxyClass(
hasNonPublicInterface ? nonPublicLoader : latestLoader,
classObjs);
} catch (IllegalArgumentException e) {
throw new ClassNotFoundException(null, e);
}
}
/** {@collect.stats}
* {@description.open}
* This method will allow trusted subclasses of ObjectInputStream to
* substitute one object for another during deserialization. Replacing
* objects is disabled until enableResolveObject is called. The
* enableResolveObject method checks that the stream requesting to resolve
* object can be trusted. Every reference to serializable objects is passed
* to resolveObject. To insure that the private state of objects is not
* unintentionally exposed only trusted streams may use resolveObject.
*
* <p>This method is called after an object has been read but before it is
* returned from readObject. The default resolveObject method just returns
* the same object.
*
* <p>When a subclass is replacing objects it must insure that the
* substituted object is compatible with every field where the reference
* will be stored. Objects whose type is not a subclass of the type of the
* field or array element abort the serialization by raising an exception
* and the object is not be stored.
*
* <p>This method is called only once when each object is first
* encountered. All subsequent references to the object will be redirected
* to the new object.
* {@description.close}
*
* @param obj object to be substituted
* @return the substituted object
* @throws IOException Any of the usual Input/Output exceptions.
*/
protected Object resolveObject(Object obj) throws IOException {
return obj;
}
/** {@collect.stats}
* {@description.open}
* Enable the stream to allow objects read from the stream to be replaced.
* When enabled, the resolveObject method is called for every object being
* deserialized.
*
* <p>If <i>enable</i> is true, and there is a security manager installed,
* this method first calls the security manager's
* <code>checkPermission</code> method with the
* <code>SerializablePermission("enableSubstitution")</code> permission to
* ensure it's ok to enable the stream to allow objects read from the
* stream to be replaced.
* {@description.close}
*
* @param enable true for enabling use of <code>resolveObject</code> for
* every object being deserialized
* @return the previous setting before this method was invoked
* @throws SecurityException if a security manager exists and its
* <code>checkPermission</code> method denies enabling the stream
* to allow objects read from the stream to be replaced.
* @see SecurityManager#checkPermission
* @see java.io.SerializablePermission
*/
protected boolean enableResolveObject(boolean enable)
throws SecurityException
{
if (enable == enableResolve) {
return enable;
}
if (enable) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkPermission(SUBSTITUTION_PERMISSION);
}
}
enableResolve = enable;
return !enableResolve;
}
/** {@collect.stats}
* {@description.open}
* The readStreamHeader method is provided to allow subclasses to read and
* verify their own stream headers. It reads and verifies the magic number
* and version number.
* {@description.close}
*
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
* @throws StreamCorruptedException if control information in the stream
* is inconsistent
*/
protected void readStreamHeader()
throws IOException, StreamCorruptedException
{
short s0 = bin.readShort();
short s1 = bin.readShort();
if (s0 != STREAM_MAGIC || s1 != STREAM_VERSION) {
throw new StreamCorruptedException(
String.format("invalid stream header: %04X%04X", s0, s1));
}
}
/** {@collect.stats}
* {@description.open}
* Read a class descriptor from the serialization stream. This method is
* called when the ObjectInputStream expects a class descriptor as the next
* item in the serialization stream. Subclasses of ObjectInputStream may
* override this method to read in class descriptors that have been written
* in non-standard formats (by subclasses of ObjectOutputStream which have
* overridden the <code>writeClassDescriptor</code> method). By default,
* this method reads class descriptors according to the format defined in
* the Object Serialization specification.
* {@description.close}
*
* @return the class descriptor read
* @throws IOException If an I/O error has occurred.
* @throws ClassNotFoundException If the Class of a serialized object used
* in the class descriptor representation cannot be found
* @see java.io.ObjectOutputStream#writeClassDescriptor(java.io.ObjectStreamClass)
* @since 1.3
*/
protected ObjectStreamClass readClassDescriptor()
throws IOException, ClassNotFoundException
{
ObjectStreamClass desc = new ObjectStreamClass();
desc.readNonProxy(this);
return desc;
}
/** {@collect.stats}
* {@description.open}
* Reads a byte of data.
* {@description.close}
* {@description.open blocking}
* This method will block if no input is available.
* {@description.close}
*
* @return the byte read, or -1 if the end of the stream is reached.
* @throws IOException If an I/O error has occurred.
*/
public int read() throws IOException {
return bin.read();
}
/** {@collect.stats}
* {@description.open}
* Reads into an array of bytes.
* {@description.close}
* {@description.open blocking}
* This method will block until some input
* is available.
* {@description.close}
* {@description.open}
* Consider using java.io.DataInputStream.readFully to read
* exactly 'length' bytes.
* {@description.close}
*
* @param buf the buffer into which the data is read
* @param off the start offset of the data
* @param len the maximum number of bytes read
* @return the actual number of bytes read, -1 is returned when the end of
* the stream is reached.
* @throws IOException If an I/O error has occurred.
* @see java.io.DataInputStream#readFully(byte[],int,int)
*/
public int read(byte[] buf, int off, int len) throws IOException {
if (buf == null) {
throw new NullPointerException();
}
int endoff = off + len;
if (off < 0 || len < 0 || endoff > buf.length || endoff < 0) {
throw new IndexOutOfBoundsException();
}
return bin.read(buf, off, len, false);
}
/** {@collect.stats}
* {@description.open}
* Returns the number of bytes that can be read without blocking.
* {@description.close}
*
* @return the number of available bytes.
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
*/
public int available() throws IOException {
return bin.available();
}
/** {@collect.stats}
* {@description.open}
* Closes the input stream.
* {@description.close}
* {@property.open runtime formal:java.io.ObjectInput_Close}
* Must be called to release any resources
* associated with the stream.
* {@property.close}
*
* @throws IOException If an I/O error has occurred.
*/
public void close() throws IOException {
/*
* Even if stream already closed, propagate redundant close to
* underlying stream to stay consistent with previous implementations.
*/
closed = true;
if (depth == 0) {
clear();
}
bin.close();
}
/** {@collect.stats}
* {@description.open}
* Reads in a boolean.
* {@description.close}
*
* @return the boolean read.
* @throws EOFException If end of file is reached.
* @throws IOException If other I/O error has occurred.
*/
public boolean readBoolean() throws IOException {
return bin.readBoolean();
}
/** {@collect.stats}
* {@description.open}
* Reads an 8 bit byte.
* {@description.close}
*
* @return the 8 bit byte read.
* @throws EOFException If end of file is reached.
* @throws IOException If other I/O error has occurred.
*/
public byte readByte() throws IOException {
return bin.readByte();
}
/** {@collect.stats}
* {@description.open}
* Reads an unsigned 8 bit byte.
* {@description.close}
*
* @return the 8 bit byte read.
* @throws EOFException If end of file is reached.
* @throws IOException If other I/O error has occurred.
*/
public int readUnsignedByte() throws IOException {
return bin.readUnsignedByte();
}
/** {@collect.stats}
* {@description.open}
* Reads a 16 bit char.
* {@description.close}
*
* @return the 16 bit char read.
* @throws EOFException If end of file is reached.
* @throws IOException If other I/O error has occurred.
*/
public char readChar() throws IOException {
return bin.readChar();
}
/** {@collect.stats}
* {@description.open}
* Reads a 16 bit short.
* {@description.close}
*
* @return the 16 bit short read.
* @throws EOFException If end of file is reached.
* @throws IOException If other I/O error has occurred.
*/
public short readShort() throws IOException {
return bin.readShort();
}
/** {@collect.stats}
* {@description.open}
* Reads an unsigned 16 bit short.
* {@description.close}
*
* @return the 16 bit short read.
* @throws EOFException If end of file is reached.
* @throws IOException If other I/O error has occurred.
*/
public int readUnsignedShort() throws IOException {
return bin.readUnsignedShort();
}
/** {@collect.stats}
* {@description.open}
* Reads a 32 bit int.
* {@description.close}
*
* @return the 32 bit integer read.
* @throws EOFException If end of file is reached.
* @throws IOException If other I/O error has occurred.
*/
public int readInt() throws IOException {
return bin.readInt();
}
/** {@collect.stats}
* {@description.open}
* Reads a 64 bit long.
* {@description.close}
*
* @return the read 64 bit long.
* @throws EOFException If end of file is reached.
* @throws IOException If other I/O error has occurred.
*/
public long readLong() throws IOException {
return bin.readLong();
}
/** {@collect.stats}
* {@description.open}
* Reads a 32 bit float.
* {@description.close}
*
* @return the 32 bit float read.
* @throws EOFException If end of file is reached.
* @throws IOException If other I/O error has occurred.
*/
public float readFloat() throws IOException {
return bin.readFloat();
}
/** {@collect.stats}
* {@description.open}
* Reads a 64 bit double.
* {@description.close}
*
* @return the 64 bit double read.
* @throws EOFException If end of file is reached.
* @throws IOException If other I/O error has occurred.
*/
public double readDouble() throws IOException {
return bin.readDouble();
}
/** {@collect.stats}
* {@description.open}
* Reads bytes,
* {@description.close}
* {@description.open blocking}
* blocking until all bytes are read.
* {@description.close}
*
* @param buf the buffer into which the data is read
* @throws EOFException If end of file is reached.
* @throws IOException If other I/O error has occurred.
*/
public void readFully(byte[] buf) throws IOException {
bin.readFully(buf, 0, buf.length, false);
}
/** {@collect.stats}
* {@description.open}
* Reads bytes,
* {@description.close}
* {@description.open blocking}
* blocking until all bytes are read.
* {@description.close}
*
* @param buf the buffer into which the data is read
* @param off the start offset of the data
* @param len the maximum number of bytes to read
* @throws EOFException If end of file is reached.
* @throws IOException If other I/O error has occurred.
*/
public void readFully(byte[] buf, int off, int len) throws IOException {
int endoff = off + len;
if (off < 0 || len < 0 || endoff > buf.length || endoff < 0) {
throw new IndexOutOfBoundsException();
}
bin.readFully(buf, off, len, false);
}
/** {@collect.stats}
* {@description.open}
* Skips bytes.
* {@description.close}
*
* @param len the number of bytes to be skipped
* @return the actual number of bytes skipped.
* @throws IOException If an I/O error has occurred.
*/
public int skipBytes(int len) throws IOException {
return bin.skipBytes(len);
}
/** {@collect.stats}
* {@description.open}
* Reads in a line that has been terminated by a \n, \r, \r\n or EOF.
* {@description.close}
*
* @return a String copy of the line.
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
* @deprecated This method does not properly convert bytes to characters.
* see DataInputStream for the details and alternatives.
*/
@Deprecated
public String readLine() throws IOException {
return bin.readLine();
}
/** {@collect.stats}
* {@description.open}
* Reads a String in
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
* format.
* {@description.close}
*
* @return the String.
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
* @throws UTFDataFormatException if read bytes do not represent a valid
* modified UTF-8 encoding of a string
*/
public String readUTF() throws IOException {
return bin.readUTF();
}
/** {@collect.stats}
* {@description.open}
* Provide access to the persistent fields read from the input stream.
* {@description.close}
*/
public static abstract class GetField {
/** {@collect.stats}
* {@description.open}
* Get the ObjectStreamClass that describes the fields in the stream.
* {@description.close}
*
* @return the descriptor class that describes the serializable fields
*/
public abstract ObjectStreamClass getObjectStreamClass();
/** {@collect.stats}
* {@description.open}
* Return true if the named field is defaulted and has no value in this
* stream.
* {@description.close}
*
* @param name the name of the field
* @return true, if and only if the named field is defaulted
* @throws IOException if there are I/O errors while reading from
* the underlying <code>InputStream</code>
* @throws IllegalArgumentException if <code>name</code> does not
* correspond to a serializable field
*/
public abstract boolean defaulted(String name) throws IOException;
/** {@collect.stats}
* {@description.open}
* Get the value of the named boolean field from the persistent field.
* {@description.close}
*
* @param name the name of the field
* @param val the default value to use if <code>name</code> does not
* have a value
* @return the value of the named <code>boolean</code> field
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
* @throws IllegalArgumentException if type of <code>name</code> is
* not serializable or if the field type is incorrect
*/
public abstract boolean get(String name, boolean val)
throws IOException;
/** {@collect.stats}
* {@description.open}
* Get the value of the named byte field from the persistent field.
* {@description.close}
*
* @param name the name of the field
* @param val the default value to use if <code>name</code> does not
* have a value
* @return the value of the named <code>byte</code> field
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
* @throws IllegalArgumentException if type of <code>name</code> is
* not serializable or if the field type is incorrect
*/
public abstract byte get(String name, byte val) throws IOException;
/** {@collect.stats}
* {@description.open}
* Get the value of the named char field from the persistent field.
* {@description.close}
*
* @param name the name of the field
* @param val the default value to use if <code>name</code> does not
* have a value
* @return the value of the named <code>char</code> field
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
* @throws IllegalArgumentException if type of <code>name</code> is
* not serializable or if the field type is incorrect
*/
public abstract char get(String name, char val) throws IOException;
/** {@collect.stats}
* {@description.open}
* Get the value of the named short field from the persistent field.
* {@description.close}
*
* @param name the name of the field
* @param val the default value to use if <code>name</code> does not
* have a value
* @return the value of the named <code>short</code> field
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
* @throws IllegalArgumentException if type of <code>name</code> is
* not serializable or if the field type is incorrect
*/
public abstract short get(String name, short val) throws IOException;
/** {@collect.stats}
* {@description.open}
* Get the value of the named int field from the persistent field.
* {@description.close}
*
* @param name the name of the field
* @param val the default value to use if <code>name</code> does not
* have a value
* @return the value of the named <code>int</code> field
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
* @throws IllegalArgumentException if type of <code>name</code> is
* not serializable or if the field type is incorrect
*/
public abstract int get(String name, int val) throws IOException;
/** {@collect.stats}
* {@description.open}
* Get the value of the named long field from the persistent field.
* {@description.close}
*
* @param name the name of the field
* @param val the default value to use if <code>name</code> does not
* have a value
* @return the value of the named <code>long</code> field
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
* @throws IllegalArgumentException if type of <code>name</code> is
* not serializable or if the field type is incorrect
*/
public abstract long get(String name, long val) throws IOException;
/** {@collect.stats}
* {@description.open}
* Get the value of the named float field from the persistent field.
* {@description.close}
*
* @param name the name of the field
* @param val the default value to use if <code>name</code> does not
* have a value
* @return the value of the named <code>float</code> field
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
* @throws IllegalArgumentException if type of <code>name</code> is
* not serializable or if the field type is incorrect
*/
public abstract float get(String name, float val) throws IOException;
/** {@collect.stats}
* {@description.open}
* Get the value of the named double field from the persistent field.
* {@description.close}
*
* @param name the name of the field
* @param val the default value to use if <code>name</code> does not
* have a value
* @return the value of the named <code>double</code> field
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
* @throws IllegalArgumentException if type of <code>name</code> is
* not serializable or if the field type is incorrect
*/
public abstract double get(String name, double val) throws IOException;
/** {@collect.stats}
* {@description.open}
* Get the value of the named Object field from the persistent field.
* {@description.close}
*
* @param name the name of the field
* @param val the default value to use if <code>name</code> does not
* have a value
* @return the value of the named <code>Object</code> field
* @throws IOException if there are I/O errors while reading from the
* underlying <code>InputStream</code>
* @throws IllegalArgumentException if type of <code>name</code> is
* not serializable or if the field type is incorrect
*/
public abstract Object get(String name, Object val) throws IOException;
}
/** {@collect.stats}
* {@description.open}
* Verifies that this (possibly subclass) instance can be constructed
* without violating security constraints: the subclass must not override
* security-sensitive non-final methods, or else the
* "enableSubclassImplementation" SerializablePermission is checked.
* {@description.close}
*/
private void verifySubclass() {
Class cl = getClass();
if (cl == ObjectInputStream.class) {
return;
}
SecurityManager sm = System.getSecurityManager();
if (sm == null) {
return;
}
processQueue(Caches.subclassAuditsQueue, Caches.subclassAudits);
WeakClassKey key = new WeakClassKey(cl, Caches.subclassAuditsQueue);
Boolean result = Caches.subclassAudits.get(key);
if (result == null) {
result = Boolean.valueOf(auditSubclass(cl));
Caches.subclassAudits.putIfAbsent(key, result);
}
if (result.booleanValue()) {
return;
}
sm.checkPermission(SUBCLASS_IMPLEMENTATION_PERMISSION);
}
/** {@collect.stats}
* {@description.open}
* Performs reflective checks on given subclass to verify that it doesn't
* override security-sensitive non-final methods. Returns true if subclass
* is "safe", false otherwise.
* {@description.close}
*/
private static boolean auditSubclass(final Class subcl) {
Boolean result = AccessController.doPrivileged(
new PrivilegedAction<Boolean>() {
public Boolean run() {
for (Class cl = subcl;
cl != ObjectInputStream.class;
cl = cl.getSuperclass())
{
try {
cl.getDeclaredMethod(
"readUnshared", (Class[]) null);
return Boolean.FALSE;
} catch (NoSuchMethodException ex) {
}
try {
cl.getDeclaredMethod("readFields", (Class[]) null);
return Boolean.FALSE;
} catch (NoSuchMethodException ex) {
}
}
return Boolean.TRUE;
}
}
);
return result.booleanValue();
}
/** {@collect.stats}
* {@description.open}
* Clears internal data structures.
* {@description.close}
*/
private void clear() {
handles.clear();
vlist.clear();
}
/** {@collect.stats}
* {@description.open}
* Underlying readObject implementation.
* {@description.close}
*/
private Object readObject0(boolean unshared) throws IOException {
boolean oldMode = bin.getBlockDataMode();
if (oldMode) {
int remain = bin.currentBlockRemaining();
if (remain > 0) {
throw new OptionalDataException(remain);
} else if (defaultDataEnd) {
/*
* Fix for 4360508: stream is currently at the end of a field
* value block written via default serialization; since there
* is no terminating TC_ENDBLOCKDATA tag, simulate
* end-of-custom-data behavior explicitly.
*/
throw new OptionalDataException(true);
}
bin.setBlockDataMode(false);
}
byte tc;
while ((tc = bin.peekByte()) == TC_RESET) {
bin.readByte();
handleReset();
}
depth++;
try {
switch (tc) {
case TC_NULL:
return readNull();
case TC_REFERENCE:
return readHandle(unshared);
case TC_CLASS:
return readClass(unshared);
case TC_CLASSDESC:
case TC_PROXYCLASSDESC:
return readClassDesc(unshared);
case TC_STRING:
case TC_LONGSTRING:
return checkResolve(readString(unshared));
case TC_ARRAY:
return checkResolve(readArray(unshared));
case TC_ENUM:
return checkResolve(readEnum(unshared));
case TC_OBJECT:
return checkResolve(readOrdinaryObject(unshared));
case TC_EXCEPTION:
IOException ex = readFatalException();
throw new WriteAbortedException("writing aborted", ex);
case TC_BLOCKDATA:
case TC_BLOCKDATALONG:
if (oldMode) {
bin.setBlockDataMode(true);
bin.peek(); // force header read
throw new OptionalDataException(
bin.currentBlockRemaining());
} else {
throw new StreamCorruptedException(
"unexpected block data");
}
case TC_ENDBLOCKDATA:
if (oldMode) {
throw new OptionalDataException(true);
} else {
throw new StreamCorruptedException(
"unexpected end of block data");
}
default:
throw new StreamCorruptedException(
String.format("invalid type code: %02X", tc));
}
} finally {
depth--;
bin.setBlockDataMode(oldMode);
}
}
/** {@collect.stats}
* {@description.open}
* If resolveObject has been enabled and given object does not have an
* exception associated with it, calls resolveObject to determine
* replacement for object, and updates handle table accordingly. Returns
* replacement object, or echoes provided object if no replacement
* occurred. Expects that passHandle is set to given object's handle prior
* to calling this method.
* {@description.close}
*/
private Object checkResolve(Object obj) throws IOException {
if (!enableResolve || handles.lookupException(passHandle) != null) {
return obj;
}
Object rep = resolveObject(obj);
if (rep != obj) {
handles.setObject(passHandle, rep);
}
return rep;
}
/** {@collect.stats}
* {@description.open}
* Reads string without allowing it to be replaced in stream. Called from
* within ObjectStreamClass.read().
* {@description.close}
*/
String readTypeString() throws IOException {
int oldHandle = passHandle;
try {
byte tc = bin.peekByte();
switch (tc) {
case TC_NULL:
return (String) readNull();
case TC_REFERENCE:
return (String) readHandle(false);
case TC_STRING:
case TC_LONGSTRING:
return readString(false);
default:
throw new StreamCorruptedException(
String.format("invalid type code: %02X", tc));
}
} finally {
passHandle = oldHandle;
}
}
/** {@collect.stats}
* {@description.open}
* Reads in null code, sets passHandle to NULL_HANDLE and returns null.
* {@description.close}
*/
private Object readNull() throws IOException {
if (bin.readByte() != TC_NULL) {
throw new InternalError();
}
passHandle = NULL_HANDLE;
return null;
}
/** {@collect.stats}
* {@description.open}
* Reads in object handle, sets passHandle to the read handle, and returns
* object associated with the handle.
* {@description.close}
*/
private Object readHandle(boolean unshared) throws IOException {
if (bin.readByte() != TC_REFERENCE) {
throw new InternalError();
}
passHandle = bin.readInt() - baseWireHandle;
if (passHandle < 0 || passHandle >= handles.size()) {
throw new StreamCorruptedException(
String.format("invalid handle value: %08X", passHandle +
baseWireHandle));
}
if (unshared) {
// REMIND: what type of exception to throw here?
throw new InvalidObjectException(
"cannot read back reference as unshared");
}
Object obj = handles.lookupObject(passHandle);
if (obj == unsharedMarker) {
// REMIND: what type of exception to throw here?
throw new InvalidObjectException(
"cannot read back reference to unshared object");
}
return obj;
}
/** {@collect.stats}
* {@description.open}
* Reads in and returns class object. Sets passHandle to class object's
* assigned handle. Returns null if class is unresolvable (in which case a
* ClassNotFoundException will be associated with the class' handle in the
* handle table).
* {@description.close}
*/
private Class readClass(boolean unshared) throws IOException {
if (bin.readByte() != TC_CLASS) {
throw new InternalError();
}
ObjectStreamClass desc = readClassDesc(false);
Class cl = desc.forClass();
passHandle = handles.assign(unshared ? unsharedMarker : cl);
ClassNotFoundException resolveEx = desc.getResolveException();
if (resolveEx != null) {
handles.markException(passHandle, resolveEx);
}
handles.finish(passHandle);
return cl;
}
/** {@collect.stats}
* {@description.open}
* Reads in and returns (possibly null) class descriptor. Sets passHandle
* to class descriptor's assigned handle. If class descriptor cannot be
* resolved to a class in the local VM, a ClassNotFoundException is
* associated with the class descriptor's handle.
* {@description.close}
*/
private ObjectStreamClass readClassDesc(boolean unshared)
throws IOException
{
byte tc = bin.peekByte();
switch (tc) {
case TC_NULL:
return (ObjectStreamClass) readNull();
case TC_REFERENCE:
return (ObjectStreamClass) readHandle(unshared);
case TC_PROXYCLASSDESC:
return readProxyDesc(unshared);
case TC_CLASSDESC:
return readNonProxyDesc(unshared);
default:
throw new StreamCorruptedException(
String.format("invalid type code: %02X", tc));
}
}
/** {@collect.stats}
* {@description.open}
* Reads in and returns class descriptor for a dynamic proxy class. Sets
* passHandle to proxy class descriptor's assigned handle. If proxy class
* descriptor cannot be resolved to a class in the local VM, a
* ClassNotFoundException is associated with the descriptor's handle.
* {@description.close}
*/
private ObjectStreamClass readProxyDesc(boolean unshared)
throws IOException
{
if (bin.readByte() != TC_PROXYCLASSDESC) {
throw new InternalError();
}
ObjectStreamClass desc = new ObjectStreamClass();
int descHandle = handles.assign(unshared ? unsharedMarker : desc);
passHandle = NULL_HANDLE;
int numIfaces = bin.readInt();
String[] ifaces = new String[numIfaces];
for (int i = 0; i < numIfaces; i++) {
ifaces[i] = bin.readUTF();
}
Class cl = null;
ClassNotFoundException resolveEx = null;
bin.setBlockDataMode(true);
try {
if ((cl = resolveProxyClass(ifaces)) == null) {
resolveEx = new ClassNotFoundException("null class");
}
} catch (ClassNotFoundException ex) {
resolveEx = ex;
}
skipCustomData();
desc.initProxy(cl, resolveEx, readClassDesc(false));
handles.finish(descHandle);
passHandle = descHandle;
return desc;
}
/** {@collect.stats}
* {@description.open}
* Reads in and returns class descriptor for a class that is not a dynamic
* proxy class. Sets passHandle to class descriptor's assigned handle. If
* class descriptor cannot be resolved to a class in the local VM, a
* ClassNotFoundException is associated with the descriptor's handle.
* {@description.close}
*/
private ObjectStreamClass readNonProxyDesc(boolean unshared)
throws IOException
{
if (bin.readByte() != TC_CLASSDESC) {
throw new InternalError();
}
ObjectStreamClass desc = new ObjectStreamClass();
int descHandle = handles.assign(unshared ? unsharedMarker : desc);
passHandle = NULL_HANDLE;
ObjectStreamClass readDesc = null;
try {
readDesc = readClassDescriptor();
} catch (ClassNotFoundException ex) {
throw (IOException) new InvalidClassException(
"failed to read class descriptor").initCause(ex);
}
Class cl = null;
ClassNotFoundException resolveEx = null;
bin.setBlockDataMode(true);
try {
if ((cl = resolveClass(readDesc)) == null) {
resolveEx = new ClassNotFoundException("null class");
}
} catch (ClassNotFoundException ex) {
resolveEx = ex;
}
skipCustomData();
desc.initNonProxy(readDesc, cl, resolveEx, readClassDesc(false));
handles.finish(descHandle);
passHandle = descHandle;
return desc;
}
/** {@collect.stats}
* {@description.open}
* Reads in and returns new string. Sets passHandle to new string's
* assigned handle.
* {@description.close}
*/
private String readString(boolean unshared) throws IOException {
String str;
byte tc = bin.readByte();
switch (tc) {
case TC_STRING:
str = bin.readUTF();
break;
case TC_LONGSTRING:
str = bin.readLongUTF();
break;
default:
throw new StreamCorruptedException(
String.format("invalid type code: %02X", tc));
}
passHandle = handles.assign(unshared ? unsharedMarker : str);
handles.finish(passHandle);
return str;
}
/** {@collect.stats}
* {@description.open}
* Reads in and returns array object, or null if array class is
* unresolvable. Sets passHandle to array's assigned handle.
* {@description.close}
*/
private Object readArray(boolean unshared) throws IOException {
if (bin.readByte() != TC_ARRAY) {
throw new InternalError();
}
ObjectStreamClass desc = readClassDesc(false);
int len = bin.readInt();
Object array = null;
Class cl, ccl = null;
if ((cl = desc.forClass()) != null) {
ccl = cl.getComponentType();
array = Array.newInstance(ccl, len);
}
int arrayHandle = handles.assign(unshared ? unsharedMarker : array);
ClassNotFoundException resolveEx = desc.getResolveException();
if (resolveEx != null) {
handles.markException(arrayHandle, resolveEx);
}
if (ccl == null) {
for (int i = 0; i < len; i++) {
readObject0(false);
}
} else if (ccl.isPrimitive()) {
if (ccl == Integer.TYPE) {
bin.readInts((int[]) array, 0, len);
} else if (ccl == Byte.TYPE) {
bin.readFully((byte[]) array, 0, len, true);
} else if (ccl == Long.TYPE) {
bin.readLongs((long[]) array, 0, len);
} else if (ccl == Float.TYPE) {
bin.readFloats((float[]) array, 0, len);
} else if (ccl == Double.TYPE) {
bin.readDoubles((double[]) array, 0, len);
} else if (ccl == Short.TYPE) {
bin.readShorts((short[]) array, 0, len);
} else if (ccl == Character.TYPE) {
bin.readChars((char[]) array, 0, len);
} else if (ccl == Boolean.TYPE) {
bin.readBooleans((boolean[]) array, 0, len);
} else {
throw new InternalError();
}
} else {
Object[] oa = (Object[]) array;
for (int i = 0; i < len; i++) {
oa[i] = readObject0(false);
handles.markDependency(arrayHandle, passHandle);
}
}
handles.finish(arrayHandle);
passHandle = arrayHandle;
return array;
}
/** {@collect.stats}
* {@description.open}
* Reads in and returns enum constant, or null if enum type is
* unresolvable. Sets passHandle to enum constant's assigned handle.
* {@description.close}
*/
private Enum readEnum(boolean unshared) throws IOException {
if (bin.readByte() != TC_ENUM) {
throw new InternalError();
}
ObjectStreamClass desc = readClassDesc(false);
if (!desc.isEnum()) {
throw new InvalidClassException("non-enum class: " + desc);
}
int enumHandle = handles.assign(unshared ? unsharedMarker : null);
ClassNotFoundException resolveEx = desc.getResolveException();
if (resolveEx != null) {
handles.markException(enumHandle, resolveEx);
}
String name = readString(false);
Enum en = null;
Class cl = desc.forClass();
if (cl != null) {
try {
en = Enum.valueOf(cl, name);
} catch (IllegalArgumentException ex) {
throw (IOException) new InvalidObjectException(
"enum constant " + name + " does not exist in " +
cl).initCause(ex);
}
if (!unshared) {
handles.setObject(enumHandle, en);
}
}
handles.finish(enumHandle);
passHandle = enumHandle;
return en;
}
/** {@collect.stats}
* {@description.open}
* Reads and returns "ordinary" (i.e., not a String, Class,
* ObjectStreamClass, array, or enum constant) object, or null if object's
* class is unresolvable (in which case a ClassNotFoundException will be
* associated with object's handle). Sets passHandle to object's assigned
* handle.
* {@description.close}
*/
private Object readOrdinaryObject(boolean unshared)
throws IOException
{
if (bin.readByte() != TC_OBJECT) {
throw new InternalError();
}
ObjectStreamClass desc = readClassDesc(false);
desc.checkDeserialize();
Object obj;
try {
obj = desc.isInstantiable() ? desc.newInstance() : null;
} catch (Exception ex) {
throw (IOException) new InvalidClassException(
desc.forClass().getName(),
"unable to create instance").initCause(ex);
}
passHandle = handles.assign(unshared ? unsharedMarker : obj);
ClassNotFoundException resolveEx = desc.getResolveException();
if (resolveEx != null) {
handles.markException(passHandle, resolveEx);
}
if (desc.isExternalizable()) {
readExternalData((Externalizable) obj, desc);
} else {
readSerialData(obj, desc);
}
handles.finish(passHandle);
if (obj != null &&
handles.lookupException(passHandle) == null &&
desc.hasReadResolveMethod())
{
Object rep = desc.invokeReadResolve(obj);
if (unshared && rep.getClass().isArray()) {
rep = cloneArray(rep);
}
if (rep != obj) {
handles.setObject(passHandle, obj = rep);
}
}
return obj;
}
/** {@collect.stats}
* {@description.open}
* If obj is non-null, reads externalizable data by invoking readExternal()
* method of obj; otherwise, attempts to skip over externalizable data.
* Expects that passHandle is set to obj's handle before this method is
* called.
* {@description.close}
*/
private void readExternalData(Externalizable obj, ObjectStreamClass desc)
throws IOException
{
SerialCallbackContext oldContext = curContext;
curContext = null;
try {
boolean blocked = desc.hasBlockExternalData();
if (blocked) {
bin.setBlockDataMode(true);
}
if (obj != null) {
try {
obj.readExternal(this);
} catch (ClassNotFoundException ex) {
/*
* In most cases, the handle table has already propagated
* a CNFException to passHandle at this point; this mark
* call is included to address cases where the readExternal
* method has cons'ed and thrown a new CNFException of its
* own.
*/
handles.markException(passHandle, ex);
}
}
if (blocked) {
skipCustomData();
}
} finally {
curContext = oldContext;
}
/*
* At this point, if the externalizable data was not written in
* block-data form and either the externalizable class doesn't exist
* locally (i.e., obj == null) or readExternal() just threw a
* CNFException, then the stream is probably in an inconsistent state,
* since some (or all) of the externalizable data may not have been
* consumed. Since there's no "correct" action to take in this case,
* we mimic the behavior of past serialization implementations and
* blindly hope that the stream is in sync; if it isn't and additional
* externalizable data remains in the stream, a subsequent read will
* most likely throw a StreamCorruptedException.
*/
}
/** {@collect.stats}
* {@description.open}
* Reads (or attempts to skip, if obj is null or is tagged with a
* ClassNotFoundException) instance data for each serializable class of
* object in stream, from superclass to subclass. Expects that passHandle
* is set to obj's handle before this method is called.
* {@description.close}
*/
private void readSerialData(Object obj, ObjectStreamClass desc)
throws IOException
{
ObjectStreamClass.ClassDataSlot[] slots = desc.getClassDataLayout();
for (int i = 0; i < slots.length; i++) {
ObjectStreamClass slotDesc = slots[i].desc;
if (slots[i].hasData) {
if (obj != null &&
slotDesc.hasReadObjectMethod() &&
handles.lookupException(passHandle) == null)
{
SerialCallbackContext oldContext = curContext;
try {
curContext = new SerialCallbackContext(obj, slotDesc);
bin.setBlockDataMode(true);
slotDesc.invokeReadObject(obj, this);
} catch (ClassNotFoundException ex) {
/*
* In most cases, the handle table has already
* propagated a CNFException to passHandle at this
* point; this mark call is included to address cases
* where the custom readObject method has cons'ed and
* thrown a new CNFException of its own.
*/
handles.markException(passHandle, ex);
} finally {
curContext.setUsed();
curContext = oldContext;
}
/*
* defaultDataEnd may have been set indirectly by custom
* readObject() method when calling defaultReadObject() or
* readFields(); clear it to restore normal read behavior.
*/
defaultDataEnd = false;
} else {
defaultReadFields(obj, slotDesc);
}
if (slotDesc.hasWriteObjectData()) {
skipCustomData();
} else {
bin.setBlockDataMode(false);
}
} else {
if (obj != null &&
slotDesc.hasReadObjectNoDataMethod() &&
handles.lookupException(passHandle) == null)
{
slotDesc.invokeReadObjectNoData(obj);
}
}
}
}
/** {@collect.stats}
* {@description.open}
* Skips over all block data and objects until TC_ENDBLOCKDATA is
* encountered.
* {@description.close}
*/
private void skipCustomData() throws IOException {
int oldHandle = passHandle;
for (;;) {
if (bin.getBlockDataMode()) {
bin.skipBlockData();
bin.setBlockDataMode(false);
}
switch (bin.peekByte()) {
case TC_BLOCKDATA:
case TC_BLOCKDATALONG:
bin.setBlockDataMode(true);
break;
case TC_ENDBLOCKDATA:
bin.readByte();
passHandle = oldHandle;
return;
default:
readObject0(false);
break;
}
}
}
/** {@collect.stats}
* {@description.open}
* Reads in values of serializable fields declared by given class
* descriptor. If obj is non-null, sets field values in obj. Expects that
* passHandle is set to obj's handle before this method is called.
* {@description.close}
*/
private void defaultReadFields(Object obj, ObjectStreamClass desc)
throws IOException
{
// REMIND: is isInstance check necessary?
Class cl = desc.forClass();
if (cl != null && obj != null && !cl.isInstance(obj)) {
throw new ClassCastException();
}
int primDataSize = desc.getPrimDataSize();
if (primVals == null || primVals.length < primDataSize) {
primVals = new byte[primDataSize];
}
bin.readFully(primVals, 0, primDataSize, false);
if (obj != null) {
desc.setPrimFieldValues(obj, primVals);
}
int objHandle = passHandle;
ObjectStreamField[] fields = desc.getFields(false);
Object[] objVals = new Object[desc.getNumObjFields()];
int numPrimFields = fields.length - objVals.length;
for (int i = 0; i < objVals.length; i++) {
ObjectStreamField f = fields[numPrimFields + i];
objVals[i] = readObject0(f.isUnshared());
if (f.getField() != null) {
handles.markDependency(objHandle, passHandle);
}
}
if (obj != null) {
desc.setObjFieldValues(obj, objVals);
}
passHandle = objHandle;
}
/** {@collect.stats}
* {@description.open}
* Reads in and returns IOException that caused serialization to abort.
* All stream state is discarded prior to reading in fatal exception. Sets
* passHandle to fatal exception's handle.
* {@description.close}
*/
private IOException readFatalException() throws IOException {
if (bin.readByte() != TC_EXCEPTION) {
throw new InternalError();
}
clear();
return (IOException) readObject0(false);
}
/** {@collect.stats}
* {@description.open}
* If recursion depth is 0, clears internal data structures; otherwise,
* throws a StreamCorruptedException. This method is called when a
* TC_RESET typecode is encountered.
* {@description.close}
*/
private void handleReset() throws StreamCorruptedException {
if (depth > 0) {
throw new StreamCorruptedException(
"unexpected reset; recursion depth: " + depth);
}
clear();
}
/** {@collect.stats}
* {@description.open}
* Converts specified span of bytes into float values.
* {@description.close}
*/
// REMIND: remove once hotspot inlines Float.intBitsToFloat
private static native void bytesToFloats(byte[] src, int srcpos,
float[] dst, int dstpos,
int nfloats);
/** {@collect.stats}
* {@description.open}
* Converts specified span of bytes into double values.
* {@description.close}
*/
// REMIND: remove once hotspot inlines Double.longBitsToDouble
private static native void bytesToDoubles(byte[] src, int srcpos,
double[] dst, int dstpos,
int ndoubles);
/** {@collect.stats}
* {@description.open}
* Returns the first non-null class loader (not counting class loaders of
* generated reflection implementation classes) up the execution stack, or
* null if only code from the null class loader is on the stack. This
* method is also called via reflection by the following RMI-IIOP class:
*
* com.sun.corba.se.internal.util.JDKClassLoader
*
* This method should not be removed or its signature changed without
* corresponding modifications to the above class.
* {@description.close}
*/
// REMIND: change name to something more accurate?
private static native ClassLoader latestUserDefinedLoader();
/** {@collect.stats}
* {@description.open}
* Default GetField implementation.
* {@description.close}
*/
private class GetFieldImpl extends GetField {
/** {@collect.stats}
* {@description.open}
* class descriptor describing serializable fields
* {@description.close}
*/
private final ObjectStreamClass desc;
/** {@collect.stats}
* {@description.open}
* primitive field values
* {@description.close}
*/
private final byte[] primVals;
/** {@collect.stats}
* {@description.open}
* object field values
* {@description.close}
*/
private final Object[] objVals;
/** {@collect.stats}
* {@description.open}
* object field value handles
* {@description.close}
*/
private final int[] objHandles;
/** {@collect.stats}
* {@description.open}
* Creates GetFieldImpl object for reading fields defined in given
* class descriptor.
* {@description.close}
*/
GetFieldImpl(ObjectStreamClass desc) {
this.desc = desc;
primVals = new byte[desc.getPrimDataSize()];
objVals = new Object[desc.getNumObjFields()];
objHandles = new int[objVals.length];
}
public ObjectStreamClass getObjectStreamClass() {
return desc;
}
public boolean defaulted(String name) throws IOException {
return (getFieldOffset(name, null) < 0);
}
public boolean get(String name, boolean val) throws IOException {
int off = getFieldOffset(name, Boolean.TYPE);
return (off >= 0) ? Bits.getBoolean(primVals, off) : val;
}
public byte get(String name, byte val) throws IOException {
int off = getFieldOffset(name, Byte.TYPE);
return (off >= 0) ? primVals[off] : val;
}
public char get(String name, char val) throws IOException {
int off = getFieldOffset(name, Character.TYPE);
return (off >= 0) ? Bits.getChar(primVals, off) : val;
}
public short get(String name, short val) throws IOException {
int off = getFieldOffset(name, Short.TYPE);
return (off >= 0) ? Bits.getShort(primVals, off) : val;
}
public int get(String name, int val) throws IOException {
int off = getFieldOffset(name, Integer.TYPE);
return (off >= 0) ? Bits.getInt(primVals, off) : val;
}
public float get(String name, float val) throws IOException {
int off = getFieldOffset(name, Float.TYPE);
return (off >= 0) ? Bits.getFloat(primVals, off) : val;
}
public long get(String name, long val) throws IOException {
int off = getFieldOffset(name, Long.TYPE);
return (off >= 0) ? Bits.getLong(primVals, off) : val;
}
public double get(String name, double val) throws IOException {
int off = getFieldOffset(name, Double.TYPE);
return (off >= 0) ? Bits.getDouble(primVals, off) : val;
}
public Object get(String name, Object val) throws IOException {
int off = getFieldOffset(name, Object.class);
if (off >= 0) {
int objHandle = objHandles[off];
handles.markDependency(passHandle, objHandle);
return (handles.lookupException(objHandle) == null) ?
objVals[off] : null;
} else {
return val;
}
}
/** {@collect.stats}
* {@description.open}
* Reads primitive and object field values from stream.
* {@description.close}
*/
void readFields() throws IOException {
bin.readFully(primVals, 0, primVals.length, false);
int oldHandle = passHandle;
ObjectStreamField[] fields = desc.getFields(false);
int numPrimFields = fields.length - objVals.length;
for (int i = 0; i < objVals.length; i++) {
objVals[i] =
readObject0(fields[numPrimFields + i].isUnshared());
objHandles[i] = passHandle;
}
passHandle = oldHandle;
}
/** {@collect.stats}
* {@description.open}
* Returns offset of field with given name and type. A specified type
* of null matches all types, Object.class matches all non-primitive
* types, and any other non-null type matches assignable types only.
* If no matching field is found in the (incoming) class
* descriptor but a matching field is present in the associated local
* class descriptor, returns -1. Throws IllegalArgumentException if
* neither incoming nor local class descriptor contains a match.
* {@description.close}
*/
private int getFieldOffset(String name, Class type) {
ObjectStreamField field = desc.getField(name, type);
if (field != null) {
return field.getOffset();
} else if (desc.getLocalDesc().getField(name, type) != null) {
return -1;
} else {
throw new IllegalArgumentException("no such field " + name +
" with type " + type);
}
}
}
/** {@collect.stats}
* {@description.open}
* Prioritized list of callbacks to be performed once object graph has been
* completely deserialized.
* {@description.close}
*/
private static class ValidationList {
private static class Callback {
final ObjectInputValidation obj;
final int priority;
Callback next;
final AccessControlContext acc;
Callback(ObjectInputValidation obj, int priority, Callback next,
AccessControlContext acc)
{
this.obj = obj;
this.priority = priority;
this.next = next;
this.acc = acc;
}
}
/** {@collect.stats}
* {@description.open}
* linked list of callbacks
* {@description.close}
*/
private Callback list;
/** {@collect.stats}
* {@description.open}
* Creates new (empty) ValidationList.
* {@description.close}
*/
ValidationList() {
}
/** {@collect.stats}
* {@description.open}
* Registers callback. Throws InvalidObjectException if callback
* object is null.
* {@description.close}
*/
void register(ObjectInputValidation obj, int priority)
throws InvalidObjectException
{
if (obj == null) {
throw new InvalidObjectException("null callback");
}
Callback prev = null, cur = list;
while (cur != null && priority < cur.priority) {
prev = cur;
cur = cur.next;
}
AccessControlContext acc = AccessController.getContext();
if (prev != null) {
prev.next = new Callback(obj, priority, cur, acc);
} else {
list = new Callback(obj, priority, list, acc);
}
}
/** {@collect.stats}
* {@description.open}
* Invokes all registered callbacks and clears the callback list.
* Callbacks with higher priorities are called first; those with equal
* priorities may be called in any order. If any of the callbacks
* throws an InvalidObjectException, the callback process is terminated
* and the exception propagated upwards.
* {@description.close}
*/
void doCallbacks() throws InvalidObjectException {
try {
while (list != null) {
AccessController.doPrivileged(
new PrivilegedExceptionAction()
{
public Object run() throws InvalidObjectException {
list.obj.validateObject();
return null;
}
}, list.acc);
list = list.next;
}
} catch (PrivilegedActionException ex) {
list = null;
throw (InvalidObjectException) ex.getException();
}
}
/** {@collect.stats}
* {@description.open}
* Resets the callback list to its initial (empty) state.
* {@description.close}
*/
public void clear() {
list = null;
}
}
/** {@collect.stats}
* {@description.open}
* Input stream supporting single-byte peek operations.
* {@description.close}
*/
private static class PeekInputStream extends InputStream {
/** {@collect.stats}
* {@description.open}
* underlying stream
* {@description.close}
*/
private final InputStream in;
/** {@collect.stats}
* {@description.open}
* peeked byte
* {@description.close}
*/
private int peekb = -1;
/** {@collect.stats}
* {@description.open}
* Creates new PeekInputStream on top of given underlying stream.
* {@description.close}
*/
PeekInputStream(InputStream in) {
this.in = in;
}
/** {@collect.stats}
* {@description.open}
* Peeks at next byte value in stream. Similar to read(), except
* that it does not consume the read value.
* {@description.close}
*/
int peek() throws IOException {
return (peekb >= 0) ? peekb : (peekb = in.read());
}
public int read() throws IOException {
if (peekb >= 0) {
int v = peekb;
peekb = -1;
return v;
} else {
return in.read();
}
}
public int read(byte[] b, int off, int len) throws IOException {
if (len == 0) {
return 0;
} else if (peekb < 0) {
return in.read(b, off, len);
} else {
b[off++] = (byte) peekb;
len--;
peekb = -1;
int n = in.read(b, off, len);
return (n >= 0) ? (n + 1) : 1;
}
}
void readFully(byte[] b, int off, int len) throws IOException {
int n = 0;
while (n < len) {
int count = read(b, off + n, len - n);
if (count < 0) {
throw new EOFException();
}
n += count;
}
}
public long skip(long n) throws IOException {
if (n <= 0) {
return 0;
}
int skipped = 0;
if (peekb >= 0) {
peekb = -1;
skipped++;
n--;
}
return skipped + skip(n);
}
public int available() throws IOException {
return in.available() + ((peekb >= 0) ? 1 : 0);
}
public void close() throws IOException {
in.close();
}
}
/** {@collect.stats}
* {@description.open}
* Input stream with two modes: in default mode, inputs data written in the
* same format as DataOutputStream; in "block data" mode, inputs data
* bracketed by block data markers (see object serialization specification
* for details). Buffering depends on block data mode: when in default
* mode, no data is buffered in advance; when in block data mode, all data
* for the current data block is read in at once (and buffered).
* {@description.close}
*/
private class BlockDataInputStream
extends InputStream implements DataInput
{
/** {@collect.stats}
* {@description.open}
* maximum data block length
* {@description.close}
*/
private static final int MAX_BLOCK_SIZE = 1024;
/** {@collect.stats}
* {@description.open}
* maximum data block header length
* {@description.close}
*/
private static final int MAX_HEADER_SIZE = 5;
/** {@collect.stats}
* {@description.open}
* (tunable) length of char buffer (for reading strings)
* {@description.close}
*/
private static final int CHAR_BUF_SIZE = 256;
/** {@collect.stats}
* {@description.open}
* readBlockHeader() return value indicating header read may block
* {@description.close}
*/
private static final int HEADER_BLOCKED = -2;
/** {@collect.stats}
* {@description.open}
* buffer for reading general/block data
* {@description.close}
*/
private final byte[] buf = new byte[MAX_BLOCK_SIZE];
/** {@collect.stats}
* {@description.open}
* buffer for reading block data headers
* {@description.close}
*/
private final byte[] hbuf = new byte[MAX_HEADER_SIZE];
/** {@collect.stats}
* {@description.open}
* char buffer for fast string reads
* {@description.close}
*/
private final char[] cbuf = new char[CHAR_BUF_SIZE];
/** {@collect.stats}
* {@description.open}
* block data mode
* {@description.close}
*/
private boolean blkmode = false;
// block data state fields; values meaningful only when blkmode true
/** {@collect.stats}
* {@description.open}
* current offset into buf
* {@description.close}
*/
private int pos = 0;
/** {@collect.stats}
* {@description.open}
* end offset of valid data in buf, or -1 if no more block data
* {@description.close}
*/
private int end = -1;
/** {@collect.stats}
* {@description.open}
* number of bytes in current block yet to be read from stream
* {@description.close}
*/
private int unread = 0;
/** {@collect.stats}
* {@description.open}
* underlying stream (wrapped in peekable filter stream)
* {@description.close}
*/
private final PeekInputStream in;
/** {@collect.stats}
* {@description.open}
* loopback stream (for data reads that span data blocks)
* {@description.close}
*/
private final DataInputStream din;
/** {@collect.stats}
* {@description.open}
* Creates new BlockDataInputStream on top of given underlying stream.
* Block data mode is turned off by default.
* {@description.close}
*/
BlockDataInputStream(InputStream in) {
this.in = new PeekInputStream(in);
din = new DataInputStream(this);
}
/** {@collect.stats}
* {@description.open}
* Sets block data mode to the given mode (true == on, false == off)
* and returns the previous mode value. If the new mode is the same as
* the old mode, no action is taken. Throws IllegalStateException if
* block data mode is being switched from on to off while unconsumed
* block data is still present in the stream.
* {@description.close}
*/
boolean setBlockDataMode(boolean newmode) throws IOException {
if (blkmode == newmode) {
return blkmode;
}
if (newmode) {
pos = 0;
end = 0;
unread = 0;
} else if (pos < end) {
throw new IllegalStateException("unread block data");
}
blkmode = newmode;
return !blkmode;
}
/** {@collect.stats}
* {@description.open}
* Returns true if the stream is currently in block data mode, false
* otherwise.
* {@description.close}
*/
boolean getBlockDataMode() {
return blkmode;
}
/** {@collect.stats}
* {@description.open}
* If in block data mode, skips to the end of the current group of data
* blocks (but does not unset block data mode). If not in block data
* mode, throws an IllegalStateException.
* {@description.close}
*/
void skipBlockData() throws IOException {
if (!blkmode) {
throw new IllegalStateException("not in block data mode");
}
while (end >= 0) {
refill();
}
}
/** {@collect.stats}
* {@description.open}
* Attempts to read in the next block data header (if any). If
* canBlock is false and a full header cannot be read without possibly
* blocking, returns HEADER_BLOCKED, else if the next element in the
* stream is a block data header, returns the block data length
* specified by the header, else returns -1.
* {@description.close}
*/
private int readBlockHeader(boolean canBlock) throws IOException {
if (defaultDataEnd) {
/*
* Fix for 4360508: stream is currently at the end of a field
* value block written via default serialization; since there
* is no terminating TC_ENDBLOCKDATA tag, simulate
* end-of-custom-data behavior explicitly.
*/
return -1;
}
try {
for (;;) {
int avail = canBlock ? Integer.MAX_VALUE : in.available();
if (avail == 0) {
return HEADER_BLOCKED;
}
int tc = in.peek();
switch (tc) {
case TC_BLOCKDATA:
if (avail < 2) {
return HEADER_BLOCKED;
}
in.readFully(hbuf, 0, 2);
return hbuf[1] & 0xFF;
case TC_BLOCKDATALONG:
if (avail < 5) {
return HEADER_BLOCKED;
}
in.readFully(hbuf, 0, 5);
int len = Bits.getInt(hbuf, 1);
if (len < 0) {
throw new StreamCorruptedException(
"illegal block data header length: " +
len);
}
return len;
/*
* TC_RESETs may occur in between data blocks.
* Unfortunately, this case must be parsed at a lower
* level than other typecodes, since primitive data
* reads may span data blocks separated by a TC_RESET.
*/
case TC_RESET:
in.read();
handleReset();
break;
default:
if (tc >= 0 && (tc < TC_BASE || tc > TC_MAX)) {
throw new StreamCorruptedException(
String.format("invalid type code: %02X",
tc));
}
return -1;
}
}
} catch (EOFException ex) {
throw new StreamCorruptedException(
"unexpected EOF while reading block data header");
}
}
/** {@collect.stats}
* {@description.open}
* Refills internal buffer buf with block data. Any data in buf at the
* time of the call is considered consumed. Sets the pos, end, and
* unread fields to reflect the new amount of available block data; if
* the next element in the stream is not a data block, sets pos and
* unread to 0 and end to -1.
* {@description.close}
*/
private void refill() throws IOException {
try {
do {
pos = 0;
if (unread > 0) {
int n =
in.read(buf, 0, Math.min(unread, MAX_BLOCK_SIZE));
if (n >= 0) {
end = n;
unread -= n;
} else {
throw new StreamCorruptedException(
"unexpected EOF in middle of data block");
}
} else {
int n = readBlockHeader(true);
if (n >= 0) {
end = 0;
unread = n;
} else {
end = -1;
unread = 0;
}
}
} while (pos == end);
} catch (IOException ex) {
pos = 0;
end = -1;
unread = 0;
throw ex;
}
}
/** {@collect.stats}
* {@description.open}
* If in block data mode, returns the number of unconsumed bytes
* remaining in the current data block. If not in block data mode,
* throws an IllegalStateException.
* {@description.close}
*/
int currentBlockRemaining() {
if (blkmode) {
return (end >= 0) ? (end - pos) + unread : 0;
} else {
throw new IllegalStateException();
}
}
/** {@collect.stats}
* {@description.open}
* Peeks at (but does not consume) and returns the next byte value in
* the stream, or -1 if the end of the stream/block data (if in block
* data mode) has been reached.
* {@description.close}
*/
int peek() throws IOException {
if (blkmode) {
if (pos == end) {
refill();
}
return (end >= 0) ? (buf[pos] & 0xFF) : -1;
} else {
return in.peek();
}
}
/** {@collect.stats}
* {@description.open}
* Peeks at (but does not consume) and returns the next byte value in
* the stream, or throws EOFException if end of stream/block data has
* been reached.
* {@description.close}
*/
byte peekByte() throws IOException {
int val = peek();
if (val < 0) {
throw new EOFException();
}
return (byte) val;
}
/* ----------------- generic input stream methods ------------------ */
/*
* The following methods are equivalent to their counterparts in
* InputStream, except that they interpret data block boundaries and
* read the requested data from within data blocks when in block data
* mode.
*/
public int read() throws IOException {
if (blkmode) {
if (pos == end) {
refill();
}
return (end >= 0) ? (buf[pos++] & 0xFF) : -1;
} else {
return in.read();
}
}
public int read(byte[] b, int off, int len) throws IOException {
return read(b, off, len, false);
}
public long skip(long len) throws IOException {
long remain = len;
while (remain > 0) {
if (blkmode) {
if (pos == end) {
refill();
}
if (end < 0) {
break;
}
int nread = (int) Math.min(remain, end - pos);
remain -= nread;
pos += nread;
} else {
int nread = (int) Math.min(remain, MAX_BLOCK_SIZE);
if ((nread = in.read(buf, 0, nread)) < 0) {
break;
}
remain -= nread;
}
}
return len - remain;
}
public int available() throws IOException {
if (blkmode) {
if ((pos == end) && (unread == 0)) {
int n;
while ((n = readBlockHeader(false)) == 0) ;
switch (n) {
case HEADER_BLOCKED:
break;
case -1:
pos = 0;
end = -1;
break;
default:
pos = 0;
end = 0;
unread = n;
break;
}
}
// avoid unnecessary call to in.available() if possible
int unreadAvail = (unread > 0) ?
Math.min(in.available(), unread) : 0;
return (end >= 0) ? (end - pos) + unreadAvail : 0;
} else {
return in.available();
}
}
public void close() throws IOException {
if (blkmode) {
pos = 0;
end = -1;
unread = 0;
}
in.close();
}
/** {@collect.stats}
* {@description.open}
* Attempts to read len bytes into byte array b at offset off. Returns
* the number of bytes read, or -1 if the end of stream/block data has
* been reached. If copy is true, reads values into an intermediate
* buffer before copying them to b (to avoid exposing a reference to
* b).
* {@description.close}
*/
int read(byte[] b, int off, int len, boolean copy) throws IOException {
if (len == 0) {
return 0;
} else if (blkmode) {
if (pos == end) {
refill();
}
if (end < 0) {
return -1;
}
int nread = Math.min(len, end - pos);
System.arraycopy(buf, pos, b, off, nread);
pos += nread;
return nread;
} else if (copy) {
int nread = in.read(buf, 0, Math.min(len, MAX_BLOCK_SIZE));
if (nread > 0) {
System.arraycopy(buf, 0, b, off, nread);
}
return nread;
} else {
return in.read(b, off, len);
}
}
/* ----------------- primitive data input methods ------------------ */
/*
* The following methods are equivalent to their counterparts in
* DataInputStream, except that they interpret data block boundaries
* and read the requested data from within data blocks when in block
* data mode.
*/
public void readFully(byte[] b) throws IOException {
readFully(b, 0, b.length, false);
}
public void readFully(byte[] b, int off, int len) throws IOException {
readFully(b, off, len, false);
}
public void readFully(byte[] b, int off, int len, boolean copy)
throws IOException
{
while (len > 0) {
int n = read(b, off, len, copy);
if (n < 0) {
throw new EOFException();
}
off += n;
len -= n;
}
}
public int skipBytes(int n) throws IOException {
return din.skipBytes(n);
}
public boolean readBoolean() throws IOException {
int v = read();
if (v < 0) {
throw new EOFException();
}
return (v != 0);
}
public byte readByte() throws IOException {
int v = read();
if (v < 0) {
throw new EOFException();
}
return (byte) v;
}
public int readUnsignedByte() throws IOException {
int v = read();
if (v < 0) {
throw new EOFException();
}
return v;
}
public char readChar() throws IOException {
if (!blkmode) {
pos = 0;
in.readFully(buf, 0, 2);
} else if (end - pos < 2) {
return din.readChar();
}
char v = Bits.getChar(buf, pos);
pos += 2;
return v;
}
public short readShort() throws IOException {
if (!blkmode) {
pos = 0;
in.readFully(buf, 0, 2);
} else if (end - pos < 2) {
return din.readShort();
}
short v = Bits.getShort(buf, pos);
pos += 2;
return v;
}
public int readUnsignedShort() throws IOException {
if (!blkmode) {
pos = 0;
in.readFully(buf, 0, 2);
} else if (end - pos < 2) {
return din.readUnsignedShort();
}
int v = Bits.getShort(buf, pos) & 0xFFFF;
pos += 2;
return v;
}
public int readInt() throws IOException {
if (!blkmode) {
pos = 0;
in.readFully(buf, 0, 4);
} else if (end - pos < 4) {
return din.readInt();
}
int v = Bits.getInt(buf, pos);
pos += 4;
return v;
}
public float readFloat() throws IOException {
if (!blkmode) {
pos = 0;
in.readFully(buf, 0, 4);
} else if (end - pos < 4) {
return din.readFloat();
}
float v = Bits.getFloat(buf, pos);
pos += 4;
return v;
}
public long readLong() throws IOException {
if (!blkmode) {
pos = 0;
in.readFully(buf, 0, 8);
} else if (end - pos < 8) {
return din.readLong();
}
long v = Bits.getLong(buf, pos);
pos += 8;
return v;
}
public double readDouble() throws IOException {
if (!blkmode) {
pos = 0;
in.readFully(buf, 0, 8);
} else if (end - pos < 8) {
return din.readDouble();
}
double v = Bits.getDouble(buf, pos);
pos += 8;
return v;
}
public String readUTF() throws IOException {
return readUTFBody(readUnsignedShort());
}
public String readLine() throws IOException {
return din.readLine(); // deprecated, not worth optimizing
}
/* -------------- primitive data array input methods --------------- */
/*
* The following methods read in spans of primitive data values.
* Though equivalent to calling the corresponding primitive read
* methods repeatedly, these methods are optimized for reading groups
* of primitive data values more efficiently.
*/
void readBooleans(boolean[] v, int off, int len) throws IOException {
int stop, endoff = off + len;
while (off < endoff) {
if (!blkmode) {
int span = Math.min(endoff - off, MAX_BLOCK_SIZE);
in.readFully(buf, 0, span);
stop = off + span;
pos = 0;
} else if (end - pos < 1) {
v[off++] = din.readBoolean();
continue;
} else {
stop = Math.min(endoff, off + end - pos);
}
while (off < stop) {
v[off++] = Bits.getBoolean(buf, pos++);
}
}
}
void readChars(char[] v, int off, int len) throws IOException {
int stop, endoff = off + len;
while (off < endoff) {
if (!blkmode) {
int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 1);
in.readFully(buf, 0, span << 1);
stop = off + span;
pos = 0;
} else if (end - pos < 2) {
v[off++] = din.readChar();
continue;
} else {
stop = Math.min(endoff, off + ((end - pos) >> 1));
}
while (off < stop) {
v[off++] = Bits.getChar(buf, pos);
pos += 2;
}
}
}
void readShorts(short[] v, int off, int len) throws IOException {
int stop, endoff = off + len;
while (off < endoff) {
if (!blkmode) {
int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 1);
in.readFully(buf, 0, span << 1);
stop = off + span;
pos = 0;
} else if (end - pos < 2) {
v[off++] = din.readShort();
continue;
} else {
stop = Math.min(endoff, off + ((end - pos) >> 1));
}
while (off < stop) {
v[off++] = Bits.getShort(buf, pos);
pos += 2;
}
}
}
void readInts(int[] v, int off, int len) throws IOException {
int stop, endoff = off + len;
while (off < endoff) {
if (!blkmode) {
int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 2);
in.readFully(buf, 0, span << 2);
stop = off + span;
pos = 0;
} else if (end - pos < 4) {
v[off++] = din.readInt();
continue;
} else {
stop = Math.min(endoff, off + ((end - pos) >> 2));
}
while (off < stop) {
v[off++] = Bits.getInt(buf, pos);
pos += 4;
}
}
}
void readFloats(float[] v, int off, int len) throws IOException {
int span, endoff = off + len;
while (off < endoff) {
if (!blkmode) {
span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 2);
in.readFully(buf, 0, span << 2);
pos = 0;
} else if (end - pos < 4) {
v[off++] = din.readFloat();
continue;
} else {
span = Math.min(endoff - off, ((end - pos) >> 2));
}
bytesToFloats(buf, pos, v, off, span);
off += span;
pos += span << 2;
}
}
void readLongs(long[] v, int off, int len) throws IOException {
int stop, endoff = off + len;
while (off < endoff) {
if (!blkmode) {
int span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 3);
in.readFully(buf, 0, span << 3);
stop = off + span;
pos = 0;
} else if (end - pos < 8) {
v[off++] = din.readLong();
continue;
} else {
stop = Math.min(endoff, off + ((end - pos) >> 3));
}
while (off < stop) {
v[off++] = Bits.getLong(buf, pos);
pos += 8;
}
}
}
void readDoubles(double[] v, int off, int len) throws IOException {
int span, endoff = off + len;
while (off < endoff) {
if (!blkmode) {
span = Math.min(endoff - off, MAX_BLOCK_SIZE >> 3);
in.readFully(buf, 0, span << 3);
pos = 0;
} else if (end - pos < 8) {
v[off++] = din.readDouble();
continue;
} else {
span = Math.min(endoff - off, ((end - pos) >> 3));
}
bytesToDoubles(buf, pos, v, off, span);
off += span;
pos += span << 3;
}
}
/** {@collect.stats}
* {@description.open}
* Reads in string written in "long" UTF format. "Long" UTF format is
* identical to standard UTF, except that it uses an 8 byte header
* (instead of the standard 2 bytes) to convey the UTF encoding length.
* {@description.close}
*/
String readLongUTF() throws IOException {
return readUTFBody(readLong());
}
/** {@collect.stats}
* {@description.open}
* Reads in the "body" (i.e., the UTF representation minus the 2-byte
* or 8-byte length header) of a UTF encoding, which occupies the next
* utflen bytes.
* {@description.close}
*/
private String readUTFBody(long utflen) throws IOException {
StringBuilder sbuf = new StringBuilder();
if (!blkmode) {
end = pos = 0;
}
while (utflen > 0) {
int avail = end - pos;
if (avail >= 3 || (long) avail == utflen) {
utflen -= readUTFSpan(sbuf, utflen);
} else {
if (blkmode) {
// near block boundary, read one byte at a time
utflen -= readUTFChar(sbuf, utflen);
} else {
// shift and refill buffer manually
if (avail > 0) {
System.arraycopy(buf, pos, buf, 0, avail);
}
pos = 0;
end = (int) Math.min(MAX_BLOCK_SIZE, utflen);
in.readFully(buf, avail, end - avail);
}
}
}
return sbuf.toString();
}
/** {@collect.stats}
* {@description.open}
* Reads span of UTF-encoded characters out of internal buffer
* (starting at offset pos and ending at or before offset end),
* consuming no more than utflen bytes. Appends read characters to
* sbuf. Returns the number of bytes consumed.
* {@description.close}
*/
private long readUTFSpan(StringBuilder sbuf, long utflen)
throws IOException
{
int cpos = 0;
int start = pos;
int avail = Math.min(end - pos, CHAR_BUF_SIZE);
// stop short of last char unless all of utf bytes in buffer
int stop = pos + ((utflen > avail) ? avail - 2 : (int) utflen);
boolean outOfBounds = false;
try {
while (pos < stop) {
int b1, b2, b3;
b1 = buf[pos++] & 0xFF;
switch (b1 >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7: // 1 byte format: 0xxxxxxx
cbuf[cpos++] = (char) b1;
break;
case 12:
case 13: // 2 byte format: 110xxxxx 10xxxxxx
b2 = buf[pos++];
if ((b2 & 0xC0) != 0x80) {
throw new UTFDataFormatException();
}
cbuf[cpos++] = (char) (((b1 & 0x1F) << 6) |
((b2 & 0x3F) << 0));
break;
case 14: // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
b3 = buf[pos + 1];
b2 = buf[pos + 0];
pos += 2;
if ((b2 & 0xC0) != 0x80 || (b3 & 0xC0) != 0x80) {
throw new UTFDataFormatException();
}
cbuf[cpos++] = (char) (((b1 & 0x0F) << 12) |
((b2 & 0x3F) << 6) |
((b3 & 0x3F) << 0));
break;
default: // 10xx xxxx, 1111 xxxx
throw new UTFDataFormatException();
}
}
} catch (ArrayIndexOutOfBoundsException ex) {
outOfBounds = true;
} finally {
if (outOfBounds || (pos - start) > utflen) {
/*
* Fix for 4450867: if a malformed utf char causes the
* conversion loop to scan past the expected end of the utf
* string, only consume the expected number of utf bytes.
*/
pos = start + (int) utflen;
throw new UTFDataFormatException();
}
}
sbuf.append(cbuf, 0, cpos);
return pos - start;
}
/** {@collect.stats}
* {@description.open}
* Reads in single UTF-encoded character one byte at a time, appends
* the character to sbuf, and returns the number of bytes consumed.
* This method is used when reading in UTF strings written in block
* data mode to handle UTF-encoded characters which (potentially)
* straddle block-data boundaries.
* {@description.close}
*/
private int readUTFChar(StringBuilder sbuf, long utflen)
throws IOException
{
int b1, b2, b3;
b1 = readByte() & 0xFF;
switch (b1 >> 4) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7: // 1 byte format: 0xxxxxxx
sbuf.append((char) b1);
return 1;
case 12:
case 13: // 2 byte format: 110xxxxx 10xxxxxx
if (utflen < 2) {
throw new UTFDataFormatException();
}
b2 = readByte();
if ((b2 & 0xC0) != 0x80) {
throw new UTFDataFormatException();
}
sbuf.append((char) (((b1 & 0x1F) << 6) |
((b2 & 0x3F) << 0)));
return 2;
case 14: // 3 byte format: 1110xxxx 10xxxxxx 10xxxxxx
if (utflen < 3) {
if (utflen == 2) {
readByte(); // consume remaining byte
}
throw new UTFDataFormatException();
}
b2 = readByte();
b3 = readByte();
if ((b2 & 0xC0) != 0x80 || (b3 & 0xC0) != 0x80) {
throw new UTFDataFormatException();
}
sbuf.append((char) (((b1 & 0x0F) << 12) |
((b2 & 0x3F) << 6) |
((b3 & 0x3F) << 0)));
return 3;
default: // 10xx xxxx, 1111 xxxx
throw new UTFDataFormatException();
}
}
}
/** {@collect.stats}
* {@description.open}
* Unsynchronized table which tracks wire handle to object mappings, as
* well as ClassNotFoundExceptions associated with deserialized objects.
* This class implements an exception-propagation algorithm for
* determining which objects should have ClassNotFoundExceptions associated
* with them, taking into account cycles and discontinuities (e.g., skipped
* fields) in the object graph.
*
* <p>General use of the table is as follows: during deserialization, a
* given object is first assigned a handle by calling the assign method.
* This method leaves the assigned handle in an "open" state, wherein
* dependencies on the exception status of other handles can be registered
* by calling the markDependency method, or an exception can be directly
* associated with the handle by calling markException. When a handle is
* tagged with an exception, the HandleTable assumes responsibility for
* propagating the exception to any other objects which depend
* (transitively) on the exception-tagged object.
*
* <p>Once all exception information/dependencies for the handle have been
* registered, the handle should be "closed" by calling the finish method
* on it. The act of finishing a handle allows the exception propagation
* algorithm to aggressively prune dependency links, lessening the
* performance/memory impact of exception tracking.
*
* <p>Note that the exception propagation algorithm used depends on handles
* being assigned/finished in LIFO order; however, for simplicity as well
* as memory conservation, it does not enforce this constraint.
* {@description.close}
*/
// REMIND: add full description of exception propagation algorithm?
private static class HandleTable {
/* status codes indicating whether object has associated exception */
private static final byte STATUS_OK = 1;
private static final byte STATUS_UNKNOWN = 2;
private static final byte STATUS_EXCEPTION = 3;
/** {@collect.stats}
* {@description.open}
* array mapping handle -> object status
* {@description.close}
*/
byte[] status;
/** {@collect.stats}
* {@description.open}
* array mapping handle -> object/exception (depending on status)
* {@description.close}
*/
Object[] entries;
/** {@collect.stats}
* {@description.open}
* array mapping handle -> list of dependent handles (if any)
* {@description.close}
*/
HandleList[] deps;
/** {@collect.stats}
* {@description.open}
* lowest unresolved dependency
* {@description.close}
*/
int lowDep = -1;
/** {@collect.stats}
* {@description.open}
* number of handles in table
* {@description.close}
*/
int size = 0;
/** {@collect.stats}
* {@description.open}
* Creates handle table with the given initial capacity.
* {@description.close}
*/
HandleTable(int initialCapacity) {
status = new byte[initialCapacity];
entries = new Object[initialCapacity];
deps = new HandleList[initialCapacity];
}
/** {@collect.stats}
* {@description.open}
* Assigns next available handle to given object, and returns assigned
* handle.
* {@description.close}
* {@property.open internal}
* Once object has been completely deserialized (and all
* dependencies on other objects identified), the handle should be
* "closed" by passing it to finish().
* {@property.close}
*/
int assign(Object obj) {
if (size >= entries.length) {
grow();
}
status[size] = STATUS_UNKNOWN;
entries[size] = obj;
return size++;
}
/** {@collect.stats}
* {@description.open}
* Registers a dependency (in exception status) of one handle on
* another.
* {@description.close}
* {@property.open}
* The dependent handle must be "open" (i.e., assigned, but
* not finished yet).
* {@property.close}
* {@description.open}
* No action is taken if either dependent or target
* handle is NULL_HANDLE.
* {@description.close}
*/
void markDependency(int dependent, int target) {
if (dependent == NULL_HANDLE || target == NULL_HANDLE) {
return;
}
switch (status[dependent]) {
case STATUS_UNKNOWN:
switch (status[target]) {
case STATUS_OK:
// ignore dependencies on objs with no exception
break;
case STATUS_EXCEPTION:
// eagerly propagate exception
markException(dependent,
(ClassNotFoundException) entries[target]);
break;
case STATUS_UNKNOWN:
// add to dependency list of target
if (deps[target] == null) {
deps[target] = new HandleList();
}
deps[target].add(dependent);
// remember lowest unresolved target seen
if (lowDep < 0 || lowDep > target) {
lowDep = target;
}
break;
default:
throw new InternalError();
}
break;
case STATUS_EXCEPTION:
break;
default:
throw new InternalError();
}
}
/** {@collect.stats}
* {@description.open}
* Associates a ClassNotFoundException (if one not already associated)
* with the currently active handle and propagates it to other
* referencing objects as appropriate.
* {@description.close}
* {@property.open}
* The specified handle must be
* "open" (i.e., assigned, but not finished yet).
* {@property.close}
*/
void markException(int handle, ClassNotFoundException ex) {
switch (status[handle]) {
case STATUS_UNKNOWN:
status[handle] = STATUS_EXCEPTION;
entries[handle] = ex;
// propagate exception to dependents
HandleList dlist = deps[handle];
if (dlist != null) {
int ndeps = dlist.size();
for (int i = 0; i < ndeps; i++) {
markException(dlist.get(i), ex);
}
deps[handle] = null;
}
break;
case STATUS_EXCEPTION:
break;
default:
throw new InternalError();
}
}
/** {@collect.stats}
* {@description.open}
* Marks given handle as finished, meaning that no new dependencies
* will be marked for handle.
* {@description.close}
* {@property.open}
* Calls to the assign and finish methods
* must occur in LIFO order.
* {@property.close}
*/
void finish(int handle) {
int end;
if (lowDep < 0) {
// no pending unknowns, only resolve current handle
end = handle + 1;
} else if (lowDep >= handle) {
// pending unknowns now clearable, resolve all upward handles
end = size;
lowDep = -1;
} else {
// unresolved backrefs present, can't resolve anything yet
return;
}
// change STATUS_UNKNOWN -> STATUS_OK in selected span of handles
for (int i = handle; i < end; i++) {
switch (status[i]) {
case STATUS_UNKNOWN:
status[i] = STATUS_OK;
deps[i] = null;
break;
case STATUS_OK:
case STATUS_EXCEPTION:
break;
default:
throw new InternalError();
}
}
}
/** {@collect.stats}
* {@description.open}
* Assigns a new object to the given handle. The object previously
* associated with the handle is forgotten.
* {@property.open}
* This method has no effect
* if the given handle already has an exception associated with it.
* {@property.close}
* {@description.open}
* This method may be called at any time after the handle is assigned.
* {@description.close}
*/
void setObject(int handle, Object obj) {
switch (status[handle]) {
case STATUS_UNKNOWN:
case STATUS_OK:
entries[handle] = obj;
break;
case STATUS_EXCEPTION:
break;
default:
throw new InternalError();
}
}
/** {@collect.stats}
* {@description.open}
* Looks up and returns object associated with the given handle.
* Returns null if the given handle is NULL_HANDLE, or if it has an
* associated ClassNotFoundException.
* {@description.close}
*/
Object lookupObject(int handle) {
return (handle != NULL_HANDLE &&
status[handle] != STATUS_EXCEPTION) ?
entries[handle] : null;
}
/** {@collect.stats}
* {@description.open}
* Looks up and returns ClassNotFoundException associated with the
* given handle. Returns null if the given handle is NULL_HANDLE, or
* if there is no ClassNotFoundException associated with the handle.
* {@description.close}
*/
ClassNotFoundException lookupException(int handle) {
return (handle != NULL_HANDLE &&
status[handle] == STATUS_EXCEPTION) ?
(ClassNotFoundException) entries[handle] : null;
}
/** {@collect.stats}
* {@description.open}
* Resets table to its initial state.
* {@description.close}
*/
void clear() {
Arrays.fill(status, 0, size, (byte) 0);
Arrays.fill(entries, 0, size, null);
Arrays.fill(deps, 0, size, null);
lowDep = -1;
size = 0;
}
/** {@collect.stats}
* {@description.open}
* Returns number of handles registered in table.
* {@description.close}
*/
int size() {
return size;
}
/** {@collect.stats}
* {@description.open}
* Expands capacity of internal arrays.
* {@description.close}
*/
private void grow() {
int newCapacity = (entries.length << 1) + 1;
byte[] newStatus = new byte[newCapacity];
Object[] newEntries = new Object[newCapacity];
HandleList[] newDeps = new HandleList[newCapacity];
System.arraycopy(status, 0, newStatus, 0, size);
System.arraycopy(entries, 0, newEntries, 0, size);
System.arraycopy(deps, 0, newDeps, 0, size);
status = newStatus;
entries = newEntries;
deps = newDeps;
}
/** {@collect.stats}
* {@description.open}
* Simple growable list of (integer) handles.
* {@description.close}
*/
private static class HandleList {
private int[] list = new int[4];
private int size = 0;
public HandleList() {
}
public void add(int handle) {
if (size >= list.length) {
int[] newList = new int[list.length << 1];
System.arraycopy(list, 0, newList, 0, list.length);
list = newList;
}
list[size++] = handle;
}
public int get(int index) {
if (index >= size) {
throw new ArrayIndexOutOfBoundsException();
}
return list[index];
}
public int size() {
return size;
}
}
}
/** {@collect.stats}
* {@description.open}
* Method for cloning arrays in case of using unsharing reading
* {@description.close}
*/
private static Object cloneArray(Object array) {
if (array instanceof Object[]) {
return ((Object[]) array).clone();
} else if (array instanceof boolean[]) {
return ((boolean[]) array).clone();
} else if (array instanceof byte[]) {
return ((byte[]) array).clone();
} else if (array instanceof char[]) {
return ((char[]) array).clone();
} else if (array instanceof double[]) {
return ((double[]) array).clone();
} else if (array instanceof float[]) {
return ((float[]) array).clone();
} else if (array instanceof int[]) {
return ((int[]) array).clone();
} else if (array instanceof long[]) {
return ((long[]) array).clone();
} else if (array instanceof double[]) {
return ((double[]) array).clone();
} else {
throw new AssertionError();
}
}
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Piped character-input streams.
* {@description.close}
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class PipedReader extends Reader {
boolean closedByWriter = false;
boolean closedByReader = false;
boolean connected = false;
/* REMIND: identification of the read and write sides needs to be
more sophisticated. Either using thread groups (but what about
pipes within a thread?) or using finalization (but it may be a
long time until the next GC). */
Thread readSide;
Thread writeSide;
/** {@collect.stats}
* {@description.open}
* The size of the pipe's circular input buffer.
* {@description.close}
*/
private static final int DEFAULT_PIPE_SIZE = 1024;
/** {@collect.stats}
* {@description.open}
* The circular buffer into which incoming data is placed.
* {@description.close}
*/
char buffer[];
/** {@collect.stats}
* {@description.open}
* The index of the position in the circular buffer at which the
* next character of data will be stored when received from the connected
* piped writer. <code>in<0</code> implies the buffer is empty,
* <code>in==out</code> implies the buffer is full
* {@description.close}
*/
int in = -1;
/** {@collect.stats}
* {@description.open}
* The index of the position in the circular buffer at which the next
* character of data will be read by this piped reader.
* {@description.close}
*/
int out = 0;
/** {@collect.stats}
* {@description.open}
* Creates a <code>PipedReader</code> so
* that it is connected to the piped writer
* <code>src</code>. Data written to <code>src</code>
* will then be available as input from this stream.
* {@description.close}
*
* @param src the stream to connect to.
* @exception IOException if an I/O error occurs.
*/
public PipedReader(PipedWriter src) throws IOException {
this(src, DEFAULT_PIPE_SIZE);
}
/** {@collect.stats}
* {@description.open}
* Creates a <code>PipedReader</code> so that it is connected
* to the piped writer <code>src</code> and uses the specified
* pipe size for the pipe's buffer. Data written to <code>src</code>
* will then be available as input from this stream.
* {@description.close}
* @param src the stream to connect to.
* @param pipeSize the size of the pipe's buffer.
* @exception IOException if an I/O error occurs.
* @exception IllegalArgumentException if <code>pipeSize <= 0</code>.
* @since 1.6
*/
public PipedReader(PipedWriter src, int pipeSize) throws IOException {
initPipe(pipeSize);
connect(src);
}
/** {@collect.stats}
* {@description.open}
* Creates a <code>PipedReader</code> so
* that it is not yet {@linkplain #connect(java.io.PipedWriter)
* connected}. It must be {@linkplain java.io.PipedWriter#connect(
* java.io.PipedReader) connected} to a <code>PipedWriter</code>
* before being used.
* {@description.close}
*/
public PipedReader() {
initPipe(DEFAULT_PIPE_SIZE);
}
/** {@collect.stats}
* {@description.open}
* Creates a <code>PipedReader</code> so that it is not yet
* {@link #connect(java.io.PipedWriter) connected} and uses
* the specified pipe size for the pipe's buffer.
* It must be {@linkplain java.io.PipedWriter#connect(
* java.io.PipedReader) connected} to a <code>PipedWriter</code>
* before being used.
* {@description.close}
*
* @param pipeSize the size of the pipe's buffer.
* @exception IllegalArgumentException if <code>pipeSize <= 0</code>.
* @since 1.6
*/
public PipedReader(int pipeSize) {
initPipe(pipeSize);
}
private void initPipe(int pipeSize) {
if (pipeSize <= 0) {
throw new IllegalArgumentException("Pipe size <= 0");
}
buffer = new char[pipeSize];
}
/** {@collect.stats}
* {@description.open}
* Causes this piped reader to be connected
* to the piped writer <code>src</code>.
* If this object is already connected to some
* other piped writer, an <code>IOException</code>
* is thrown.
* <p>
* If <code>src</code> is an
* unconnected piped writer and <code>snk</code>
* is an unconnected piped reader, they
* may be connected by either the call:
* <p>
* <pre><code>snk.connect(src)</code> </pre>
* <p>
* or the call:
* <p>
* <pre><code>src.connect(snk)</code> </pre>
* <p>
* The two
* calls have the same effect.
* {@description.close}
*
* @param src The piped writer to connect to.
* @exception IOException if an I/O error occurs.
*/
public void connect(PipedWriter src) throws IOException {
src.connect(this);
}
/** {@collect.stats}
* {@description.open}
* Receives a char of data.
* {@description.close}
* {@description.open blocking}
* This method will block if no input is
* available.
* {@description.close}
*/
synchronized void receive(int c) throws IOException {
if (!connected) {
throw new IOException("Pipe not connected");
} else if (closedByWriter || closedByReader) {
throw new IOException("Pipe closed");
} else if (readSide != null && !readSide.isAlive()) {
throw new IOException("Read end dead");
}
writeSide = Thread.currentThread();
while (in == out) {
if ((readSide != null) && !readSide.isAlive()) {
throw new IOException("Pipe broken");
}
/* full: kick any waiting readers */
notifyAll();
try {
wait(1000);
} catch (InterruptedException ex) {
throw new java.io.InterruptedIOException();
}
}
if (in < 0) {
in = 0;
out = 0;
}
buffer[in++] = (char) c;
if (in >= buffer.length) {
in = 0;
}
}
/** {@collect.stats}
* {@description.open}
* Receives data into an array of characters.
* {@description.close}
* {@description.open blocking}
* This method will
* block until some input is available.
* {@description.close}
*/
synchronized void receive(char c[], int off, int len) throws IOException {
while (--len >= 0) {
receive(c[off++]);
}
}
/** {@collect.stats}
* {@description.open}
* Notifies all waiting threads that the last character of data has been
* received.
* {@description.close}
*/
synchronized void receivedLast() {
closedByWriter = true;
notifyAll();
}
/** {@collect.stats}
* {@description.open}
* Reads the next character of data from this piped stream.
* If no character is available because the end of the stream
* has been reached, the value <code>-1</code> is returned.
* {@description.close}
* {@description.open blocking}
* This method blocks until input data is available, the end of
* the stream is detected, or an exception is thrown.
* {@description.close}
*
* @return the next character of data, or <code>-1</code> if the end of the
* stream is reached.
* @exception IOException if the pipe is
* <a href=PipedInputStream.html#BROKEN> <code>broken</code></a>,
* {@link #connect(java.io.PipedWriter) unconnected}, closed,
* or an I/O error occurs.
*/
public synchronized int read() throws IOException {
if (!connected) {
throw new IOException("Pipe not connected");
} else if (closedByReader) {
throw new IOException("Pipe closed");
} else if (writeSide != null && !writeSide.isAlive()
&& !closedByWriter && (in < 0)) {
throw new IOException("Write end dead");
}
readSide = Thread.currentThread();
int trials = 2;
while (in < 0) {
if (closedByWriter) {
/* closed by writer, return EOF */
return -1;
}
if ((writeSide != null) && (!writeSide.isAlive()) && (--trials < 0)) {
throw new IOException("Pipe broken");
}
/* might be a writer waiting */
notifyAll();
try {
wait(1000);
} catch (InterruptedException ex) {
throw new java.io.InterruptedIOException();
}
}
int ret = buffer[out++];
if (out >= buffer.length) {
out = 0;
}
if (in == out) {
/* now empty */
in = -1;
}
return ret;
}
/** {@collect.stats}
* {@description.open}
* Reads up to <code>len</code> characters of data from this piped
* stream into an array of characters. Less than <code>len</code> characters
* will be read if the end of the data stream is reached or if
* <code>len</code> exceeds the pipe's buffer size.
* {@description.close}
* {@description.open blocking}
* This method
* blocks until at least one character of input is available.
* {@description.close}
*
* @param cbuf the buffer into which the data is read.
* @param off the start offset of the data.
* @param len the maximum number of characters read.
* @return the total number of characters read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the stream has been reached.
* @exception IOException if the pipe is
* <a href=PipedInputStream.html#BROKEN> <code>broken</code></a>,
* {@link #connect(java.io.PipedWriter) unconnected}, closed,
* or an I/O error occurs.
*/
public synchronized int read(char cbuf[], int off, int len) throws IOException {
if (!connected) {
throw new IOException("Pipe not connected");
} else if (closedByReader) {
throw new IOException("Pipe closed");
} else if (writeSide != null && !writeSide.isAlive()
&& !closedByWriter && (in < 0)) {
throw new IOException("Write end dead");
}
if ((off < 0) || (off > cbuf.length) || (len < 0) ||
((off + len) > cbuf.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
/* possibly wait on the first character */
int c = read();
if (c < 0) {
return -1;
}
cbuf[off] = (char)c;
int rlen = 1;
while ((in >= 0) && (--len > 0)) {
cbuf[off + rlen] = buffer[out++];
rlen++;
if (out >= buffer.length) {
out = 0;
}
if (in == out) {
/* now empty */
in = -1;
}
}
return rlen;
}
/** {@collect.stats}
* {@description.open}
* Tell whether this stream is ready to be read. A piped character
* stream is ready if the circular buffer is not empty.
* {@description.close}
*
* @exception IOException if the pipe is
* <a href=PipedInputStream.html#BROKEN> <code>broken</code></a>,
* {@link #connect(java.io.PipedWriter) unconnected}, or closed.
*/
public synchronized boolean ready() throws IOException {
if (!connected) {
throw new IOException("Pipe not connected");
} else if (closedByReader) {
throw new IOException("Pipe closed");
} else if (writeSide != null && !writeSide.isAlive()
&& !closedByWriter && (in < 0)) {
throw new IOException("Write end dead");
}
if (in < 0) {
return false;
} else {
return true;
}
}
/** {@collect.stats}
* {@description.open}
* Closes this piped stream and releases any system resources
* associated with the stream.
* {@description.close}
*
* @exception IOException if an I/O error occurs.
*/
public void close() throws IOException {
in = -1;
closedByReader = true;
}
}
|
Java
|
/*
* Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* ObjectOutput extends the DataOutput interface to include writing of objects.
* DataOutput includes methods for output of primitive types, ObjectOutput
* extends that interface to include objects, arrays, and Strings.
* {@description.close}
*
* @author unascribed
* @see java.io.InputStream
* @see java.io.ObjectOutputStream
* @see java.io.ObjectInputStream
* @since JDK1.1
*/
public interface ObjectOutput extends DataOutput {
/** {@collect.stats}
* {@description.open}
* Write an object to the underlying storage or stream. The
* class that implements this interface defines how the object is
* written.
* {@description.close}
*
* @param obj the object to be written
* @exception IOException Any of the usual Input/Output related exceptions.
*/
public void writeObject(Object obj)
throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes a byte.
* {@description.close}
* {@description.open blocking}
* This method will block until the byte is actually
* written.
* {@description.close}
* @param b the byte
* @exception IOException If an I/O error has occurred.
*/
public void write(int b) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes an array of bytes.
* {@description.close}
* {@description.open blocking}
* This method will block until the bytes
* are actually written.
* {@description.close}
* @param b the data to be written
* @exception IOException If an I/O error has occurred.
*/
public void write(byte b[]) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes a sub array of bytes.
* {@description.close}
* @param b the data to be written
* @param off the start offset in the data
* @param len the number of bytes that are written
* @exception IOException If an I/O error has occurred.
*/
public void write(byte b[], int off, int len) throws IOException;
/** {@collect.stats}
* {@description.open}
* Flushes the stream. This will write any buffered
* output bytes.
* {@description.close}
* @exception IOException If an I/O error has occurred.
*/
public void flush() throws IOException;
/** {@collect.stats}
* {@description.open}
* Closes the stream.
* {@description.close}
* {@property.open runtime formal:java.io.ObjectOutput_Close}
* This method must be called
* to release any resources associated with the
* stream.
* {@property.close}
* @exception IOException If an I/O error has occurred.
*/
public void close() throws IOException;
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import sun.nio.cs.StreamDecoder;
/** {@collect.stats}
* {@description.open}
* An InputStreamReader is a bridge from byte streams to character streams: It
* reads bytes and decodes them into characters using a specified {@link
* java.nio.charset.Charset <code>charset</code>}. The charset that it uses
* may be specified by name or may be given explicitly, or the platform's
* default charset may be accepted.
*
* <p> Each invocation of one of an InputStreamReader's read() methods may
* cause one or more bytes to be read from the underlying byte-input stream.
* To enable the efficient conversion of bytes to characters, more bytes may
* be read ahead from the underlying stream than are necessary to satisfy the
* current read operation.
*
* <p> For top efficiency, consider wrapping an InputStreamReader within a
* BufferedReader. For example:
*
* <pre>
* BufferedReader in
* = new BufferedReader(new InputStreamReader(System.in));
* </pre>
* {@description.close}
*
* @see BufferedReader
* @see InputStream
* @see java.nio.charset.Charset
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class InputStreamReader extends Reader {
private final StreamDecoder sd;
/** {@collect.stats}
* {@description.open}
* Creates an InputStreamReader that uses the default charset.
* {@description.close}
*
* @param in An InputStream
*/
public InputStreamReader(InputStream in) {
super(in);
try {
sd = StreamDecoder.forInputStreamReader(in, this, (String)null); // ## check lock object
} catch (UnsupportedEncodingException e) {
// The default encoding should always be available
throw new Error(e);
}
}
/** {@collect.stats}
* {@description.open}
* Creates an InputStreamReader that uses the named charset.
* {@description.close}
*
* @param in
* An InputStream
*
* @param charsetName
* The name of a supported
* {@link java.nio.charset.Charset </code>charset<code>}
*
* @exception UnsupportedEncodingException
* If the named charset is not supported
*/
public InputStreamReader(InputStream in, String charsetName)
throws UnsupportedEncodingException
{
super(in);
if (charsetName == null)
throw new NullPointerException("charsetName");
sd = StreamDecoder.forInputStreamReader(in, this, charsetName);
}
/** {@collect.stats}
* {@description.open}
* Creates an InputStreamReader that uses the given charset. </p>
* {@description.close}
*
* @param in An InputStream
* @param cs A charset
*
* @since 1.4
* @spec JSR-51
*/
public InputStreamReader(InputStream in, Charset cs) {
super(in);
if (cs == null)
throw new NullPointerException("charset");
sd = StreamDecoder.forInputStreamReader(in, this, cs);
}
/** {@collect.stats}
* {@description.open}
* Creates an InputStreamReader that uses the given charset decoder. </p>
* {@description.close}
*
* @param in An InputStream
* @param dec A charset decoder
*
* @since 1.4
* @spec JSR-51
*/
public InputStreamReader(InputStream in, CharsetDecoder dec) {
super(in);
if (dec == null)
throw new NullPointerException("charset decoder");
sd = StreamDecoder.forInputStreamReader(in, this, dec);
}
/** {@collect.stats}
* {@description.open}
* Returns the name of the character encoding being used by this stream.
* {@description.close}
*
* {@property.open}
* <p> If the encoding has an historical name then that name is returned;
* otherwise the encoding's canonical name is returned.
* {@property.close}
*
* {@description.open}
* <p> If this instance was created with the {@link
* #InputStreamReader(InputStream, String)} constructor then the returned
* name, being unique for the encoding, may differ from the name passed to
* the constructor. This method will return <code>null</code> if the
* stream has been closed.
* </p>
* {@description.close}
* @return The historical name of this encoding, or
* <code>null</code> if the stream has been closed
*
* @see java.nio.charset.Charset
*
* @revised 1.4
* @spec JSR-51
*/
public String getEncoding() {
return sd.getEncoding();
}
/** {@collect.stats}
* {@description.open}
* Reads a single character.
* {@description.close}
*
* @return The character read, or -1 if the end of the stream has been
* reached
*
* @exception IOException If an I/O error occurs
*/
public int read() throws IOException {
return sd.read();
}
/** {@collect.stats}
* {@description.open}
* Reads characters into a portion of an array.
* {@description.close}
*
* @param cbuf Destination buffer
* @param offset Offset at which to start storing characters
* @param length Maximum number of characters to read
*
* @return The number of characters read, or -1 if the end of the
* stream has been reached
*
* @exception IOException If an I/O error occurs
*/
public int read(char cbuf[], int offset, int length) throws IOException {
return sd.read(cbuf, offset, length);
}
/** {@collect.stats}
* {@description.open}
* Tells whether this stream is ready to be read. An InputStreamReader is
* ready if its input buffer is not empty, or if bytes are available to be
* read from the underlying byte stream.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public boolean ready() throws IOException {
return sd.ready();
}
public void close() throws IOException {
sd.close();
}
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Thrown when serialization or deserialization is not active.
* {@description.close}
*
* @author unascribed
* @since JDK1.1
*/
public class NotActiveException extends ObjectStreamException {
private static final long serialVersionUID = -3893467273049808895L;
/** {@collect.stats}
* {@description.open}
* Constructor to create a new NotActiveException with the reason given.
* {@description.close}
*
* @param reason a String describing the reason for the exception.
*/
public NotActiveException(String reason) {
super(reason);
}
/** {@collect.stats}
* {@description.open}
* Constructor to create a new NotActiveException without a reason.
* {@description.close}
*/
public NotActiveException() {
super();
}
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Abstract class for reading filtered character streams.
* The abstract class <code>FilterReader</code> itself
* provides default methods that pass all requests to
* the contained stream. Subclasses of <code>FilterReader</code>
* should override some of these methods and may also provide
* additional methods and fields.
* {@description.close}
*
* @author Mark Reinhold
* @since JDK1.1
*/
public abstract class FilterReader extends Reader {
/** {@collect.stats}
* {@description.open}
* The underlying character-input stream.
* {@description.close}
*/
protected Reader in;
/** {@collect.stats}
* {@description.open}
* Creates a new filtered reader.
* {@description.close}
*
* @param in a Reader object providing the underlying stream.
* @throws NullPointerException if <code>in</code> is <code>null</code>
*/
protected FilterReader(Reader in) {
super(in);
this.in = in;
}
/** {@collect.stats}
* {@description.open}
* Reads a single character.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public int read() throws IOException {
return in.read();
}
/** {@collect.stats}
* {@description.open}
* Reads characters into a portion of an array.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public int read(char cbuf[], int off, int len) throws IOException {
return in.read(cbuf, off, len);
}
/** {@collect.stats}
* {@description.open}
* Skips characters.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public long skip(long n) throws IOException {
return in.skip(n);
}
/** {@collect.stats}
* {@description.open}
* Tells whether this stream is ready to be read.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public boolean ready() throws IOException {
return in.ready();
}
/** {@collect.stats}
* {@description.open}
* Tells whether this stream supports the mark() operation.
* {@description.close}
*/
public boolean markSupported() {
return in.markSupported();
}
/** {@collect.stats}
* {@description.open}
* Marks the present position in the stream.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public void mark(int readAheadLimit) throws IOException {
in.mark(readAheadLimit);
}
/** {@collect.stats}
* {@description.open}
* Resets the stream.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public void reset() throws IOException {
in.reset();
}
public void close() throws IOException {
in.close();
}
}
|
Java
|
/*
* Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* ObjectInput extends the DataInput interface to include the reading of
* objects. DataInput includes methods for the input of primitive types,
* ObjectInput extends that interface to include objects, arrays, and Strings.
* {@description.close}
*
* @author unascribed
* @see java.io.InputStream
* @see java.io.ObjectOutputStream
* @see java.io.ObjectInputStream
* @since JDK1.1
*/
public interface ObjectInput extends DataInput {
/** {@collect.stats}
* {@description.open}
* Read and return an object. The class that implements this interface
* defines where the object is "read" from.
* {@description.close}
*
* @return the object read from the stream
* @exception java.lang.ClassNotFoundException If the class of a serialized
* object cannot be found.
* @exception IOException If any of the usual Input/Output
* related exceptions occur.
*/
public Object readObject()
throws ClassNotFoundException, IOException;
/** {@collect.stats}
* {@description.open}
* Reads a byte of data.
* {@description.close}
* {@description.open blocking}
* This method will block if no input is
* available.
* {@description.close}
* @return the byte read, or -1 if the end of the
* stream is reached.
* @exception IOException If an I/O error has occurred.
*/
public int read() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads into an array of bytes.
* {@description.close}
* {@description.open blocking}
* This method will
* block until some input is available.
* {@description.close}
* @param b the buffer into which the data is read
* @return the actual number of bytes read, -1 is
* returned when the end of the stream is reached.
* @exception IOException If an I/O error has occurred.
*/
public int read(byte b[]) throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads into an array of bytes.
* {@description.close}
* {@description.open blocking}
* This method will
* block until some input is available.
* {@description.close}
* @param b the buffer into which the data is read
* @param off the start offset of the data
* @param len the maximum number of bytes read
* @return the actual number of bytes read, -1 is
* returned when the end of the stream is reached.
* @exception IOException If an I/O error has occurred.
*/
public int read(byte b[], int off, int len) throws IOException;
/** {@collect.stats}
* {@description.open}
* Skips n bytes of input.
* {@description.close}
* @param n the number of bytes to be skipped
* @return the actual number of bytes skipped.
* @exception IOException If an I/O error has occurred.
*/
public long skip(long n) throws IOException;
/** {@collect.stats}
* {@description.open}
* Returns the number of bytes that can be read
* without blocking.
* {@description.close}
* @return the number of available bytes.
* @exception IOException If an I/O error has occurred.
*/
public int available() throws IOException;
/** {@collect.stats}
* {@description.open}
* Closes the input stream.
* {@description.close}
* {@property.open runtime formal:java.io.ObjectInput_Close}
* Must be called
* to release any resources associated with
* the stream.
* {@property.close}
* @exception IOException If an I/O error has occurred.
*/
public void close() throws IOException;
}
|
Java
|
/*
* Copyright (c) 1996, 2001, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Convenience class for reading character files. The constructors of this
* class assume that the default character encoding and the default byte-buffer
* size are appropriate. To specify these values yourself, construct an
* InputStreamReader on a FileInputStream.
*
* <p><code>FileReader</code> is meant for reading streams of characters.
* For reading streams of raw bytes, consider using a
* <code>FileInputStream</code>.
* {@description.close}
*
* @see InputStreamReader
* @see FileInputStream
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class FileReader extends InputStreamReader {
/** {@collect.stats}
* {@description.open}
* Creates a new <tt>FileReader</tt>, given the name of the
* file to read from.
* {@description.close}
*
* @param fileName the name of the file to read from
* @exception FileNotFoundException if the named file does not exist,
* is a directory rather than a regular file,
* or for some other reason cannot be opened for
* reading.
*/
public FileReader(String fileName) throws FileNotFoundException {
super(new FileInputStream(fileName));
}
/** {@collect.stats}
* {@description.open}
* Creates a new <tt>FileReader</tt>, given the <tt>File</tt>
* to read from.
* {@description.close}
*
* @param file the <tt>File</tt> to read from
* @exception FileNotFoundException if the file does not exist,
* is a directory rather than a regular file,
* or for some other reason cannot be opened for
* reading.
*/
public FileReader(File file) throws FileNotFoundException {
super(new FileInputStream(file));
}
/** {@collect.stats}
* {@description.open}
* Creates a new <tt>FileReader</tt>, given the
* <tt>FileDescriptor</tt> to read from.
* {@description.close}
*
* @param fd the FileDescriptor to read from
*/
public FileReader(FileDescriptor fd) {
super(new FileInputStream(fd));
}
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* A character stream whose source is a string.
* {@description.close}
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class StringReader extends Reader {
private String str;
private int length;
private int next = 0;
private int mark = 0;
/** {@collect.stats}
* {@description.open}
* Creates a new string reader.
* {@description.close}
*
* @param s String providing the character stream.
*/
public StringReader(String s) {
this.str = s;
this.length = s.length();
}
/** {@collect.stats}
* {@description.open}
* Check to make sure that the stream has not been closed
* {@description.close}
*/
private void ensureOpen() throws IOException {
if (str == null)
throw new IOException("Stream closed");
}
/** {@collect.stats}
* {@description.open}
* Reads a single character.
* {@description.close}
*
* @return The character read, or -1 if the end of the stream has been
* reached
*
* @exception IOException If an I/O error occurs
*/
public int read() throws IOException {
synchronized (lock) {
ensureOpen();
if (next >= length)
return -1;
return str.charAt(next++);
}
}
/** {@collect.stats}
* {@description.open}
* Reads characters into a portion of an array.
* {@description.close}
*
* @param cbuf Destination buffer
* @param off Offset at which to start writing characters
* @param len Maximum number of characters to read
*
* @return The number of characters read, or -1 if the end of the
* stream has been reached
*
* @exception IOException If an I/O error occurs
*/
public int read(char cbuf[], int off, int len) throws IOException {
synchronized (lock) {
ensureOpen();
if ((off < 0) || (off > cbuf.length) || (len < 0) ||
((off + len) > cbuf.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
if (next >= length)
return -1;
int n = Math.min(length - next, len);
str.getChars(next, next + n, cbuf, off);
next += n;
return n;
}
}
/** {@collect.stats}
* {@description.open}
* Skips the specified number of characters in the stream. Returns
* the number of characters that were skipped.
*
* <p>The <code>ns</code> parameter may be negative, even though the
* <code>skip</code> method of the {@link Reader} superclass throws
* an exception in this case. Negative values of <code>ns</code> cause the
* stream to skip backwards. Negative return values indicate a skip
* backwards. It is not possible to skip backwards past the beginning of
* the string.
*
* <p>If the entire string has been read or skipped, then this method has
* no effect and always returns 0.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public long skip(long ns) throws IOException {
synchronized (lock) {
ensureOpen();
if (next >= length)
return 0;
// Bound skip by beginning and end of the source
long n = Math.min(length - next, ns);
n = Math.max(-next, n);
next += n;
return n;
}
}
/** {@collect.stats}
* {@description.open}
* Tells whether this stream is ready to be read.
* {@description.close}
*
* @return True if the next read() is guaranteed not to block for input
*
* @exception IOException If the stream is closed
*/
public boolean ready() throws IOException {
synchronized (lock) {
ensureOpen();
return true;
}
}
/** {@collect.stats}
* {@description.open}
* Tells whether this stream supports the mark() operation, which it does.
* {@description.close}
*/
public boolean markSupported() {
return true;
}
/** {@collect.stats}
* {@description.open}
* Marks the present position in the stream.
* {@description.close}
* {@property.open runtime formal:java.io.Reader_MarkReset}
* Subsequent calls to reset()
* will reposition the stream to this point.
* {@property.close}
*
* @param readAheadLimit Limit on the number of characters that may be
* read while still preserving the mark. Because
* the stream's input comes from a string, there
* is no actual limit, so this argument must not
* be negative, but is otherwise ignored.
*
* @exception IllegalArgumentException If readAheadLimit is < 0
* @exception IOException If an I/O error occurs
*/
public void mark(int readAheadLimit) throws IOException {
if (readAheadLimit < 0){
throw new IllegalArgumentException("Read-ahead limit < 0");
}
synchronized (lock) {
ensureOpen();
mark = next;
}
}
/** {@collect.stats}
* {@property.open runtime formal:java.io.Reader_MarkReset formal:java.io.Reader_UnmarkedReset}
* Resets the stream to the most recent mark, or to the beginning of the
* string if it has never been marked.
* {@property.close}
*
* @exception IOException If an I/O error occurs
*/
public void reset() throws IOException {
synchronized (lock) {
ensureOpen();
next = mark;
}
}
/** {@collect.stats}
* {@description.open}
* Closes the stream and releases any system resources associated with
* it.
* {@description.close}
* {@property.open runtime formal:java.io.Reader_ManipulateAfterClose}
* Once the stream has been closed, further read(),
* ready(), mark(), or reset() invocations will throw an IOException.
* {@property.close}
* {@property.open runtime formal:java.io.Closeable_MultipleClose}
* Closing a previously closed stream has no effect.
* {@property.close}
*/
public void close() {
str = null;
}
}
|
Java
|
/*
* Copyright (c) 1997, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.security.*;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.StringTokenizer;
/** {@collect.stats}
* {@description.open}
* This class is for Serializable permissions. A SerializablePermission
* contains a name (also referred to as a "target name") but
* no actions list; you either have the named permission
* or you don't.
*
* <P>
* The target name is the name of the Serializable permission (see below).
*
* <P>
* The following table lists all the possible SerializablePermission target names,
* and for each provides a description of what the permission allows
* and a discussion of the risks of granting code the permission.
* <P>
*
* <table border=1 cellpadding=5 summary="Permission target name, what the permission allows, and associated risks">
* <tr>
* <th>Permission Target Name</th>
* <th>What the Permission Allows</th>
* <th>Risks of Allowing this Permission</th>
* </tr>
*
* <tr>
* <td>enableSubclassImplementation</td>
* <td>Subclass implementation of ObjectOutputStream or ObjectInputStream
* to override the default serialization or deserialization, respectively,
* of objects</td>
* <td>Code can use this to serialize or
* deserialize classes in a purposefully malfeasant manner. For example,
* during serialization, malicious code can use this to
* purposefully store confidential private field data in a way easily accessible
* to attackers. Or, during deserialization it could, for example, deserialize
* a class with all its private fields zeroed out.</td>
* </tr>
*
* <tr>
* <td>enableSubstitution</td>
* <td>Substitution of one object for another during
* serialization or deserialization</td>
* <td>This is dangerous because malicious code
* can replace the actual object with one which has incorrect or
* malignant data.</td>
* </tr>
*
* </table>
* {@description.close}
*
* @see java.security.BasicPermission
* @see java.security.Permission
* @see java.security.Permissions
* @see java.security.PermissionCollection
* @see java.lang.SecurityManager
*
*
* @author Joe Fialli
* @since 1.2
*/
/* code was borrowed originally from java.lang.RuntimePermission. */
public final class SerializablePermission extends BasicPermission {
private static final long serialVersionUID = 8537212141160296410L;
/** {@collect.stats}
* @serial
*/
private String actions;
/** {@collect.stats}
* {@description.open}
* Creates a new SerializablePermission with the specified name.
* The name is the symbolic name of the SerializablePermission, such as
* "enableSubstitution", etc.
* {@description.close}
*
* @param name the name of the SerializablePermission.
*
* @throws NullPointerException if <code>name</code> is <code>null</code>.
* @throws IllegalArgumentException if <code>name</code> is empty.
*/
public SerializablePermission(String name)
{
super(name);
}
/** {@collect.stats}
* {@description.open}
* Creates a new SerializablePermission object with the specified name.
* The name is the symbolic name of the SerializablePermission, and the
* actions String is currently unused and should be null.
* {@description.close}
*
* @param name the name of the SerializablePermission.
* @param actions currently unused and must be set to null
*
* @throws NullPointerException if <code>name</code> is <code>null</code>.
* @throws IllegalArgumentException if <code>name</code> is empty.
*/
public SerializablePermission(String name, String actions)
{
super(name, actions);
}
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.lang.reflect.Field;
/** {@collect.stats}
* {@description.open}
* A description of a Serializable field from a Serializable class. An array
* of ObjectStreamFields is used to declare the Serializable fields of a class.
* {@description.close}
*
* @author Mike Warres
* @author Roger Riggs
* @see ObjectStreamClass
* @since 1.2
*/
public class ObjectStreamField
implements Comparable<Object>
{
/** {@collect.stats}
* {@description.open}
* field name
* {@description.close}
*/
private final String name;
/** {@collect.stats}
* {@description.open}
* canonical JVM signature of field type
* {@description.close}
*/
private final String signature;
/** {@collect.stats}
* {@description.open}
* field type (Object.class if unknown non-primitive type)
* {@description.close}
*/
private final Class type;
/** {@collect.stats}
* {@description.open}
* whether or not to (de)serialize field values as unshared
* {@description.close}
*/
private final boolean unshared;
/** {@collect.stats}
* {@description.open}
* corresponding reflective field object, if any
* {@description.close}
*/
private final Field field;
/** {@collect.stats}
* {@description.open}
* offset of field value in enclosing field group
* {@description.close}
*/
private int offset = 0;
/** {@collect.stats}
* {@description.open}
* Create a Serializable field with the specified type. This field should
* be documented with a <code>serialField</code> tag.
* {@description.close}
*
* @param name the name of the serializable field
* @param type the <code>Class</code> object of the serializable field
*/
public ObjectStreamField(String name, Class<?> type) {
this(name, type, false);
}
/** {@collect.stats}
* {@description.open}
* Creates an ObjectStreamField representing a serializable field with the
* given name and type. If unshared is false, values of the represented
* field are serialized and deserialized in the default manner--if the
* field is non-primitive, object values are serialized and deserialized as
* if they had been written and read by calls to writeObject and
* readObject. If unshared is true, values of the represented field are
* serialized and deserialized as if they had been written and read by
* calls to writeUnshared and readUnshared.
* {@description.close}
*
* @param name field name
* @param type field type
* @param unshared if false, write/read field values in the same manner
* as writeObject/readObject; if true, write/read in the same
* manner as writeUnshared/readUnshared
* @since 1.4
*/
public ObjectStreamField(String name, Class<?> type, boolean unshared) {
if (name == null) {
throw new NullPointerException();
}
this.name = name;
this.type = type;
this.unshared = unshared;
signature = ObjectStreamClass.getClassSignature(type).intern();
field = null;
}
/** {@collect.stats}
* {@description.open}
* Creates an ObjectStreamField representing a field with the given name,
* signature and unshared setting.
* {@description.close}
*/
ObjectStreamField(String name, String signature, boolean unshared) {
if (name == null) {
throw new NullPointerException();
}
this.name = name;
this.signature = signature.intern();
this.unshared = unshared;
field = null;
switch (signature.charAt(0)) {
case 'Z': type = Boolean.TYPE; break;
case 'B': type = Byte.TYPE; break;
case 'C': type = Character.TYPE; break;
case 'S': type = Short.TYPE; break;
case 'I': type = Integer.TYPE; break;
case 'J': type = Long.TYPE; break;
case 'F': type = Float.TYPE; break;
case 'D': type = Double.TYPE; break;
case 'L':
case '[': type = Object.class; break;
default: throw new IllegalArgumentException("illegal signature");
}
}
/** {@collect.stats}
* {@description.open}
* Creates an ObjectStreamField representing the given field with the
* specified unshared setting. For compatibility with the behavior of
* earlier serialization implementations, a "showType" parameter is
* necessary to govern whether or not a getType() call on this
* ObjectStreamField (if non-primitive) will return Object.class (as
* opposed to a more specific reference type).
* {@description.close}
*/
ObjectStreamField(Field field, boolean unshared, boolean showType) {
this.field = field;
this.unshared = unshared;
name = field.getName();
Class ftype = field.getType();
type = (showType || ftype.isPrimitive()) ? ftype : Object.class;
signature = ObjectStreamClass.getClassSignature(ftype).intern();
}
/** {@collect.stats}
* {@description.open}
* Get the name of this field.
* {@description.close}
*
* @return a <code>String</code> representing the name of the serializable
* field
*/
public String getName() {
return name;
}
/** {@collect.stats}
* {@description.open}
* Get the type of the field. If the type is non-primitive and this
* <code>ObjectStreamField</code> was obtained from a deserialized {@link
* ObjectStreamClass} instance, then <code>Object.class</code> is returned.
* Otherwise, the <code>Class</code> object for the type of the field is
* returned.
* {@description.close}
*
* @return a <code>Class</code> object representing the type of the
* serializable field
*/
public Class<?> getType() {
return type;
}
/** {@collect.stats}
* {@description.open}
* Returns character encoding of field type. The encoding is as follows:
* <blockquote><pre>
* B byte
* C char
* D double
* F float
* I int
* J long
* L class or interface
* S short
* Z boolean
* [ array
* </pre></blockquote>
* {@description.close}
*
* @return the typecode of the serializable field
*/
// REMIND: deprecate?
public char getTypeCode() {
return signature.charAt(0);
}
/** {@collect.stats}
* {@description.open}
* Return the JVM type signature.
* {@description.close}
*
* @return null if this field has a primitive type.
*/
// REMIND: deprecate?
public String getTypeString() {
return isPrimitive() ? null : signature;
}
/** {@collect.stats}
* {@description.open}
* Offset of field within instance data.
* {@description.close}
*
* @return the offset of this field
* @see #setOffset
*/
// REMIND: deprecate?
public int getOffset() {
return offset;
}
/** {@collect.stats}
* {@description.open}
* Offset within instance data.
* {@description.close}
*
* @param offset the offset of the field
* @see #getOffset
*/
// REMIND: deprecate?
protected void setOffset(int offset) {
this.offset = offset;
}
/** {@collect.stats}
* {@description.open}
* Return true if this field has a primitive type.
* {@description.close}
*
* @return true if and only if this field corresponds to a primitive type
*/
// REMIND: deprecate?
public boolean isPrimitive() {
char tcode = signature.charAt(0);
return ((tcode != 'L') && (tcode != '['));
}
/** {@collect.stats}
* {@description.open}
* Returns boolean value indicating whether or not the serializable field
* represented by this ObjectStreamField instance is unshared.
* {@description.close}
*
* @since 1.4
*/
public boolean isUnshared() {
return unshared;
}
/** {@collect.stats}
* {@description.open}
* Compare this field with another <code>ObjectStreamField</code>. Return
* -1 if this is smaller, 0 if equal, 1 if greater. Types that are
* primitives are "smaller" than object types. If equal, the field names
* are compared.
* {@description.close}
*/
// REMIND: deprecate?
public int compareTo(Object obj) {
ObjectStreamField other = (ObjectStreamField) obj;
boolean isPrim = isPrimitive();
if (isPrim != other.isPrimitive()) {
return isPrim ? -1 : 1;
}
return name.compareTo(other.name);
}
/** {@collect.stats}
* {@description.open}
* Return a string that describes this field.
* {@description.close}
*/
public String toString() {
return signature + ' ' + name;
}
/** {@collect.stats}
* {@description.open}
* Returns field represented by this ObjectStreamField, or null if
* ObjectStreamField is not associated with an actual field.
* {@description.close}
*/
Field getField() {
return field;
}
/** {@collect.stats}
* {@description.open}
* Returns JVM type signature of field (similar to getTypeString, except
* that signature strings are returned for primitive fields as well).
* {@description.close}
*/
String getSignature() {
return signature;
}
}
|
Java
|
/*
* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Context during upcalls from object stream to class-defined
* readObject/writeObject methods.
* Holds object currently being deserialized and descriptor for current class.
*
* This context keeps track of the thread it was constructed on, and allows
* only a single call of defaultReadObject, readFields, defaultWriteObject
* or writeFields which must be invoked on the same thread before the class's
* readObject/writeObject method has returned.
* If not set to the current thread, the getObj method throws NotActiveException.
* {@description.close}
*/
final class SerialCallbackContext {
private final Object obj;
private final ObjectStreamClass desc;
/** {@collect.stats}
* {@description.open}
* Thread this context is in use by.
* As this only works in one thread, we do not need to worry about thread-safety.
* {@description.close}
*/
private Thread thread;
public SerialCallbackContext(Object obj, ObjectStreamClass desc) {
this.obj = obj;
this.desc = desc;
this.thread = Thread.currentThread();
}
public Object getObj() throws NotActiveException {
checkAndSetUsed();
return obj;
}
public ObjectStreamClass getDesc() {
return desc;
}
private void checkAndSetUsed() throws NotActiveException {
if (thread != Thread.currentThread()) {
throw new NotActiveException(
"not in readObject invocation or fields already read");
}
thread = null;
}
public void setUsed() {
thread = null;
}
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* A character-stream reader that allows characters to be pushed back into the
* stream.
* {@description.close}
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class PushbackReader extends FilterReader {
/** {@collect.stats}
* {@description.open}
* Pushback buffer
* {@description.close}
*/
private char[] buf;
/** {@collect.stats}
* {@description.open}
* Current position in buffer
* {@description.close}
*/
private int pos;
/** {@collect.stats}
* {@description.open}
* Creates a new pushback reader with a pushback buffer of the given size.
* {@description.close}
*
* @param in The reader from which characters will be read
* @param size The size of the pushback buffer
* @exception IllegalArgumentException if size is <= 0
*/
public PushbackReader(Reader in, int size) {
super(in);
if (size <= 0) {
throw new IllegalArgumentException("size <= 0");
}
this.buf = new char[size];
this.pos = size;
}
/** {@collect.stats}
* {@description.open}
* Creates a new pushback reader with a one-character pushback buffer.
* {@description.close}
*
* @param in The reader from which characters will be read
*/
public PushbackReader(Reader in) {
this(in, 1);
}
/** {@collect.stats}
* {@description.open}
* Checks to make sure that the stream has not been closed.
* {@description.close}
*/
private void ensureOpen() throws IOException {
if (buf == null)
throw new IOException("Stream closed");
}
/** {@collect.stats}
* {@description.open}
* Reads a single character.
* {@description.close}
*
* @return The character read, or -1 if the end of the stream has been
* reached
*
* @exception IOException If an I/O error occurs
*/
public int read() throws IOException {
synchronized (lock) {
ensureOpen();
if (pos < buf.length)
return buf[pos++];
else
return super.read();
}
}
/** {@collect.stats}
* {@description.open}
* Reads characters into a portion of an array.
* {@description.close}
*
* @param cbuf Destination buffer
* @param off Offset at which to start writing characters
* @param len Maximum number of characters to read
*
* @return The number of characters read, or -1 if the end of the
* stream has been reached
*
* @exception IOException If an I/O error occurs
*/
public int read(char cbuf[], int off, int len) throws IOException {
synchronized (lock) {
ensureOpen();
try {
if (len <= 0) {
if (len < 0) {
throw new IndexOutOfBoundsException();
} else if ((off < 0) || (off > cbuf.length)) {
throw new IndexOutOfBoundsException();
}
return 0;
}
int avail = buf.length - pos;
if (avail > 0) {
if (len < avail)
avail = len;
System.arraycopy(buf, pos, cbuf, off, avail);
pos += avail;
off += avail;
len -= avail;
}
if (len > 0) {
len = super.read(cbuf, off, len);
if (len == -1) {
return (avail == 0) ? -1 : avail;
}
return avail + len;
}
return avail;
} catch (ArrayIndexOutOfBoundsException e) {
throw new IndexOutOfBoundsException();
}
}
}
/** {@collect.stats}
* {@description.open}
* Pushes back a single character by copying it to the front of the
* pushback buffer.
* After this method returns, the next character to be read
* will have the value <code>(char)c</code>.
* {@description.close}
*
* @param c The int value representing a character to be pushed back
*
* @exception IOException If the pushback buffer is full,
* or if some other I/O error occurs
*/
public void unread(int c) throws IOException {
synchronized (lock) {
ensureOpen();
if (pos == 0)
throw new IOException("Pushback buffer overflow");
buf[--pos] = (char) c;
}
}
/** {@collect.stats}
* {@description.open}
* Pushes back a portion of an array of characters by copying it to the
* front of the pushback buffer. After this method returns, the next
* character to be read will have the value <code>cbuf[off]</code>, the
* character after that will have the value <code>cbuf[off+1]</code>, and
* so forth.
* {@description.close}
*
* @param cbuf Character array
* @param off Offset of first character to push back
* @param len Number of characters to push back
*
* @exception IOException If there is insufficient room in the pushback
* buffer, or if some other I/O error occurs
*/
public void unread(char cbuf[], int off, int len) throws IOException {
synchronized (lock) {
ensureOpen();
if (len > pos)
throw new IOException("Pushback buffer overflow");
pos -= len;
System.arraycopy(cbuf, off, buf, pos, len);
}
}
/** {@collect.stats}
* {@description.open}
* Pushes back an array of characters by copying it to the front of the
* pushback buffer. After this method returns, the next character to be
* read will have the value <code>cbuf[0]</code>, the character after that
* will have the value <code>cbuf[1]</code>, and so forth.
* {@description.close}
*
* @param cbuf Character array to push back
*
* @exception IOException If there is insufficient room in the pushback
* buffer, or if some other I/O error occurs
*/
public void unread(char cbuf[]) throws IOException {
unread(cbuf, 0, cbuf.length);
}
/** {@collect.stats}
* {@description.open}
* Tells whether this stream is ready to be read.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public boolean ready() throws IOException {
synchronized (lock) {
ensureOpen();
return (pos < buf.length) || super.ready();
}
}
/** {@collect.stats}
* {@description.open}
* Marks the present position in the stream.
* {@description.close}
* {@property.open runtime formal:java.io.Reader_MarkReset}
* The <code>mark</code>
* for class <code>PushbackReader</code> always throws an exception.
* {@property.close}
*
* @exception IOException Always, since mark is not supported
*/
public void mark(int readAheadLimit) throws IOException {
throw new IOException("mark/reset not supported");
}
/** {@collect.stats}
* {@description.open}
* Resets the stream.
* {@description.close}
* {@property.open runtime formal:java.io.Reader_MarkReset}
* The <code>reset</code> method of
* <code>PushbackReader</code> always throws an exception.
* {@property.close}
*
* @exception IOException Always, since reset is not supported
*/
public void reset() throws IOException {
throw new IOException("mark/reset not supported");
}
/** {@collect.stats}
* {@description.open}
* Tells whether this stream supports the mark() operation, which it does
* not.
* {@description.close}
*/
public boolean markSupported() {
return false;
}
/** {@collect.stats}
* {@description.open}
* Closes the stream and releases any system resources associated with
* it.
* {@description.close}
* {@property.open runtime formal:java.io.Reader_ManipulateAfterClose}
* Once the stream has been closed, further read(),
* unread(), ready(), or skip() invocations will throw an IOException.
* {@property.close}
* {@property.open runtime formal:java.io.Closeable_MultipleClose}
* Closing a previously closed stream has no effect.
* {@property.close}
*
* @exception IOException If an I/O error occurs
*/
public void close() throws IOException {
super.close();
buf = null;
}
/** {@collect.stats}
* {@description.open}
* Skips characters.
* {@description.close}
* {@description.open blocking}
* This method will block until some characters are
* available, an I/O error occurs, or the end of the stream is reached.
* {@description.close}
*
* @param n The number of characters to skip
*
* @return The number of characters actually skipped
*
* @exception IllegalArgumentException If <code>n</code> is negative.
* @exception IOException If an I/O error occurs
*/
public long skip(long n) throws IOException {
if (n < 0L)
throw new IllegalArgumentException("skip value is negative");
synchronized (lock) {
ensureOpen();
int avail = buf.length - pos;
if (avail > 0) {
if (n <= avail) {
pos += n;
return n;
} else {
pos = buf.length;
n -= avail;
}
}
return avail + super.skip(n);
}
}
}
|
Java
|
/*
* Copyright (c) 1994, 1998, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Instances of classes that implement this interface are used to
* filter filenames. These instances are used to filter directory
* listings in the <code>list</code> method of class
* <code>File</code>, and by the Abstract Window Toolkit's file
* dialog component.
* {@description.close}
*
* @author Arthur van Hoff
* @author Jonathan Payne
* @see java.awt.FileDialog#setFilenameFilter(java.io.FilenameFilter)
* @see java.io.File
* @see java.io.File#list(java.io.FilenameFilter)
* @since JDK1.0
*/
public
interface FilenameFilter {
/** {@collect.stats}
* {@description.open}
* Tests if a specified file should be included in a file list.
* {@description.close}
*
* @param dir the directory in which the file was found.
* @param name the name of the file.
* @return <code>true</code> if and only if the name should be
* included in the file list; <code>false</code> otherwise.
*/
boolean accept(File dir, String name);
}
|
Java
|
/* Copyright (c) 2001, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Utility methods for packing/unpacking primitive values in/out of byte arrays
* using big-endian byte ordering.
* {@description.close}
*/
class Bits {
/*
* Methods for unpacking primitive values from byte arrays starting at
* given offsets.
*/
static boolean getBoolean(byte[] b, int off) {
return b[off] != 0;
}
static char getChar(byte[] b, int off) {
return (char) (((b[off + 1] & 0xFF) << 0) +
((b[off + 0]) << 8));
}
static short getShort(byte[] b, int off) {
return (short) (((b[off + 1] & 0xFF) << 0) +
((b[off + 0]) << 8));
}
static int getInt(byte[] b, int off) {
return ((b[off + 3] & 0xFF) << 0) +
((b[off + 2] & 0xFF) << 8) +
((b[off + 1] & 0xFF) << 16) +
((b[off + 0]) << 24);
}
static float getFloat(byte[] b, int off) {
int i = ((b[off + 3] & 0xFF) << 0) +
((b[off + 2] & 0xFF) << 8) +
((b[off + 1] & 0xFF) << 16) +
((b[off + 0]) << 24);
return Float.intBitsToFloat(i);
}
static long getLong(byte[] b, int off) {
return ((b[off + 7] & 0xFFL) << 0) +
((b[off + 6] & 0xFFL) << 8) +
((b[off + 5] & 0xFFL) << 16) +
((b[off + 4] & 0xFFL) << 24) +
((b[off + 3] & 0xFFL) << 32) +
((b[off + 2] & 0xFFL) << 40) +
((b[off + 1] & 0xFFL) << 48) +
(((long) b[off + 0]) << 56);
}
static double getDouble(byte[] b, int off) {
long j = ((b[off + 7] & 0xFFL) << 0) +
((b[off + 6] & 0xFFL) << 8) +
((b[off + 5] & 0xFFL) << 16) +
((b[off + 4] & 0xFFL) << 24) +
((b[off + 3] & 0xFFL) << 32) +
((b[off + 2] & 0xFFL) << 40) +
((b[off + 1] & 0xFFL) << 48) +
(((long) b[off + 0]) << 56);
return Double.longBitsToDouble(j);
}
/*
* Methods for packing primitive values into byte arrays starting at given
* offsets.
*/
static void putBoolean(byte[] b, int off, boolean val) {
b[off] = (byte) (val ? 1 : 0);
}
static void putChar(byte[] b, int off, char val) {
b[off + 1] = (byte) (val >>> 0);
b[off + 0] = (byte) (val >>> 8);
}
static void putShort(byte[] b, int off, short val) {
b[off + 1] = (byte) (val >>> 0);
b[off + 0] = (byte) (val >>> 8);
}
static void putInt(byte[] b, int off, int val) {
b[off + 3] = (byte) (val >>> 0);
b[off + 2] = (byte) (val >>> 8);
b[off + 1] = (byte) (val >>> 16);
b[off + 0] = (byte) (val >>> 24);
}
static void putFloat(byte[] b, int off, float val) {
int i = Float.floatToIntBits(val);
b[off + 3] = (byte) (i >>> 0);
b[off + 2] = (byte) (i >>> 8);
b[off + 1] = (byte) (i >>> 16);
b[off + 0] = (byte) (i >>> 24);
}
static void putLong(byte[] b, int off, long val) {
b[off + 7] = (byte) (val >>> 0);
b[off + 6] = (byte) (val >>> 8);
b[off + 5] = (byte) (val >>> 16);
b[off + 4] = (byte) (val >>> 24);
b[off + 3] = (byte) (val >>> 32);
b[off + 2] = (byte) (val >>> 40);
b[off + 1] = (byte) (val >>> 48);
b[off + 0] = (byte) (val >>> 56);
}
static void putDouble(byte[] b, int off, double val) {
long j = Double.doubleToLongBits(val);
b[off + 7] = (byte) (j >>> 0);
b[off + 6] = (byte) (j >>> 8);
b[off + 5] = (byte) (j >>> 16);
b[off + 4] = (byte) (j >>> 24);
b[off + 3] = (byte) (j >>> 32);
b[off + 2] = (byte) (j >>> 40);
b[off + 1] = (byte) (j >>> 48);
b[off + 0] = (byte) (j >>> 56);
}
}
|
Java
|
/*
* Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* This abstract class is the superclass of all classes representing
* an input stream of bytes.
* {@description.close}
*
* {@property.open enforced}
* <p> Applications that need to define a subclass of <code>InputStream</code>
* must always provide a method that returns the next byte of input.
* {@property.close}
*
* @author Arthur van Hoff
* @see java.io.BufferedInputStream
* @see java.io.ByteArrayInputStream
* @see java.io.DataInputStream
* @see java.io.FilterInputStream
* @see java.io.InputStream#read()
* @see java.io.OutputStream
* @see java.io.PushbackInputStream
* @since JDK1.0
*/
public abstract class InputStream implements Closeable {
// SKIP_BUFFER_SIZE is used to determine the size of skipBuffer
private static final int SKIP_BUFFER_SIZE = 2048;
// skipBuffer is initialized in skip(long), if needed.
private static byte[] skipBuffer;
/** {@collect.stats}
* {@description.open}
* Reads the next byte of data from the input stream. The value byte is
* returned as an <code>int</code> in the range <code>0</code> to
* <code>255</code>. If no byte is available because the end of the stream
* has been reached, the value <code>-1</code> is returned.
* {@description.close}
* {@description.open blocking}
* This method
* blocks until input data is available, the end of the stream is detected,
* or an exception is thrown.
* {@description.close}
*
* {@property.open enforced}
* <p> A subclass must provide an implementation of this method.
* {@property.close}
*
* @return the next byte of data, or <code>-1</code> if the end of the
* stream is reached.
* @exception IOException if an I/O error occurs.
*/
public abstract int read() throws IOException;
/** {@collect.stats}
* {@description.open}
* Reads some number of bytes from the input stream and stores them into
* the buffer array <code>b</code>. The number of bytes actually read is
* returned as an integer.
* {@description.close}
* {@description.open blocking}
* This method blocks until input data is
* available, end of file is detected, or an exception is thrown.
* {@description.close}
*
* {@description.open}
* <p> If the length of <code>b</code> is zero, then no bytes are read and
* <code>0</code> is returned; otherwise, there is an attempt to read at
* least one byte. If no byte is available because the stream is at the
* end of the file, the value <code>-1</code> is returned; otherwise, at
* least one byte is read and stored into <code>b</code>.
* {@description.close}
*
* {@property.open internal}
* <p> The first byte read is stored into element <code>b[0]</code>, the
* next one into <code>b[1]</code>, and so on. The number of bytes read is,
* at most, equal to the length of <code>b</code>. Let <i>k</i> be the
* number of bytes actually read; these bytes will be stored in elements
* <code>b[0]</code> through <code>b[</code><i>k</i><code>-1]</code>,
* leaving elements <code>b[</code><i>k</i><code>]</code> through
* <code>b[b.length-1]</code> unaffected.
* {@property.close}
*
* {@description.open}
* <p> The <code>read(b)</code> method for class <code>InputStream</code>
* has the same effect as: <pre><code> read(b, 0, b.length) </code></pre>
* {@description.close}
*
* @param b the buffer into which the data is read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> is there is no more data because the end of
* the stream has been reached.
* @exception IOException If the first byte cannot be read for any reason
* other than the end of the file, if the input stream has been closed, or
* if some other I/O error occurs.
* @exception NullPointerException if <code>b</code> is <code>null</code>.
* @see java.io.InputStream#read(byte[], int, int)
*/
public int read(byte b[]) throws IOException {
return read(b, 0, b.length);
}
/** {@collect.stats}
* {@description.open}
* Reads up to <code>len</code> bytes of data from the input stream into
* an array of bytes. An attempt is made to read as many as
* <code>len</code> bytes, but a smaller number may be read.
* The number of bytes actually read is returned as an integer.
* {@description.close}
*
* {@description.open blocking}
* <p> This method blocks until input data is available, end of file is
* detected, or an exception is thrown.
*
* <p> If <code>len</code> is zero, then no bytes are read and
* <code>0</code> is returned; otherwise, there is an attempt to read at
* least one byte. If no byte is available because the stream is at end of
* file, the value <code>-1</code> is returned; otherwise, at least one
* byte is read and stored into <code>b</code>.
* {@description.close}
*
* {@property.open internal}
* <p> The first byte read is stored into element <code>b[off]</code>, the
* next one into <code>b[off+1]</code>, and so on. The number of bytes read
* is, at most, equal to <code>len</code>. Let <i>k</i> be the number of
* bytes actually read; these bytes will be stored in elements
* <code>b[off]</code> through <code>b[off+</code><i>k</i><code>-1]</code>,
* leaving elements <code>b[off+</code><i>k</i><code>]</code> through
* <code>b[off+len-1]</code> unaffected.
*
* <p> In every case, elements <code>b[0]</code> through
* <code>b[off]</code> and elements <code>b[off+len]</code> through
* <code>b[b.length-1]</code> are unaffected.
*
* <p> The <code>read(b,</code> <code>off,</code> <code>len)</code> method
* for class <code>InputStream</code> simply calls the method
* <code>read()</code> repeatedly. If the first such call results in an
* <code>IOException</code>, that exception is returned from the call to
* the <code>read(b,</code> <code>off,</code> <code>len)</code> method. If
* any subsequent call to <code>read()</code> results in a
* <code>IOException</code>, the exception is caught and treated as if it
* were end of file; the bytes read up to that point are stored into
* <code>b</code> and the number of bytes read before the exception
* occurred is returned. The default implementation of this method blocks
* until the requested amount of input data <code>len</code> has been read,
* end of file is detected, or an exception is thrown. Subclasses are encouraged
* to provide a more efficient implementation of this method.
* {@property.close}
*
* @param b the buffer into which the data is read.
* @param off the start offset in array <code>b</code>
* at which the data is written.
* @param len the maximum number of bytes to read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the stream has been reached.
* @exception IOException If the first byte cannot be read for any reason
* other than end of file, or if the input stream has been closed, or if
* some other I/O error occurs.
* @exception NullPointerException If <code>b</code> is <code>null</code>.
* @exception IndexOutOfBoundsException If <code>off</code> is negative,
* <code>len</code> is negative, or <code>len</code> is greater than
* <code>b.length - off</code>
* @see java.io.InputStream#read()
*/
public int read(byte b[], int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
int c = read();
if (c == -1) {
return -1;
}
b[off] = (byte)c;
int i = 1;
try {
for (; i < len ; i++) {
c = read();
if (c == -1) {
break;
}
b[off + i] = (byte)c;
}
} catch (IOException ee) {
}
return i;
}
/** {@collect.stats}
* {@description.open}
* Skips over and discards <code>n</code> bytes of data from this input
* stream. The <code>skip</code> method may, for a variety of reasons, end
* up skipping over some smaller number of bytes, possibly <code>0</code>.
* This may result from any of a number of conditions; reaching end of file
* before <code>n</code> bytes have been skipped is only one possibility.
* The actual number of bytes skipped is returned. If <code>n</code> is
* negative, no bytes are skipped.
*
* <p> The <code>skip</code> method of this class creates a
* byte array and then repeatedly reads into it until <code>n</code> bytes
* have been read or the end of the stream has been reached. Subclasses are
* encouraged to provide a more efficient implementation of this method.
* For instance, the implementation may depend on the ability to seek.
* {@description.close}
*
* @param n the number of bytes to be skipped.
* @return the actual number of bytes skipped.
* @exception IOException if the stream does not support seek,
* or if some other I/O error occurs.
*/
public long skip(long n) throws IOException {
long remaining = n;
int nr;
if (skipBuffer == null)
skipBuffer = new byte[SKIP_BUFFER_SIZE];
byte[] localSkipBuffer = skipBuffer;
if (n <= 0) {
return 0;
}
while (remaining > 0) {
nr = read(localSkipBuffer, 0,
(int) Math.min(SKIP_BUFFER_SIZE, remaining));
if (nr < 0) {
break;
}
remaining -= nr;
}
return n - remaining;
}
/** {@collect.stats}
* {@description.open}
* Returns an estimate of the number of bytes that can be read (or
* skipped over) from this input stream without blocking by the next
* invocation of a method for this input stream. The next invocation
* might be the same thread or another thread.
* {@description.close}
* {@description.open blocking}
* A single read or skip of this
* many bytes will not block, but may read or skip fewer bytes.
* {@description.close}
*
* {@property.open uncheckable}
* <p> Note that while some implementations of {@code InputStream} will return
* the total number of bytes in the stream, many will not. It is
* never correct to use the return value of this method to allocate
* a buffer intended to hold all data in this stream.
* {@new.open}
* Since JavaMOP does not monitor local variable manipulation, this
* property is not checkable.
* {@new.close}
* {@property.close}
*
* {@description.open}
* <p> A subclass' implementation of this method may choose to throw an
* {@link IOException} if this input stream has been closed by
* invoking the {@link #close()} method.
*
* <p> The {@code available} method for class {@code InputStream} always
* returns {@code 0}.
* {@description.close}
*
* {@property.open static}
* <p> This method should be overridden by subclasses.
* {@property.close}
*
* @return an estimate of the number of bytes that can be read (or skipped
* over) from this input stream without blocking or {@code 0} when
* it reaches the end of the input stream.
* @exception IOException if an I/O error occurs.
*/
public int available() throws IOException {
return 0;
}
/** {@collect.stats}
* {@description.open}
* Closes this input stream and releases any system resources associated
* with the stream.
*
* <p> The <code>close</code> method of <code>InputStream</code> does
* nothing.
* {@description.close}
*
* @exception IOException if an I/O error occurs.
*/
public void close() throws IOException {}
/** {@collect.stats}
* {@description.open}
* Marks the current position in this input stream. A subsequent call to
* the <code>reset</code> method repositions this stream at the last marked
* position so that subsequent reads re-read the same bytes.
*
* <p> The <code>readlimit</code> arguments tells this input stream to
* allow that many bytes to be read before the mark position gets
* invalidated.
* {@description.close}
*
* {@property.open runtime formal:java.io.InputStream_MarkReset}
* <p> The general contract of <code>mark</code> is that, if the method
* <code>markSupported</code> returns <code>true</code>, the stream somehow
* remembers all the bytes read after the call to <code>mark</code> and
* stands ready to supply those same bytes again if and whenever the method
* <code>reset</code> is called.
* {@property.close}
* {@property.open runtime formal:java.io.InputStream_ReadAheadLimit}
* However, the stream is not required to
* remember any data at all if more than <code>readlimit</code> bytes are
* read from the stream before <code>reset</code> is called.
* {@property.close}
*
* {@property.open runtime formal:java.io.InputStream_MarkAfterClose}
* <p> Marking a closed stream should not have any effect on the stream.
* {@property.close}
*
* {@description.open}
* <p> The <code>mark</code> method of <code>InputStream</code> does
* nothing.
* {@description.close}
*
* @param readlimit the maximum limit of bytes that can be read before
* the mark position becomes invalid.
* @see java.io.InputStream#reset()
*/
public synchronized void mark(int readlimit) {}
/** {@collect.stats}
* {@description.open}
* Repositions this stream to the position at the time the
* <code>mark</code> method was last called on this input stream.
*
* <p> The general contract of <code>reset</code> is:
*
* <p><ul>
* {@description.close}
*
* {@property.open runtime formal:java.io.InputStream_MarkReset formal:java.io.InputStream_UnmarkedReset}
* <li> If the method <code>markSupported</code> returns
* <code>true</code>, then:
*
* <ul><li> If the method <code>mark</code> has not been called since
* the stream was created, or the number of bytes read from the stream
* since <code>mark</code> was last called is larger than the argument
* to <code>mark</code> at that last call, then an
* <code>IOException</code> might be thrown.
*
* <li> If such an <code>IOException</code> is not thrown, then the
* stream is reset to a state such that all the bytes read since the
* most recent call to <code>mark</code> (or since the start of the
* file, if <code>mark</code> has not been called) will be resupplied
* to subsequent callers of the <code>read</code> method, followed by
* any bytes that otherwise would have been the next input data as of
* the time of the call to <code>reset</code>. </ul>
*
* <li> If the method <code>markSupported</code> returns
* <code>false</code>, then:
*
* <ul><li> The call to <code>reset</code> may throw an
* <code>IOException</code>.
*
* <li> If an <code>IOException</code> is not thrown, then the stream
* is reset to a fixed state that depends on the particular type of the
* input stream and how it was created. The bytes that will be supplied
* to subsequent callers of the <code>read</code> method depend on the
* particular type of the input stream. </ul></ul>
*
* <p>The method <code>reset</code> for class <code>InputStream</code>
* does nothing except throw an <code>IOException</code>.
* {@property.close}
*
* @exception IOException if this stream has not been marked or if the
* mark has been invalidated.
* @see java.io.InputStream#mark(int)
* @see java.io.IOException
*/
public synchronized void reset() throws IOException {
throw new IOException("mark/reset not supported");
}
/** {@collect.stats}
* {@description.open}
* Tests if this input stream supports the <code>mark</code> and
* <code>reset</code> methods. Whether or not <code>mark</code> and
* <code>reset</code> are supported is an invariant property of a
* particular input stream instance. The <code>markSupported</code> method
* of <code>InputStream</code> returns <code>false</code>.
* {@description.close}
*
* @return <code>true</code> if this stream instance supports the mark
* and reset methods; <code>false</code> otherwise.
* @see java.io.InputStream#mark(int)
* @see java.io.InputStream#reset()
*/
public boolean markSupported() {
return false;
}
}
|
Java
|
/*
* Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
/** {@collect.stats}
* {@description.open}
* A <code>BufferedInputStream</code> adds
* functionality to another input stream-namely,
* the ability to buffer the input and to
* support the <code>mark</code> and <code>reset</code>
* methods. When the <code>BufferedInputStream</code>
* is created, an internal buffer array is
* created. As bytes from the stream are read
* or skipped, the internal buffer is refilled
* as necessary from the contained input stream,
* many bytes at a time.
* {@description.close}
*
* {@property.open runtime formal:java.io.Reader_MarkReset formal:java.io.Reader_ReadAheadLimit formal:java.io.Reader_UnmarkedReset}
* The <code>mark</code>
* operation remembers a point in the input
* stream and the <code>reset</code> operation
* causes all the bytes read since the most
* recent <code>mark</code> operation to be
* reread before new bytes are taken from
* the contained input stream.
* {@property.close}
*
* @author Arthur van Hoff
* @since JDK1.0
*/
public
class BufferedInputStream extends FilterInputStream {
private static int defaultBufferSize = 8192;
/** {@collect.stats}
* {@description.open}
* The internal buffer array where the data is stored. When necessary,
* it may be replaced by another array of
* a different size.
* {@description.close}
*/
protected volatile byte buf[];
/** {@collect.stats}
* {@description.open}
* Atomic updater to provide compareAndSet for buf. This is
* necessary because closes can be asynchronous. We use nullness
* of buf[] as primary indicator that this stream is closed. (The
* "in" field is also nulled out on close.)
* {@description.close}
*/
private static final
AtomicReferenceFieldUpdater<BufferedInputStream, byte[]> bufUpdater =
AtomicReferenceFieldUpdater.newUpdater
(BufferedInputStream.class, byte[].class, "buf");
/** {@collect.stats}
* {@description.open}
* The index one greater than the index of the last valid byte in
* the buffer.
* {@description.close}
* {@property.open internal}
* This value is always
* in the range <code>0</code> through <code>buf.length</code>;
* elements <code>buf[0]</code> through <code>buf[count-1]
* </code>contain buffered input data obtained
* from the underlying input stream.
* {@property.close}
*/
protected int count;
/** {@collect.stats}
* {@description.open}
* The current position in the buffer. This is the index of the next
* character to be read from the <code>buf</code> array.
* <p>
* {@description.close}
* {@property.open internal}
* This value is always in the range <code>0</code>
* through <code>count</code>. If it is less
* than <code>count</code>, then <code>buf[pos]</code>
* is the next byte to be supplied as input;
* if it is equal to <code>count</code>, then
* the next <code>read</code> or <code>skip</code>
* operation will require more bytes to be
* read from the contained input stream.
* {@property.close}
*
* @see java.io.BufferedInputStream#buf
*/
protected int pos;
/** {@collect.stats}
* {@description.open}
* The value of the <code>pos</code> field at the time the last
* <code>mark</code> method was called.
* <p>
* {@description.close}
* {@property.open internal}
* This value is always
* in the range <code>-1</code> through <code>pos</code>.
* If there is no marked position in the input
* stream, this field is <code>-1</code>. If
* there is a marked position in the input
* stream, then <code>buf[markpos]</code>
* is the first byte to be supplied as input
* after a <code>reset</code> operation. If
* <code>markpos</code> is not <code>-1</code>,
* then all bytes from positions <code>buf[markpos]</code>
* through <code>buf[pos-1]</code> must remain
* in the buffer array (though they may be
* moved to another place in the buffer array,
* with suitable adjustments to the values
* of <code>count</code>, <code>pos</code>,
* and <code>markpos</code>); they may not
* be discarded unless and until the difference
* between <code>pos</code> and <code>markpos</code>
* exceeds <code>marklimit</code>.
* {@property.close}
*
* @see java.io.BufferedInputStream#mark(int)
* @see java.io.BufferedInputStream#pos
*/
protected int markpos = -1;
/** {@collect.stats}
* {@description.open}
* The maximum read ahead allowed after a call to the
* <code>mark</code> method before subsequent calls to the
* <code>reset</code> method fail.
* {@description.close}
* {@property.open runtime formal:java.io.InputStream_ReadAheadLimit}
* Whenever the difference between <code>pos</code>
* and <code>markpos</code> exceeds <code>marklimit</code>,
* then the mark may be dropped by setting
* <code>markpos</code> to <code>-1</code>.
* {@property.close}
*
* @see java.io.BufferedInputStream#mark(int)
* @see java.io.BufferedInputStream#reset()
*/
protected int marklimit;
/** {@collect.stats}
* {@description.open}
* Check to make sure that underlying input stream has not been
* nulled out due to close; if not return it;
* {@description.close}
*/
private InputStream getInIfOpen() throws IOException {
InputStream input = in;
if (input == null)
throw new IOException("Stream closed");
return input;
}
/** {@collect.stats}
* {@description.open}
* Check to make sure that buffer has not been nulled out due to
* close; if not return it;
* {@description.close}
*/
private byte[] getBufIfOpen() throws IOException {
byte[] buffer = buf;
if (buffer == null)
throw new IOException("Stream closed");
return buffer;
}
/** {@collect.stats}
* {@description.open}
* Creates a <code>BufferedInputStream</code>
* and saves its argument, the input stream
* <code>in</code>, for later use. An internal
* buffer array is created and stored in <code>buf</code>.
* {@description.close}
*
* @param in the underlying input stream.
*/
public BufferedInputStream(InputStream in) {
this(in, defaultBufferSize);
}
/** {@collect.stats}
* {@description.open}
* Creates a <code>BufferedInputStream</code>
* with the specified buffer size,
* and saves its argument, the input stream
* <code>in</code>, for later use. An internal
* buffer array of length <code>size</code>
* is created and stored in <code>buf</code>.
* {@description.close}
*
* @param in the underlying input stream.
* @param size the buffer size.
* @exception IllegalArgumentException if size <= 0.
*/
public BufferedInputStream(InputStream in, int size) {
super(in);
if (size <= 0) {
throw new IllegalArgumentException("Buffer size <= 0");
}
buf = new byte[size];
}
/** {@collect.stats}
* {@description.open}
* Fills the buffer with more data, taking into account
* shuffling and other tricks for dealing with marks.
* {@description.close}
* {@property.open runtime internal formal:java.io.BufferedInputStream_SynchronizedFill}
* Assumes that it is being called by a synchronized method.
* {@property.close}
* {@property.open internal}
* This method also assumes that all data has already been read in,
* hence pos > count.
* {@property.close}
*/
private void fill() throws IOException {
byte[] buffer = getBufIfOpen();
if (markpos < 0)
pos = 0; /* no mark: throw away the buffer */
else if (pos >= buffer.length) /* no room left in buffer */
if (markpos > 0) { /* can throw away early part of the buffer */
int sz = pos - markpos;
System.arraycopy(buffer, markpos, buffer, 0, sz);
pos = sz;
markpos = 0;
} else if (buffer.length >= marklimit) {
markpos = -1; /* buffer got too big, invalidate mark */
pos = 0; /* drop buffer contents */
} else { /* grow buffer */
int nsz = pos * 2;
if (nsz > marklimit)
nsz = marklimit;
byte nbuf[] = new byte[nsz];
System.arraycopy(buffer, 0, nbuf, 0, pos);
if (!bufUpdater.compareAndSet(this, buffer, nbuf)) {
// Can't replace buf if there was an async close.
// Note: This would need to be changed if fill()
// is ever made accessible to multiple threads.
// But for now, the only way CAS can fail is via close.
// assert buf == null;
throw new IOException("Stream closed");
}
buffer = nbuf;
}
count = pos;
int n = getInIfOpen().read(buffer, pos, buffer.length - pos);
if (n > 0)
count = n + pos;
}
/** {@collect.stats}
* {@description.open}
* See
* the general contract of the <code>read</code>
* method of <code>InputStream</code>.
* {@description.close}
*
* @return the next byte of data, or <code>-1</code> if the end of the
* stream is reached.
* @exception IOException if this input stream has been closed by
* invoking its {@link #close()} method,
* or an I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public synchronized int read() throws IOException {
if (pos >= count) {
fill();
if (pos >= count)
return -1;
}
return getBufIfOpen()[pos++] & 0xff;
}
/** {@collect.stats}
* {@description.open}
* Read characters into a portion of an array, reading from the underlying
* stream at most once if necessary.
* {@description.close}
*/
private int read1(byte[] b, int off, int len) throws IOException {
int avail = count - pos;
if (avail <= 0) {
/* If the requested length is at least as large as the buffer, and
if there is no mark/reset activity, do not bother to copy the
bytes into the local buffer. In this way buffered streams will
cascade harmlessly. */
if (len >= getBufIfOpen().length && markpos < 0) {
return getInIfOpen().read(b, off, len);
}
fill();
avail = count - pos;
if (avail <= 0) return -1;
}
int cnt = (avail < len) ? avail : len;
System.arraycopy(getBufIfOpen(), pos, b, off, cnt);
pos += cnt;
return cnt;
}
/** {@collect.stats}
* {@description.open}
* Reads bytes from this byte-input stream into the specified byte array,
* starting at the given offset.
*
* <p> This method implements the general contract of the corresponding
* <code>{@link InputStream#read(byte[], int, int) read}</code> method of
* the <code>{@link InputStream}</code> class. As an additional
* convenience, it attempts to read as many bytes as possible by repeatedly
* invoking the <code>read</code> method of the underlying stream. This
* iterated <code>read</code> continues until one of the following
* conditions becomes true: <ul>
*
* <li> The specified number of bytes have been read,
*
* <li> The <code>read</code> method of the underlying stream returns
* <code>-1</code>, indicating end-of-file, or
*
* <li> The <code>available</code> method of the underlying stream
* returns zero, indicating that further input requests would block.
*
* </ul> If the first <code>read</code> on the underlying stream returns
* <code>-1</code> to indicate end-of-file then this method returns
* <code>-1</code>. Otherwise this method returns the number of bytes
* actually read.
*
* <p> Subclasses of this class are encouraged, but not required, to
* attempt to read as many bytes as possible in the same fashion.
* {@description.close}
*
* @param b destination buffer.
* @param off offset at which to start storing bytes.
* @param len maximum number of bytes to read.
* @return the number of bytes read, or <code>-1</code> if the end of
* the stream has been reached.
* @exception IOException if this input stream has been closed by
* invoking its {@link #close()} method,
* or an I/O error occurs.
*/
public synchronized int read(byte b[], int off, int len)
throws IOException
{
getBufIfOpen(); // Check for closed stream
if ((off | len | (off + len) | (b.length - (off + len))) < 0) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
int n = 0;
for (;;) {
int nread = read1(b, off + n, len - n);
if (nread <= 0)
return (n == 0) ? nread : n;
n += nread;
if (n >= len)
return n;
// if not closed but no bytes available, return
InputStream input = in;
if (input != null && input.available() <= 0)
return n;
}
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>skip</code>
* method of <code>InputStream</code>.
* {@description.close}
*
* @exception IOException if the stream does not support seek,
* or if this input stream has been closed by
* invoking its {@link #close()} method, or an
* I/O error occurs.
*/
public synchronized long skip(long n) throws IOException {
getBufIfOpen(); // Check for closed stream
if (n <= 0) {
return 0;
}
long avail = count - pos;
if (avail <= 0) {
// If no mark position set then don't keep in buffer
if (markpos <0)
return getInIfOpen().skip(n);
// Fill in buffer to save bytes for reset
fill();
avail = count - pos;
if (avail <= 0)
return 0;
}
long skipped = (avail < n) ? avail : n;
pos += skipped;
return skipped;
}
/** {@collect.stats}
* {@description.open blocking}
* Returns an estimate of the number of bytes that can be read (or
* skipped over) from this input stream without blocking by the next
* invocation of a method for this input stream. The next invocation might be
* the same thread or another thread. A single read or skip of this
* many bytes will not block, but may read or skip fewer bytes.
* {@description.close}
* {@description.open}
* <p>
* This method returns the sum of the number of bytes remaining to be read in
* the buffer (<code>count - pos</code>) and the result of calling the
* {@link java.io.FilterInputStream#in in}.available().
* {@description.close}
*
* @return an estimate of the number of bytes that can be read (or skipped
* over) from this input stream without blocking.
* @exception IOException if this input stream has been closed by
* invoking its {@link #close()} method,
* or an I/O error occurs.
*/
public synchronized int available() throws IOException {
return getInIfOpen().available() + (count - pos);
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>mark</code>
* method of <code>InputStream</code>.
* {@description.close}
*
* @param readlimit the maximum limit of bytes that can be read before
* the mark position becomes invalid.
* @see java.io.BufferedInputStream#reset()
*/
public synchronized void mark(int readlimit) {
marklimit = readlimit;
markpos = pos;
}
/** {@collect.stats}
* {@description.open}
* See the general contract of the <code>reset</code>
* method of <code>InputStream</code>.
* <p>
* {@description.close}
* {@property.open runtime formal:java.io.Reader_ReadAheadLimit formal:java.io.Reader_UnmarkedReset}
* If <code>markpos</code> is <code>-1</code>
* (no mark has been set or the mark has been
* invalidated), an <code>IOException</code>
* is thrown. Otherwise, <code>pos</code> is
* set equal to <code>markpos</code>.
* {@property.close}
*
* @exception IOException if this stream has not been marked or,
* if the mark has been invalidated, or the stream
* has been closed by invoking its {@link #close()}
* method, or an I/O error occurs.
* @see java.io.BufferedInputStream#mark(int)
*/
public synchronized void reset() throws IOException {
getBufIfOpen(); // Cause exception if closed
if (markpos < 0)
throw new IOException("Resetting to invalid mark");
pos = markpos;
}
/** {@collect.stats}
* {@description.open}
* Tests if this input stream supports the <code>mark</code>
* and <code>reset</code> methods.
* {@description.close}
* {@property.open runtime formal:java.io.Reader_MarkReset}
* The <code>markSupported</code>
* method of <code>BufferedInputStream</code> returns
* <code>true</code>.
* {@property.close}
*
* @return a <code>boolean</code> indicating if this stream type supports
* the <code>mark</code> and <code>reset</code> methods.
* @see java.io.InputStream#mark(int)
* @see java.io.InputStream#reset()
*/
public boolean markSupported() {
return true;
}
/** {@collect.stats}
* {@description.open}
* Closes this input stream and releases any system resources
* associated with the stream.
* {@description.close}
* {@property.open runtime formal:java.io.InputStream_ManipulateAfterClose}
* Once the stream has been closed, further read(), available(), reset(),
* or skip() invocations will throw an IOException.
* {@property.close}
* {@property.open runtime formal:java.io.Closeable_MultipleClose}
* Closing a previously closed stream has no effect.
* {@property.close}
*
* @exception IOException if an I/O error occurs.
*/
public void close() throws IOException {
byte[] buffer;
while ( (buffer = buf) != null) {
if (bufUpdater.compareAndSet(this, buffer, null)) {
InputStream input = in;
in = null;
if (input != null)
input.close();
return;
}
// Else retry in case a new buf was CASed in fill()
}
}
}
|
Java
|
/*
* Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* A piped input stream should be connected
* to a piped output stream; the piped input
* stream then provides whatever data bytes
* are written to the piped output stream.
* Typically, data is read from a <code>PipedInputStream</code>
* object by one thread and data is written
* to the corresponding <code>PipedOutputStream</code>
* by some other thread.
* {@description.close}
* {@property.open runtime formal:java.io.PipedStream_SingleThread}
* Attempting to use
* both objects from a single thread is not
* recommended, as it may deadlock the thread.
* {@property.close}
* {@description.open}
* The piped input stream contains a buffer,
* decoupling read operations from write operations,
* within limits.
* A pipe is said to be <a name=BROKEN> <i>broken</i> </a> if a
* thread that was providing data bytes to the connected
* piped output stream is no longer alive.
* {@description.close}
*
* @author James Gosling
* @see java.io.PipedOutputStream
* @since JDK1.0
*/
public class PipedInputStream extends InputStream {
boolean closedByWriter = false;
volatile boolean closedByReader = false;
boolean connected = false;
/* REMIND: identification of the read and write sides needs to be
more sophisticated. Either using thread groups (but what about
pipes within a thread?) or using finalization (but it may be a
long time until the next GC). */
Thread readSide;
Thread writeSide;
private static final int DEFAULT_PIPE_SIZE = 1024;
/** {@collect.stats}
* {@description.open}
* The default size of the pipe's circular input buffer.
* {@description.close}
* @since JDK1.1
*/
// This used to be a constant before the pipe size was allowed
// to change. This field will continue to be maintained
// for backward compatibility.
protected static final int PIPE_SIZE = DEFAULT_PIPE_SIZE;
/** {@collect.stats}
* {@description.open}
* The circular buffer into which incoming data is placed.
* {@description.close}
* @since JDK1.1
*/
protected byte buffer[];
/** {@collect.stats}
* {@description.open}
* The index of the position in the circular buffer at which the
* next byte of data will be stored when received from the connected
* piped output stream. <code>in<0</code> implies the buffer is empty,
* <code>in==out</code> implies the buffer is full
* {@description.close}
* @since JDK1.1
*/
protected int in = -1;
/** {@collect.stats}
* {@description.open}
* The index of the position in the circular buffer at which the next
* byte of data will be read by this piped input stream.
* {@description.close}
* @since JDK1.1
*/
protected int out = 0;
/** {@collect.stats}
* {@description.open}
* Creates a <code>PipedInputStream</code> so
* that it is connected to the piped output
* stream <code>src</code>. Data bytes written
* to <code>src</code> will then be available
* as input from this stream.
* {@description.close}
*
* @param src the stream to connect to.
* @exception IOException if an I/O error occurs.
*/
public PipedInputStream(PipedOutputStream src) throws IOException {
this(src, DEFAULT_PIPE_SIZE);
}
/** {@collect.stats}
* {@description.open}
* Creates a <code>PipedInputStream</code> so that it is
* connected to the piped output stream
* <code>src</code> and uses the specified pipe size for
* the pipe's buffer.
* Data bytes written to <code>src</code> will then
* be available as input from this stream.
* {@description.close}
*
* @param src the stream to connect to.
* @param pipeSize the size of the pipe's buffer.
* @exception IOException if an I/O error occurs.
* @exception IllegalArgumentException if <code>pipeSize <= 0</code>.
* @since 1.6
*/
public PipedInputStream(PipedOutputStream src, int pipeSize)
throws IOException {
initPipe(pipeSize);
connect(src);
}
/** {@collect.stats}
* {@description.open}
* Creates a <code>PipedInputStream</code> so
* that it is not yet {@linkplain #connect(java.io.PipedOutputStream)
* connected}.
* It must be {@linkplain java.io.PipedOutputStream#connect(
* java.io.PipedInputStream) connected} to a
* <code>PipedOutputStream</code> before being used.
* {@description.close}
*/
public PipedInputStream() {
initPipe(DEFAULT_PIPE_SIZE);
}
/** {@collect.stats}
* {@description.open}
* Creates a <code>PipedInputStream</code> so that it is not yet
* {@linkplain #connect(java.io.PipedOutputStream) connected} and
* uses the specified pipe size for the pipe's buffer.
* It must be {@linkplain java.io.PipedOutputStream#connect(
* java.io.PipedInputStream)
* connected} to a <code>PipedOutputStream</code> before being used.
* {@description.close}
*
* @param pipeSize the size of the pipe's buffer.
* @exception IllegalArgumentException if <code>pipeSize <= 0</code>.
* @since 1.6
*/
public PipedInputStream(int pipeSize) {
initPipe(pipeSize);
}
private void initPipe(int pipeSize) {
if (pipeSize <= 0) {
throw new IllegalArgumentException("Pipe Size <= 0");
}
buffer = new byte[pipeSize];
}
/** {@collect.stats}
* {@description.open}
* Causes this piped input stream to be connected
* to the piped output stream <code>src</code>.
* If this object is already connected to some
* other piped output stream, an <code>IOException</code>
* is thrown.
* <p>
* If <code>src</code> is an
* unconnected piped output stream and <code>snk</code>
* is an unconnected piped input stream, they
* may be connected by either the call:
* <p>
* <pre><code>snk.connect(src)</code> </pre>
* <p>
* or the call:
* <p>
* <pre><code>src.connect(snk)</code> </pre>
* <p>
* The two
* calls have the same effect.
* {@description.close}
*
* @param src The piped output stream to connect to.
* @exception IOException if an I/O error occurs.
*/
public void connect(PipedOutputStream src) throws IOException {
src.connect(this);
}
/** {@collect.stats}
* {@description.open}
* Receives a byte of data.
* {@description.close}
* {@description.open blocking}
* This method will block if no input is
* available.
* {@description.close}
* @param b the byte being received
* @exception IOException If the pipe is <a href=#BROKEN> <code>broken</code></a>,
* {@link #connect(java.io.PipedOutputStream) unconnected},
* closed, or if an I/O error occurs.
* @since JDK1.1
*/
protected synchronized void receive(int b) throws IOException {
checkStateForReceive();
writeSide = Thread.currentThread();
if (in == out)
awaitSpace();
if (in < 0) {
in = 0;
out = 0;
}
buffer[in++] = (byte)(b & 0xFF);
if (in >= buffer.length) {
in = 0;
}
}
/** {@collect.stats}
* {@description.open}
* Receives data into an array of bytes.
* {@description.close}
* {@description.open blocking}
* This method will
* block until some input is available.
* {@description.close}
* @param b the buffer into which the data is received
* @param off the start offset of the data
* @param len the maximum number of bytes received
* @exception IOException If the pipe is <a href=#BROKEN> broken</a>,
* {@link #connect(java.io.PipedOutputStream) unconnected},
* closed,or if an I/O error occurs.
*/
synchronized void receive(byte b[], int off, int len) throws IOException {
checkStateForReceive();
writeSide = Thread.currentThread();
int bytesToTransfer = len;
while (bytesToTransfer > 0) {
if (in == out)
awaitSpace();
int nextTransferAmount = 0;
if (out < in) {
nextTransferAmount = buffer.length - in;
} else if (in < out) {
if (in == -1) {
in = out = 0;
nextTransferAmount = buffer.length - in;
} else {
nextTransferAmount = out - in;
}
}
if (nextTransferAmount > bytesToTransfer)
nextTransferAmount = bytesToTransfer;
assert(nextTransferAmount > 0);
System.arraycopy(b, off, buffer, in, nextTransferAmount);
bytesToTransfer -= nextTransferAmount;
off += nextTransferAmount;
in += nextTransferAmount;
if (in >= buffer.length) {
in = 0;
}
}
}
private void checkStateForReceive() throws IOException {
if (!connected) {
throw new IOException("Pipe not connected");
} else if (closedByWriter || closedByReader) {
throw new IOException("Pipe closed");
} else if (readSide != null && !readSide.isAlive()) {
throw new IOException("Read end dead");
}
}
private void awaitSpace() throws IOException {
while (in == out) {
checkStateForReceive();
/* full: kick any waiting readers */
notifyAll();
try {
wait(1000);
} catch (InterruptedException ex) {
throw new java.io.InterruptedIOException();
}
}
}
/** {@collect.stats}
* {@description.open}
* Notifies all waiting threads that the last byte of data has been
* received.
* {@description.close}
*/
synchronized void receivedLast() {
closedByWriter = true;
notifyAll();
}
/** {@collect.stats}
* {@description.open}
* Reads the next byte of data from this piped input stream. The
* value byte is returned as an <code>int</code> in the range
* <code>0</code> to <code>255</code>.
* {@description.close}
* {@description.open blocking}
* This method blocks until input data is available, the end of the
* stream is detected, or an exception is thrown.
* {@description.close}
*
* @return the next byte of data, or <code>-1</code> if the end of the
* stream is reached.
* @exception IOException if the pipe is
* {@link #connect(java.io.PipedOutputStream) unconnected},
* <a href=#BROKEN> <code>broken</code></a>, closed,
* or if an I/O error occurs.
*/
public synchronized int read() throws IOException {
if (!connected) {
throw new IOException("Pipe not connected");
} else if (closedByReader) {
throw new IOException("Pipe closed");
} else if (writeSide != null && !writeSide.isAlive()
&& !closedByWriter && (in < 0)) {
throw new IOException("Write end dead");
}
readSide = Thread.currentThread();
int trials = 2;
while (in < 0) {
if (closedByWriter) {
/* closed by writer, return EOF */
return -1;
}
if ((writeSide != null) && (!writeSide.isAlive()) && (--trials < 0)) {
throw new IOException("Pipe broken");
}
/* might be a writer waiting */
notifyAll();
try {
wait(1000);
} catch (InterruptedException ex) {
throw new java.io.InterruptedIOException();
}
}
int ret = buffer[out++] & 0xFF;
if (out >= buffer.length) {
out = 0;
}
if (in == out) {
/* now empty */
in = -1;
}
return ret;
}
/** {@collect.stats}
* {@description.open}
* Reads up to <code>len</code> bytes of data from this piped input
* stream into an array of bytes. Less than <code>len</code> bytes
* will be read if the end of the data stream is reached or if
* <code>len</code> exceeds the pipe's buffer size.
* {@description.close}
* {@description.open blocking}
* If <code>len </code> is zero, then no bytes are read and 0 is returned;
* otherwise, the method blocks until at least 1 byte of input is
* available, end of the stream has been detected, or an exception is
* thrown.
* {@description.close}
*
* @param b the buffer into which the data is read.
* @param off the start offset in the destination array <code>b</code>
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the stream has been reached.
* @exception NullPointerException If <code>b</code> is <code>null</code>.
* @exception IndexOutOfBoundsException If <code>off</code> is negative,
* <code>len</code> is negative, or <code>len</code> is greater than
* <code>b.length - off</code>
* @exception IOException if the pipe is <a href=#BROKEN> <code>broken</code></a>,
* {@link #connect(java.io.PipedOutputStream) unconnected},
* closed, or if an I/O error occurs.
*/
public synchronized int read(byte b[], int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return 0;
}
/* possibly wait on the first character */
int c = read();
if (c < 0) {
return -1;
}
b[off] = (byte) c;
int rlen = 1;
while ((in >= 0) && (len > 1)) {
int available;
if (in > out) {
available = Math.min((buffer.length - out), (in - out));
} else {
available = buffer.length - out;
}
// A byte is read beforehand outside the loop
if (available > (len - 1)) {
available = len - 1;
}
System.arraycopy(buffer, out, b, off + rlen, available);
out += available;
rlen += available;
len -= available;
if (out >= buffer.length) {
out = 0;
}
if (in == out) {
/* now empty */
in = -1;
}
}
return rlen;
}
/** {@collect.stats}
* {@description.open}
* Returns the number of bytes that can be read from this input
* stream without blocking.
* {@description.close}
*
* @return the number of bytes that can be read from this input stream
* without blocking, or {@code 0} if this input stream has been
* closed by invoking its {@link #close()} method, or if the pipe
* is {@link #connect(java.io.PipedOutputStream) unconnected}, or
* <a href=#BROKEN> <code>broken</code></a>.
*
* @exception IOException if an I/O error occurs.
* @since JDK1.0.2
*/
public synchronized int available() throws IOException {
if(in < 0)
return 0;
else if(in == out)
return buffer.length;
else if (in > out)
return in - out;
else
return in + buffer.length - out;
}
/** {@collect.stats}
* {@description.open}
* Closes this piped input stream and releases any system resources
* associated with the stream.
* {@description.close}
*
* @exception IOException if an I/O error occurs.
*/
public void close() throws IOException {
closedByReader = true;
synchronized (this) {
in = -1;
}
}
}
|
Java
|
/*
* Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* A data output stream lets an application write primitive Java data
* types to an output stream in a portable way. An application can
* then use a data input stream to read the data back in.
* {@description.close}
*
* @author unascribed
* @see java.io.DataInputStream
* @since JDK1.0
*/
public
class DataOutputStream extends FilterOutputStream implements DataOutput {
/** {@collect.stats}
* {@description.open}
* The number of bytes written to the data output stream so far.
* {@description.close}
* {@property.open}
* If this counter overflows, it will be wrapped to Integer.MAX_VALUE.
* {@property.close}
*/
protected int written;
/** {@collect.stats}
* {@description.open}
* bytearr is initialized on demand by writeUTF
* {@description.close}
*/
private byte[] bytearr = null;
/** {@collect.stats}
* {@description.open}
* Creates a new data output stream to write data to the specified
* underlying output stream. The counter <code>written</code> is
* set to zero.
* {@description.close}
*
* @param out the underlying output stream, to be saved for later
* use.
* @see java.io.FilterOutputStream#out
*/
public DataOutputStream(OutputStream out) {
super(out);
}
/** {@collect.stats}
* {@description.open}
* Increases the written counter by the specified value
* until it reaches Integer.MAX_VALUE.
* {@description.close}
*/
private void incCount(int value) {
int temp = written + value;
if (temp < 0) {
temp = Integer.MAX_VALUE;
}
written = temp;
}
/** {@collect.stats}
* {@description.open}
* Writes the specified byte (the low eight bits of the argument
* <code>b</code>) to the underlying output stream. If no exception
* is thrown, the counter <code>written</code> is incremented by
* <code>1</code>.
* <p>
* Implements the <code>write</code> method of <code>OutputStream</code>.
* {@description.close}
*
* @param b the <code>byte</code> to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
*/
public synchronized void write(int b) throws IOException {
out.write(b);
incCount(1);
}
/** {@collect.stats}
* {@description.open}
* Writes <code>len</code> bytes from the specified byte array
* starting at offset <code>off</code> to the underlying output stream.
* If no exception is thrown, the counter <code>written</code> is
* incremented by <code>len</code>.
* {@description.close}
*
* @param b the data.
* @param off the start offset in the data.
* @param len the number of bytes to write.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
*/
public synchronized void write(byte b[], int off, int len)
throws IOException
{
out.write(b, off, len);
incCount(len);
}
/** {@collect.stats}
* {@description.open}
* Flushes this data output stream. This forces any buffered output
* bytes to be written out to the stream.
* <p>
* The <code>flush</code> method of <code>DataOutputStream</code>
* calls the <code>flush</code> method of its underlying output stream.
* {@description.close}
*
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
* @see java.io.OutputStream#flush()
*/
public void flush() throws IOException {
out.flush();
}
/** {@collect.stats}
* {@description.open}
* Writes a <code>boolean</code> to the underlying output stream as
* a 1-byte value. The value <code>true</code> is written out as the
* value <code>(byte)1</code>; the value <code>false</code> is
* written out as the value <code>(byte)0</code>. If no exception is
* thrown, the counter <code>written</code> is incremented by
* <code>1</code>.
* {@description.close}
*
* @param v a <code>boolean</code> value to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
*/
public final void writeBoolean(boolean v) throws IOException {
out.write(v ? 1 : 0);
incCount(1);
}
/** {@collect.stats}
* {@description.open}
* Writes out a <code>byte</code> to the underlying output stream as
* a 1-byte value. If no exception is thrown, the counter
* <code>written</code> is incremented by <code>1</code>.
* {@description.close}
*
* @param v a <code>byte</code> value to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
*/
public final void writeByte(int v) throws IOException {
out.write(v);
incCount(1);
}
/** {@collect.stats}
* {@description.open}
* Writes a <code>short</code> to the underlying output stream as two
* bytes, high byte first. If no exception is thrown, the counter
* <code>written</code> is incremented by <code>2</code>.
* {@description.close}
*
* @param v a <code>short</code> to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
*/
public final void writeShort(int v) throws IOException {
out.write((v >>> 8) & 0xFF);
out.write((v >>> 0) & 0xFF);
incCount(2);
}
/** {@collect.stats}
* {@description.open}
* Writes a <code>char</code> to the underlying output stream as a
* 2-byte value, high byte first. If no exception is thrown, the
* counter <code>written</code> is incremented by <code>2</code>.
* {@description.close}
*
* @param v a <code>char</code> value to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
*/
public final void writeChar(int v) throws IOException {
out.write((v >>> 8) & 0xFF);
out.write((v >>> 0) & 0xFF);
incCount(2);
}
/** {@collect.stats}
* {@description.open}
* Writes an <code>int</code> to the underlying output stream as four
* bytes, high byte first. If no exception is thrown, the counter
* <code>written</code> is incremented by <code>4</code>.
* {@description.close}
*
* @param v an <code>int</code> to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
*/
public final void writeInt(int v) throws IOException {
out.write((v >>> 24) & 0xFF);
out.write((v >>> 16) & 0xFF);
out.write((v >>> 8) & 0xFF);
out.write((v >>> 0) & 0xFF);
incCount(4);
}
private byte writeBuffer[] = new byte[8];
/** {@collect.stats}
* {@description.open}
* Writes a <code>long</code> to the underlying output stream as eight
* bytes, high byte first. In no exception is thrown, the counter
* <code>written</code> is incremented by <code>8</code>.
* {@description.close}
*
* @param v a <code>long</code> to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
*/
public final void writeLong(long v) throws IOException {
writeBuffer[0] = (byte)(v >>> 56);
writeBuffer[1] = (byte)(v >>> 48);
writeBuffer[2] = (byte)(v >>> 40);
writeBuffer[3] = (byte)(v >>> 32);
writeBuffer[4] = (byte)(v >>> 24);
writeBuffer[5] = (byte)(v >>> 16);
writeBuffer[6] = (byte)(v >>> 8);
writeBuffer[7] = (byte)(v >>> 0);
out.write(writeBuffer, 0, 8);
incCount(8);
}
/** {@collect.stats}
* {@description.open}
* Converts the float argument to an <code>int</code> using the
* <code>floatToIntBits</code> method in class <code>Float</code>,
* and then writes that <code>int</code> value to the underlying
* output stream as a 4-byte quantity, high byte first. If no
* exception is thrown, the counter <code>written</code> is
* incremented by <code>4</code>.
* {@description.close}
*
* @param v a <code>float</code> value to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
* @see java.lang.Float#floatToIntBits(float)
*/
public final void writeFloat(float v) throws IOException {
writeInt(Float.floatToIntBits(v));
}
/** {@collect.stats}
* {@description.open}
* Converts the double argument to a <code>long</code> using the
* <code>doubleToLongBits</code> method in class <code>Double</code>,
* and then writes that <code>long</code> value to the underlying
* output stream as an 8-byte quantity, high byte first. If no
* exception is thrown, the counter <code>written</code> is
* incremented by <code>8</code>.
* {@description.close}
*
* @param v a <code>double</code> value to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
* @see java.lang.Double#doubleToLongBits(double)
*/
public final void writeDouble(double v) throws IOException {
writeLong(Double.doubleToLongBits(v));
}
/** {@collect.stats}
* {@description.open}
* Writes out the string to the underlying output stream as a
* sequence of bytes. Each character in the string is written out, in
* sequence, by discarding its high eight bits. If no exception is
* thrown, the counter <code>written</code> is incremented by the
* length of <code>s</code>.
* {@description.close}
*
* @param s a string of bytes to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
*/
public final void writeBytes(String s) throws IOException {
int len = s.length();
for (int i = 0 ; i < len ; i++) {
out.write((byte)s.charAt(i));
}
incCount(len);
}
/** {@collect.stats}
* {@description.open}
* Writes a string to the underlying output stream as a sequence of
* characters. Each character is written to the data output stream as
* if by the <code>writeChar</code> method. If no exception is
* thrown, the counter <code>written</code> is incremented by twice
* the length of <code>s</code>.
* {@description.close}
*
* @param s a <code>String</code> value to be written.
* @exception IOException if an I/O error occurs.
* @see java.io.DataOutputStream#writeChar(int)
* @see java.io.FilterOutputStream#out
*/
public final void writeChars(String s) throws IOException {
int len = s.length();
for (int i = 0 ; i < len ; i++) {
int v = s.charAt(i);
out.write((v >>> 8) & 0xFF);
out.write((v >>> 0) & 0xFF);
}
incCount(len * 2);
}
/** {@collect.stats}
* {@description.open}
* Writes a string to the underlying output stream using
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
* encoding in a machine-independent manner.
* <p>
* First, two bytes are written to the output stream as if by the
* <code>writeShort</code> method giving the number of bytes to
* follow. This value is the number of bytes actually written out,
* not the length of the string. Following the length, each character
* of the string is output, in sequence, using the modified UTF-8 encoding
* for the character. If no exception is thrown, the counter
* <code>written</code> is incremented by the total number of
* bytes written to the output stream. This will be at least two
* plus the length of <code>str</code>, and at most two plus
* thrice the length of <code>str</code>.
* {@description.close}
*
* @param str a string to be written.
* @exception IOException if an I/O error occurs.
*/
public final void writeUTF(String str) throws IOException {
writeUTF(str, this);
}
/** {@collect.stats}
* {@description.open}
* Writes a string to the specified DataOutput using
* <a href="DataInput.html#modified-utf-8">modified UTF-8</a>
* encoding in a machine-independent manner.
* <p>
* First, two bytes are written to out as if by the <code>writeShort</code>
* method giving the number of bytes to follow. This value is the number of
* bytes actually written out, not the length of the string. Following the
* length, each character of the string is output, in sequence, using the
* modified UTF-8 encoding for the character. If no exception is thrown, the
* counter <code>written</code> is incremented by the total number of
* bytes written to the output stream. This will be at least two
* plus the length of <code>str</code>, and at most two plus
* thrice the length of <code>str</code>.
* {@description.close}
*
* @param str a string to be written.
* @param out destination to write to
* @return The number of bytes written out.
* @exception IOException if an I/O error occurs.
*/
static int writeUTF(String str, DataOutput out) throws IOException {
int strlen = str.length();
int utflen = 0;
int c, count = 0;
/* use charAt instead of copying String to char array */
for (int i = 0; i < strlen; i++) {
c = str.charAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
utflen++;
} else if (c > 0x07FF) {
utflen += 3;
} else {
utflen += 2;
}
}
if (utflen > 65535)
throw new UTFDataFormatException(
"encoded string too long: " + utflen + " bytes");
byte[] bytearr = null;
if (out instanceof DataOutputStream) {
DataOutputStream dos = (DataOutputStream)out;
if(dos.bytearr == null || (dos.bytearr.length < (utflen+2)))
dos.bytearr = new byte[(utflen*2) + 2];
bytearr = dos.bytearr;
} else {
bytearr = new byte[utflen+2];
}
bytearr[count++] = (byte) ((utflen >>> 8) & 0xFF);
bytearr[count++] = (byte) ((utflen >>> 0) & 0xFF);
int i=0;
for (i=0; i<strlen; i++) {
c = str.charAt(i);
if (!((c >= 0x0001) && (c <= 0x007F))) break;
bytearr[count++] = (byte) c;
}
for (;i < strlen; i++){
c = str.charAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
bytearr[count++] = (byte) c;
} else if (c > 0x07FF) {
bytearr[count++] = (byte) (0xE0 | ((c >> 12) & 0x0F));
bytearr[count++] = (byte) (0x80 | ((c >> 6) & 0x3F));
bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F));
} else {
bytearr[count++] = (byte) (0xC0 | ((c >> 6) & 0x1F));
bytearr[count++] = (byte) (0x80 | ((c >> 0) & 0x3F));
}
}
out.write(bytearr, 0, utflen+2);
return utflen + 2;
}
/** {@collect.stats}
* {@description.open}
* Returns the current value of the counter <code>written</code>,
* the number of bytes written to this data output stream so far.
* If the counter overflows, it will be wrapped to Integer.MAX_VALUE.
* {@description.close}
*
* @return the value of the <code>written</code> field.
* @see java.io.DataOutputStream#written
*/
public final int size() {
return written;
}
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Abstract class for reading character streams. The only methods that a
* subclass must implement are read(char[], int, int) and close(). Most
* subclasses, however, will override some of the methods defined here in order
* to provide higher efficiency, additional functionality, or both.
* {@description.close}
*
*
* @see BufferedReader
* @see LineNumberReader
* @see CharArrayReader
* @see InputStreamReader
* @see FileReader
* @see FilterReader
* @see PushbackReader
* @see PipedReader
* @see StringReader
* @see Writer
*
* @author Mark Reinhold
* @since JDK1.1
*/
public abstract class Reader implements Readable, Closeable {
/** {@collect.stats}
* {@description.open}
* The object used to synchronize operations on this stream. For
* efficiency, a character-stream object may use an object other than
* itself to protect critical sections. A subclass should therefore use
* the object in this field rather than <tt>this</tt> or a synchronized
* method.
* {@description.close}
*/
protected Object lock;
/** {@collect.stats}
* {@description.open}
* Creates a new character-stream reader whose critical sections will
* synchronize on the reader itself.
* {@description.close}
*/
protected Reader() {
this.lock = this;
}
/** {@collect.stats}
* {@description.open}
* Creates a new character-stream reader whose critical sections will
* synchronize on the given object.
* {@description.close}
*
* @param lock The Object to synchronize on.
*/
protected Reader(Object lock) {
if (lock == null) {
throw new NullPointerException();
}
this.lock = lock;
}
/** {@collect.stats}
* {@description.open}
* Attempts to read characters into the specified character buffer.
* The buffer is used as a repository of characters as-is: the only
* changes made are the results of a put operation. No flipping or
* rewinding of the buffer is performed.
* {@description.close}
*
* @param target the buffer to read characters into
* @return The number of characters added to the buffer, or
* -1 if this source of characters is at its end
* @throws IOException if an I/O error occurs
* @throws NullPointerException if target is null
* @throws ReadOnlyBufferException if target is a read only buffer
* @since 1.5
*/
public int read(java.nio.CharBuffer target) throws IOException {
int len = target.remaining();
char[] cbuf = new char[len];
int n = read(cbuf, 0, len);
if (n > 0)
target.put(cbuf, 0, n);
return n;
}
/** {@collect.stats}
* {@description.open}
* Reads a single character.
* {@description.close}
* {@description.open blocking}
* This method will block until a character is
* available, an I/O error occurs, or the end of the stream is reached.
* {@description.close}
*
* {@description.open}
* <p> Subclasses that intend to support efficient single-character input
* should override this method.
* {@description.close}
*
* @return The character read, as an integer in the range 0 to 65535
* (<tt>0x00-0xffff</tt>), or -1 if the end of the stream has
* been reached
*
* @exception IOException If an I/O error occurs
*/
public int read() throws IOException {
char cb[] = new char[1];
if (read(cb, 0, 1) == -1)
return -1;
else
return cb[0];
}
/** {@collect.stats}
* {@description.open}
* Reads characters into an array.
* {@description.close}
* {@description.open blocking}
* This method will block until some input
* is available, an I/O error occurs, or the end of the stream is reached.
* {@description.close}
*
* @param cbuf Destination buffer
*
* @return The number of characters read, or -1
* if the end of the stream
* has been reached
*
* @exception IOException If an I/O error occurs
*/
public int read(char cbuf[]) throws IOException {
return read(cbuf, 0, cbuf.length);
}
/** {@collect.stats}
* {@description.open}
* Reads characters into a portion of an array.
* {@description.close}
* {@description.open blocking}
* This method will block
* until some input is available, an I/O error occurs, or the end of the
* stream is reached.
* {@description.close}
*
* @param cbuf Destination buffer
* @param off Offset at which to start storing characters
* @param len Maximum number of characters to read
*
* @return The number of characters read, or -1 if the end of the
* stream has been reached
*
* @exception IOException If an I/O error occurs
*/
abstract public int read(char cbuf[], int off, int len) throws IOException;
/** {@collect.stats}
* {@description.open}
* Maximum skip-buffer size
* {@description.close}
*/
private static final int maxSkipBufferSize = 8192;
/** {@collect.stats}
* {@description.open}
* Skip buffer, null until allocated
* {@description.close}
*/
private char skipBuffer[] = null;
/** {@collect.stats}
* {@description.open}
* Skips characters.
* {@description.close}
* {@description.open blocking}
* This method will block until some characters are
* available, an I/O error occurs, or the end of the stream is reached.
* {@description.close}
*
* @param n The number of characters to skip
*
* @return The number of characters actually skipped
*
* @exception IllegalArgumentException If <code>n</code> is negative.
* @exception IOException If an I/O error occurs
*/
public long skip(long n) throws IOException {
if (n < 0L)
throw new IllegalArgumentException("skip value is negative");
int nn = (int) Math.min(n, maxSkipBufferSize);
synchronized (lock) {
if ((skipBuffer == null) || (skipBuffer.length < nn))
skipBuffer = new char[nn];
long r = n;
while (r > 0) {
int nc = read(skipBuffer, 0, (int)Math.min(r, nn));
if (nc == -1)
break;
r -= nc;
}
return n - r;
}
}
/** {@collect.stats}
* {@description.open}
* Tells whether this stream is ready to be read.
* {@description.close}
*
* @return True if the next read() is guaranteed not to block for input,
* false otherwise. Note that returning false does not guarantee that the
* next read will block.
*
* @exception IOException If an I/O error occurs
*/
public boolean ready() throws IOException {
return false;
}
/** {@collect.stats}
* {@description.open}
* Tells whether this stream supports the mark() operation. The default
* implementation always returns false. Subclasses should override this
* method.
* {@description.close}
*
* @return true if and only if this stream supports the mark operation.
*/
public boolean markSupported() {
return false;
}
/** {@collect.stats}
* {@description.open}
* Marks the present position in the stream. Subsequent calls to reset()
* will attempt to reposition the stream to this point.
* {@description.close}
* {@property.open runtime formal:java.io.Reader_MarkReset}
* Not all
* character-input streams support the mark() operation.
* {@property.close}
*
* @param readAheadLimit Limit on the number of characters that may be
* read while still preserving the mark. After
* reading this many characters, attempting to
* reset the stream may fail.
*
* @exception IOException If the stream does not support mark(),
* or if some other I/O error occurs
*/
public void mark(int readAheadLimit) throws IOException {
throw new IOException("mark() not supported");
}
/** {@collect.stats}
* {@description.open}
* Resets the stream. If the stream has been marked, then attempt to
* reposition it at the mark.
* {@description.close}
* {@property.open runtime formal:java.io.Reader_UnmarkedReset}
* If the stream has not been marked, then
* attempt to reset it in some way appropriate to the particular stream,
* for example by repositioning it to its starting point. Not all
* character-input streams support the reset() operation, and some support
* reset() without supporting mark().
* {@property.close}
*
* @exception IOException If the stream has not been marked,
* or if the mark has been invalidated,
* or if the stream does not support reset(),
* or if some other I/O error occurs
*/
public void reset() throws IOException {
throw new IOException("reset() not supported");
}
/** {@collect.stats}
* {@description.open}
* Closes the stream and releases any system resources associated with
* it.
* {@description.close}
* {@property.open runtime formal:java.io.Reader_ManipulateAfterClose}
* Once the stream has been closed, further read(), ready(),
* mark(), reset(), or skip() invocations will throw an IOException.
* {@property.close}
* {@property.open runtime formal:java.io.Closeable_MultipleClose}
* Closing a previously closed stream has no effect.
* {@property.close}
*
* @exception IOException If an I/O error occurs
*/
abstract public void close() throws IOException;
}
|
Java
|
/*
* Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.io.IOException;
/** {@collect.stats}
* {@description.open}
* A <tt>Flushable</tt> is a destination of data that can be flushed. The
* flush method is invoked to write any buffered output to the underlying
* stream.
* {@description.close}
*
* @since 1.5
*/
public interface Flushable {
/** {@collect.stats}
* {@description.open}
* Flushes this stream by writing any buffered output to the underlying
* stream.
* {@description.close}
*
* @throws IOException If an I/O error occurs
*/
void flush() throws IOException;
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Superclass of all exceptions specific to Object Stream classes.
* {@description.close}
*
* @author unascribed
* @since JDK1.1
*/
public abstract class ObjectStreamException extends IOException {
private static final long serialVersionUID = 7260898174833392607L;
/** {@collect.stats}
* {@description.open}
* Create an ObjectStreamException with the specified argument.
* {@description.close}
*
* @param classname the detailed message for the exception
*/
protected ObjectStreamException(String classname) {
super(classname);
}
/** {@collect.stats}
* {@description.open}
* Create an ObjectStreamException.
* {@description.close}
*/
protected ObjectStreamException() {
super();
}
}
|
Java
|
/*
* Copyright (c) 1994, 2007, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.nio.channels.FileChannel;
import sun.nio.ch.FileChannelImpl;
/** {@collect.stats}
* {@description.open}
* A file output stream is an output stream for writing data to a
* <code>File</code> or to a <code>FileDescriptor</code>. Whether or not
* a file is available or may be created depends upon the underlying
* platform. Some platforms, in particular, allow a file to be opened
* for writing by only one <tt>FileOutputStream</tt> (or other
* file-writing object) at a time. In such situations the constructors in
* this class will fail if the file involved is already open.
*
* <p><code>FileOutputStream</code> is meant for writing streams of raw bytes
* such as image data. For writing streams of characters, consider using
* <code>FileWriter</code>.
* {@description.close}
*
* @author Arthur van Hoff
* @see java.io.File
* @see java.io.FileDescriptor
* @see java.io.FileInputStream
* @since JDK1.0
*/
public
class FileOutputStream extends OutputStream
{
/** {@collect.stats}
* {@description.open}
* The system dependent file descriptor. The value is
* 1 more than actual file descriptor. This means that
* the default value 0 indicates that the file is not open.
* {@description.close}
*/
private FileDescriptor fd;
private FileChannel channel= null;
private boolean append = false;
private Object closeLock = new Object();
private volatile boolean closed = false;
private static ThreadLocal<Boolean> runningFinalize =
new ThreadLocal<Boolean>();
private static boolean isRunningFinalize() {
Boolean val;
if ((val = runningFinalize.get()) != null)
return val.booleanValue();
return false;
}
/** {@collect.stats}
* {@description.open}
* Creates an output file stream to write to the file with the
* specified name. A new <code>FileDescriptor</code> object is
* created to represent this file connection.
* <p>
* First, if there is a security manager, its <code>checkWrite</code>
* method is called with <code>name</code> as its argument.
* <p>
* If the file exists but is a directory rather than a regular file, does
* not exist but cannot be created, or cannot be opened for any other
* reason then a <code>FileNotFoundException</code> is thrown.
* {@description.close}
*
* @param name the system-dependent filename
* @exception FileNotFoundException if the file exists but is a directory
* rather than a regular file, does not exist but cannot
* be created, or cannot be opened for any other reason
* @exception SecurityException if a security manager exists and its
* <code>checkWrite</code> method denies write access
* to the file.
* @see java.lang.SecurityManager#checkWrite(java.lang.String)
*/
public FileOutputStream(String name) throws FileNotFoundException {
this(name != null ? new File(name) : null, false);
}
/** {@collect.stats}
* {@description.open}
* Creates an output file stream to write to the file with the specified
* <code>name</code>. If the second argument is <code>true</code>, then
* bytes will be written to the end of the file rather than the beginning.
* A new <code>FileDescriptor</code> object is created to represent this
* file connection.
* <p>
* First, if there is a security manager, its <code>checkWrite</code>
* method is called with <code>name</code> as its argument.
* <p>
* If the file exists but is a directory rather than a regular file, does
* not exist but cannot be created, or cannot be opened for any other
* reason then a <code>FileNotFoundException</code> is thrown.
* {@description.close}
*
* @param name the system-dependent file name
* @param append if <code>true</code>, then bytes will be written
* to the end of the file rather than the beginning
* @exception FileNotFoundException if the file exists but is a directory
* rather than a regular file, does not exist but cannot
* be created, or cannot be opened for any other reason.
* @exception SecurityException if a security manager exists and its
* <code>checkWrite</code> method denies write access
* to the file.
* @see java.lang.SecurityManager#checkWrite(java.lang.String)
* @since JDK1.1
*/
public FileOutputStream(String name, boolean append)
throws FileNotFoundException
{
this(name != null ? new File(name) : null, append);
}
/** {@collect.stats}
* {@description.open}
* Creates a file output stream to write to the file represented by
* the specified <code>File</code> object. A new
* <code>FileDescriptor</code> object is created to represent this
* file connection.
* <p>
* First, if there is a security manager, its <code>checkWrite</code>
* method is called with the path represented by the <code>file</code>
* argument as its argument.
* <p>
* If the file exists but is a directory rather than a regular file, does
* not exist but cannot be created, or cannot be opened for any other
* reason then a <code>FileNotFoundException</code> is thrown.
* {@description.close}
*
* @param file the file to be opened for writing.
* @exception FileNotFoundException if the file exists but is a directory
* rather than a regular file, does not exist but cannot
* be created, or cannot be opened for any other reason
* @exception SecurityException if a security manager exists and its
* <code>checkWrite</code> method denies write access
* to the file.
* @see java.io.File#getPath()
* @see java.lang.SecurityException
* @see java.lang.SecurityManager#checkWrite(java.lang.String)
*/
public FileOutputStream(File file) throws FileNotFoundException {
this(file, false);
}
/** {@collect.stats}
* {@description.open}
* Creates a file output stream to write to the file represented by
* the specified <code>File</code> object. If the second argument is
* <code>true</code>, then bytes will be written to the end of the file
* rather than the beginning. A new <code>FileDescriptor</code> object is
* created to represent this file connection.
* <p>
* First, if there is a security manager, its <code>checkWrite</code>
* method is called with the path represented by the <code>file</code>
* argument as its argument.
* <p>
* If the file exists but is a directory rather than a regular file, does
* not exist but cannot be created, or cannot be opened for any other
* reason then a <code>FileNotFoundException</code> is thrown.
* {@description.close}
*
* @param file the file to be opened for writing.
* @param append if <code>true</code>, then bytes will be written
* to the end of the file rather than the beginning
* @exception FileNotFoundException if the file exists but is a directory
* rather than a regular file, does not exist but cannot
* be created, or cannot be opened for any other reason
* @exception SecurityException if a security manager exists and its
* <code>checkWrite</code> method denies write access
* to the file.
* @see java.io.File#getPath()
* @see java.lang.SecurityException
* @see java.lang.SecurityManager#checkWrite(java.lang.String)
* @since 1.4
*/
public FileOutputStream(File file, boolean append)
throws FileNotFoundException
{
String name = (file != null ? file.getPath() : null);
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkWrite(name);
}
if (name == null) {
throw new NullPointerException();
}
fd = new FileDescriptor();
fd.incrementAndGetUseCount();
this.append = append;
if (append) {
openAppend(name);
} else {
open(name);
}
}
/** {@collect.stats}
* {@description.open}
* Creates an output file stream to write to the specified file
* descriptor, which represents an existing connection to an actual
* file in the file system.
* <p>
* First, if there is a security manager, its <code>checkWrite</code>
* method is called with the file descriptor <code>fdObj</code>
* argument as its argument.
* {@description.close}
*
* @param fdObj the file descriptor to be opened for writing
* @exception SecurityException if a security manager exists and its
* <code>checkWrite</code> method denies
* write access to the file descriptor
* @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor)
*/
public FileOutputStream(FileDescriptor fdObj) {
SecurityManager security = System.getSecurityManager();
if (fdObj == null) {
throw new NullPointerException();
}
if (security != null) {
security.checkWrite(fdObj);
}
fd = fdObj;
/*
* FileDescriptor is being shared by streams.
* Ensure that it's GC'ed only when all the streams/channels are done
* using it.
*/
fd.incrementAndGetUseCount();
}
/** {@collect.stats}
* {@description.open}
* Opens a file, with the specified name, for writing.
* {@description.close}
* @param name name of file to be opened
*/
private native void open(String name) throws FileNotFoundException;
/** {@collect.stats}
* {@description.open}
* Opens a file, with the specified name, for appending.
* {@description.close}
* @param name name of file to be opened
*/
private native void openAppend(String name) throws FileNotFoundException;
/** {@collect.stats}
* {@description.open}
* Writes the specified byte to this file output stream. Implements
* the <code>write</code> method of <code>OutputStream</code>.
* {@description.close}
*
* @param b the byte to be written.
* @exception IOException if an I/O error occurs.
*/
public native void write(int b) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes a sub array as a sequence of bytes.
* {@description.close}
* @param b the data to be written
* @param off the start offset in the data
* @param len the number of bytes that are written
* @exception IOException If an I/O error has occurred.
*/
private native void writeBytes(byte b[], int off, int len) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes <code>b.length</code> bytes from the specified byte array
* to this file output stream.
* {@description.close}
*
* @param b the data.
* @exception IOException if an I/O error occurs.
*/
public void write(byte b[]) throws IOException {
writeBytes(b, 0, b.length);
}
/** {@collect.stats}
* {@description.open}
* Writes <code>len</code> bytes from the specified byte array
* starting at offset <code>off</code> to this file output stream.
* {@description.close}
*
* @param b the data.
* @param off the start offset in the data.
* @param len the number of bytes to write.
* @exception IOException if an I/O error occurs.
*/
public void write(byte b[], int off, int len) throws IOException {
writeBytes(b, off, len);
}
/** {@collect.stats}
* {@description.open}
* Closes this file output stream and releases any system resources
* associated with this stream.
* {@description.close}
* {@property.open runtime formal:java.io.OutputStream_ManipulateAfterClose}
* This file output stream may no longer
* be used for writing bytes.
* {@property.close}
*
* {@description.open}
* <p> If this stream has an associated channel then the channel is closed
* as well.
* {@description.close}
*
* @exception IOException if an I/O error occurs.
*
* @revised 1.4
* @spec JSR-51
*/
public void close() throws IOException {
synchronized (closeLock) {
if (closed) {
return;
}
closed = true;
}
if (channel != null) {
/*
* Decrement FD use count associated with the channel
* The use count is incremented whenever a new channel
* is obtained from this stream.
*/
fd.decrementAndGetUseCount();
channel.close();
}
/*
* Decrement FD use count associated with this stream
*/
int useCount = fd.decrementAndGetUseCount();
/*
* If FileDescriptor is still in use by another stream, the finalizer
* will not close it.
*/
if ((useCount <= 0) || !isRunningFinalize()) {
close0();
}
}
/** {@collect.stats}
* {@description.open}
* Returns the file descriptor associated with this stream.
* {@description.close}
*
* @return the <code>FileDescriptor</code> object that represents
* the connection to the file in the file system being used
* by this <code>FileOutputStream</code> object.
*
* @exception IOException if an I/O error occurs.
* @see java.io.FileDescriptor
*/
public final FileDescriptor getFD() throws IOException {
if (fd != null) return fd;
throw new IOException();
}
/** {@collect.stats}
* {@description.open}
* Returns the unique {@link java.nio.channels.FileChannel FileChannel}
* object associated with this file output stream. </p>
*
* <p> The initial {@link java.nio.channels.FileChannel#position()
* </code>position<code>} of the returned channel will be equal to the
* number of bytes written to the file so far unless this stream is in
* append mode, in which case it will be equal to the size of the file.
* Writing bytes to this stream will increment the channel's position
* accordingly. Changing the channel's position, either explicitly or by
* writing, will change this stream's file position.
* {@description.close}
*
* @return the file channel associated with this file output stream
*
* @since 1.4
* @spec JSR-51
*/
public FileChannel getChannel() {
synchronized (this) {
if (channel == null) {
channel = FileChannelImpl.open(fd, false, true, this, append);
/*
* Increment fd's use count. Invoking the channel's close()
* method will result in decrementing the use count set for
* the channel.
*/
fd.incrementAndGetUseCount();
}
return channel;
}
}
/** {@collect.stats}
* {@description.open}
* Cleans up the connection to the file, and ensures that the
* <code>close</code> method of this file output stream is
* called when there are no more references to this stream.
* {@description.close}
*
* @exception IOException if an I/O error occurs.
* @see java.io.FileInputStream#close()
*/
protected void finalize() throws IOException {
if (fd != null) {
if (fd == fd.out || fd == fd.err) {
flush();
} else {
/*
* Finalizer should not release the FileDescriptor if another
* stream is still using it. If the user directly invokes
* close() then the FileDescriptor is also released.
*/
runningFinalize.set(Boolean.TRUE);
try {
close();
} finally {
runningFinalize.set(Boolean.FALSE);
}
}
}
}
private native void close0() throws IOException;
private static native void initIDs();
static {
initIDs();
}
}
|
Java
|
/*
* Copyright (c) 1994, 2004, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* This abstract class is the superclass of all classes representing
* an output stream of bytes. An output stream accepts output bytes
* and sends them to some sink.
* {@description.close}
* {@property.open enforced}
* <p>
* Applications that need to define a subclass of
* <code>OutputStream</code> must always provide at least a method
* that writes one byte of output.
* {@property.close}
*
* @author Arthur van Hoff
* @see java.io.BufferedOutputStream
* @see java.io.ByteArrayOutputStream
* @see java.io.DataOutputStream
* @see java.io.FilterOutputStream
* @see java.io.InputStream
* @see java.io.OutputStream#write(int)
* @since JDK1.0
*/
public abstract class OutputStream implements Closeable, Flushable {
/** {@collect.stats}
* {@description.open}
* Writes the specified byte to this output stream. The general
* contract for <code>write</code> is that one byte is written
* to the output stream. The byte to be written is the eight
* low-order bits of the argument <code>b</code>. The 24
* high-order bits of <code>b</code> are ignored.
* {@description.close}
* {@property.open enforced}
* <p>
* Subclasses of <code>OutputStream</code> must provide an
* implementation for this method.
* {@property.close}
*
* @param b the <code>byte</code>.
* @exception IOException if an I/O error occurs. In particular,
* an <code>IOException</code> may be thrown if the
* output stream has been closed.
*/
public abstract void write(int b) throws IOException;
/** {@collect.stats}
* {@description.open}
* Writes <code>b.length</code> bytes from the specified byte array
* to this output stream. The general contract for <code>write(b)</code>
* is that it should have exactly the same effect as the call
* <code>write(b, 0, b.length)</code>.
* {@description.close}
*
* @param b the data.
* @exception IOException if an I/O error occurs.
* @see java.io.OutputStream#write(byte[], int, int)
*/
public void write(byte b[]) throws IOException {
write(b, 0, b.length);
}
/** {@collect.stats}
* {@description.open}
* Writes <code>len</code> bytes from the specified byte array
* starting at offset <code>off</code> to this output stream.
* The general contract for <code>write(b, off, len)</code> is that
* some of the bytes in the array <code>b</code> are written to the
* output stream in order; element <code>b[off]</code> is the first
* byte written and <code>b[off+len-1]</code> is the last byte written
* by this operation.
* <p>
* The <code>write</code> method of <code>OutputStream</code> calls
* the write method of one argument on each of the bytes to be
* written out. Subclasses are encouraged to override this method and
* provide a more efficient implementation.
* <p>
* If <code>b</code> is <code>null</code>, a
* <code>NullPointerException</code> is thrown.
* <p>
* If <code>off</code> is negative, or <code>len</code> is negative, or
* <code>off+len</code> is greater than the length of the array
* <code>b</code>, then an <tt>IndexOutOfBoundsException</tt> is thrown.
* {@description.close}
*
* @param b the data.
* @param off the start offset in the data.
* @param len the number of bytes to write.
* @exception IOException if an I/O error occurs. In particular,
* an <code>IOException</code> is thrown if the output
* stream is closed.
*/
public void write(byte b[], int off, int len) throws IOException {
if (b == null) {
throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
for (int i = 0 ; i < len ; i++) {
write(b[off + i]);
}
}
/** {@collect.stats}
* {@description.open}
* Flushes this output stream and forces any buffered output bytes
* to be written out. The general contract of <code>flush</code> is
* that calling it is an indication that, if any bytes previously
* written have been buffered by the implementation of the output
* stream, such bytes should immediately be written to their
* intended destination.
* <p>
* If the intended destination of this stream is an abstraction provided by
* the underlying operating system, for example a file, then flushing the
* stream guarantees only that bytes previously written to the stream are
* passed to the operating system for writing; it does not guarantee that
* they are actually written to a physical device such as a disk drive.
* <p>
* The <code>flush</code> method of <code>OutputStream</code> does nothing.
* {@description.close}
*
* @exception IOException if an I/O error occurs.
*/
public void flush() throws IOException {
}
/** {@collect.stats}
* {@description.open}
* Closes this output stream and releases any system resources
* associated with this stream.
* {@description.close}
* {@property.open runtime formal:java.io.OutputStream_ManipulateAfterClose}
* The general contract of <code>close</code>
* is that it closes the output stream. A closed stream cannot perform
* output operations and cannot be reopened.
* {@property.close}
* {@description.open}
* <p>
* The <code>close</code> method of <code>OutputStream</code> does nothing.
* {@description.close}
*
* @exception IOException if an I/O error occurs.
*/
public void close() throws IOException {
}
}
|
Java
|
/*
* Copyright (c) 1994, 2003, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* The class implements a buffered output stream. By setting up such
* an output stream, an application can write bytes to the underlying
* output stream without necessarily causing a call to the underlying
* system for each byte written.
* {@description.close}
*
* @author Arthur van Hoff
* @since JDK1.0
*/
public
class BufferedOutputStream extends FilterOutputStream {
/** {@collect.stats}
* {@description.open}
* The internal buffer where data is stored.
* {@description.close}
*/
protected byte buf[];
/** {@collect.stats}
* {@description.open}
* The number of valid bytes in the buffer.
* {@description.close}
* {@property.open internal}
* This value is always
* in the range <tt>0</tt> through <tt>buf.length</tt>; elements
* <tt>buf[0]</tt> through <tt>buf[count-1]</tt> contain valid
* byte data.
* {@property.close}
*/
protected int count;
/** {@collect.stats}
* {@description.open}
* Creates a new buffered output stream to write data to the
* specified underlying output stream.
* {@description.close}
*
* @param out the underlying output stream.
*/
public BufferedOutputStream(OutputStream out) {
this(out, 8192);
}
/** {@collect.stats}
* {@description.open}
* Creates a new buffered output stream to write data to the
* specified underlying output stream with the specified buffer
* size.
* {@description.close}
*
* @param out the underlying output stream.
* @param size the buffer size.
* @exception IllegalArgumentException if size <= 0.
*/
public BufferedOutputStream(OutputStream out, int size) {
super(out);
if (size <= 0) {
throw new IllegalArgumentException("Buffer size <= 0");
}
buf = new byte[size];
}
/** {@collect.stats}
* {@description.open}
* Flush the internal buffer
* {@description.close}
*/
private void flushBuffer() throws IOException {
if (count > 0) {
out.write(buf, 0, count);
count = 0;
}
}
/** {@collect.stats}
* {@description.open}
* Writes the specified byte to this buffered output stream.
* {@description.close}
*
* @param b the byte to be written.
* @exception IOException if an I/O error occurs.
*/
public synchronized void write(int b) throws IOException {
if (count >= buf.length) {
flushBuffer();
}
buf[count++] = (byte)b;
}
/** {@collect.stats}
* {@description.open}
* Writes <code>len</code> bytes from the specified byte array
* starting at offset <code>off</code> to this buffered output stream.
*
* <p> Ordinarily this method stores bytes from the given array into this
* stream's buffer, flushing the buffer to the underlying output stream as
* needed. If the requested length is at least as large as this stream's
* buffer, however, then this method will flush the buffer and write the
* bytes directly to the underlying output stream. Thus redundant
* <code>BufferedOutputStream</code>s will not copy data unnecessarily.
* {@description.close}
*
* @param b the data.
* @param off the start offset in the data.
* @param len the number of bytes to write.
* @exception IOException if an I/O error occurs.
*/
public synchronized void write(byte b[], int off, int len) throws IOException {
if (len >= buf.length) {
/* If the request length exceeds the size of the output buffer,
flush the output buffer and then write the data directly.
In this way buffered streams will cascade harmlessly. */
flushBuffer();
out.write(b, off, len);
return;
}
if (len > buf.length - count) {
flushBuffer();
}
System.arraycopy(b, off, buf, count, len);
count += len;
}
/** {@collect.stats}
* {@description.open}
* Flushes this buffered output stream. This forces any buffered
* output bytes to be written out to the underlying output stream.
* {@description.close}
*
* @exception IOException if an I/O error occurs.
* @see java.io.FilterOutputStream#out
*/
public synchronized void flush() throws IOException {
flushBuffer();
out.flush();
}
}
|
Java
|
/*
* Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Base class for character conversion exceptions.
* {@description.close}
*
* @author Asmus Freytag
* @since JDK1.1
*/
public class CharConversionException
extends java.io.IOException
{
/** {@collect.stats}
* {@description.open}
* This provides no detailed message.
* {@description.close}
*/
public CharConversionException() {
}
/** {@collect.stats}
* {@description.open}
* This provides a detailed message.
* {@description.close}
*
* @param s the detailed message associated with the exception.
*/
public CharConversionException(String s) {
super(s);
}
}
|
Java
|
/*
* Copyright (c) 1996, 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* The Character Encoding is not supported.
* {@description.close}
*
* @author Asmus Freytag
* @since JDK1.1
*/
public class UnsupportedEncodingException
extends IOException
{
/** {@collect.stats}
* {@description.open}
* Constructs an UnsupportedEncodingException without a detail message.
* {@description.close}
*/
public UnsupportedEncodingException() {
super();
}
/** {@collect.stats}
* {@description.open}
* Constructs an UnsupportedEncodingException with a detail message.
* {@description.close}
* @param s Describes the reason for the exception.
*/
public UnsupportedEncodingException(String s) {
super(s);
}
}
|
Java
|
/*
* Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* A <code>FilterInputStream</code> contains
* some other input stream, which it uses as
* its basic source of data, possibly transforming
* the data along the way or providing additional
* functionality. The class <code>FilterInputStream</code>
* itself simply overrides all methods of
* <code>InputStream</code> with versions that
* pass all requests to the contained input
* stream. Subclasses of <code>FilterInputStream</code>
* may further override some of these methods
* and may also provide additional methods
* and fields.
* {@description.close}
*
* @author Jonathan Payne
* @since JDK1.0
*/
public
class FilterInputStream extends InputStream {
/** {@collect.stats}
* {@description.open}
* The input stream to be filtered.
* {@description.close}
*/
protected volatile InputStream in;
/** {@collect.stats}
* {@description.open}
* Creates a <code>FilterInputStream</code>
* by assigning the argument <code>in</code>
* to the field <code>this.in</code> so as
* to remember it for later use.
* {@description.close}
*
* @param in the underlying input stream, or <code>null</code> if
* this instance is to be created without an underlying stream.
*/
protected FilterInputStream(InputStream in) {
this.in = in;
}
/** {@collect.stats}
* {@description.open}
* Reads the next byte of data from this input stream. The value
* byte is returned as an <code>int</code> in the range
* <code>0</code> to <code>255</code>. If no byte is available
* because the end of the stream has been reached, the value
* <code>-1</code> is returned.
* {@description.close}
* {@description.open blocking}
* This method blocks until input data
* is available, the end of the stream is detected, or an exception
* is thrown.
* {@description.close}
* {@description.open}
* <p>
* This method
* simply performs <code>in.read()</code> and returns the result.
* {@description.close}
*
* @return the next byte of data, or <code>-1</code> if the end of the
* stream is reached.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public int read() throws IOException {
return in.read();
}
/** {@collect.stats}
* {@description.open}
* Reads up to <code>byte.length</code> bytes of data from this
* input stream into an array of bytes.
* {@description.close}
* {@description.open blocking}
* This method blocks until some
* input is available.
* {@description.close}
* {@description.open}
* <p>
* This method simply performs the call
* <code>read(b, 0, b.length)</code> and returns
* the result. It is important that it does
* <i>not</i> do <code>in.read(b)</code> instead;
* certain subclasses of <code>FilterInputStream</code>
* depend on the implementation strategy actually
* used.
* {@description.close}
*
* @param b the buffer into which the data is read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the stream has been reached.
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#read(byte[], int, int)
*/
public int read(byte b[]) throws IOException {
return read(b, 0, b.length);
}
/** {@collect.stats}
* {@description.open}
* Reads up to <code>len</code> bytes of data from this input stream
* into an array of bytes.
* {@description.close}
* {@description.open blocking}
* If <code>len</code> is not zero, the method
* blocks until some input is available; otherwise, no
* bytes are read and <code>0</code> is returned.
* {@description.close}
* {@description.open}
* <p>
* This method simply performs <code>in.read(b, off, len)</code>
* and returns the result.
* {@description.close}
*
* @param b the buffer into which the data is read.
* @param off the start offset in the destination array <code>b</code>
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end of
* the stream has been reached.
* @exception NullPointerException If <code>b</code> is <code>null</code>.
* @exception IndexOutOfBoundsException If <code>off</code> is negative,
* <code>len</code> is negative, or <code>len</code> is greater than
* <code>b.length - off</code>
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public int read(byte b[], int off, int len) throws IOException {
return in.read(b, off, len);
}
/** {@collect.stats}
* {@inheritDoc}
* {@description.open}
* <p>
* This method simply performs <code>in.skip(n)</code>.
* {@description.close}
*/
public long skip(long n) throws IOException {
return in.skip(n);
}
/** {@collect.stats}
* {@description.open}
* Returns an estimate of the number of bytes that can be read (or
* skipped over) from this input stream without blocking by the next
* caller of a method for this input stream. The next caller might be
* the same thread or another thread. A single read or skip of this
* many bytes will not block, but may read or skip fewer bytes.
* <p>
* This method returns the result of {@link #in in}.available().
* {@description.close}
*
* @return an estimate of the number of bytes that can be read (or skipped
* over) from this input stream without blocking.
* @exception IOException if an I/O error occurs.
*/
public int available() throws IOException {
return in.available();
}
/** {@collect.stats}
* {@description.open}
* Closes this input stream and releases any system resources
* associated with the stream.
* This
* method simply performs <code>in.close()</code>.
* {@description.close}
*
* @exception IOException if an I/O error occurs.
* @see java.io.FilterInputStream#in
*/
public void close() throws IOException {
in.close();
}
/** {@collect.stats}
* {@description.open}
* Marks the current position in this input stream. A subsequent
* call to the <code>reset</code> method repositions this stream at
* the last marked position so that subsequent reads re-read the same bytes.
* <p>
* {@description.close}
* {@property.open runtime formal:java.io.InputStream_ReadAheadLimit}
* The <code>readlimit</code> argument tells this input stream to
* allow that many bytes to be read before the mark position gets
* invalidated.
* {@property.close}
* {@description.open}
* <p>
* This method simply performs <code>in.mark(readlimit)</code>.
* {@description.close}
*
* @param readlimit the maximum limit of bytes that can be read before
* the mark position becomes invalid.
* @see java.io.FilterInputStream#in
* @see java.io.FilterInputStream#reset()
*/
public synchronized void mark(int readlimit) {
in.mark(readlimit);
}
/** {@collect.stats}
* {@description.open}
* Repositions this stream to the position at the time the
* <code>mark</code> method was last called on this input stream.
* <p>
* This method
* simply performs <code>in.reset()</code>.
* <p>
* Stream marks are intended to be used in
* situations where you need to read ahead a little to see what's in
* the stream. Often this is most easily done by invoking some
* general parser. If the stream is of the type handled by the
* parse, it just chugs along happily. If the stream is not of
* that type, the parser should toss an exception when it fails.
* If this happens within readlimit bytes, it allows the outer
* code to reset the stream and try another parser.
* {@description.close}
*
* @exception IOException if the stream has not been marked or if the
* mark has been invalidated.
* @see java.io.FilterInputStream#in
* @see java.io.FilterInputStream#mark(int)
*/
public synchronized void reset() throws IOException {
in.reset();
}
/** {@collect.stats}
* {@description.open}
* Tests if this input stream supports the <code>mark</code>
* and <code>reset</code> methods.
* This method
* simply performs <code>in.markSupported()</code>.
* {@description.close}
*
* @return <code>true</code> if this stream type supports the
* <code>mark</code> and <code>reset</code> method;
* <code>false</code> otherwise.
* @see java.io.FilterInputStream#in
* @see java.io.InputStream#mark(int)
* @see java.io.InputStream#reset()
*/
public boolean markSupported() {
return in.markSupported();
}
}
|
Java
|
/*
* Copyright (c) 1994, 1999, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
* {@description.open}
* Signals that an attempt to open the file denoted by a specified pathname
* has failed.
*
* <p> This exception will be thrown by the {@link FileInputStream}, {@link
* FileOutputStream}, and {@link RandomAccessFile} constructors when a file
* with the specified pathname does not exist. It will also be thrown by these
* constructors if the file does exist but for some reason is inaccessible, for
* example when an attempt is made to open a read-only file for writing.
* {@description.close}
*
* @author unascribed
* @since JDK1.0
*/
public class FileNotFoundException extends IOException {
/** {@collect.stats}
* {@description.open}
* Constructs a <code>FileNotFoundException</code> with
* <code>null</code> as its error detail message.
* {@description.close}
*/
public FileNotFoundException() {
super();
}
/** {@collect.stats}
* {@description.open}
* Constructs a <code>FileNotFoundException</code> with the
* specified detail message. The string <code>s</code> can be
* retrieved later by the
* <code>{@link java.lang.Throwable#getMessage}</code>
* method of class <code>java.lang.Throwable</code>.
* {@description.close}
*
* @param s the detail message.
*/
public FileNotFoundException(String s) {
super(s);
}
/** {@collect.stats}
* {@description.open}
* Constructs a <code>FileNotFoundException</code> with a detail message
* consisting of the given pathname string followed by the given reason
* string. If the <code>reason</code> argument is <code>null</code> then
* it will be omitted. This private constructor is invoked only by native
* I/O methods.
* {@description.close}
*
* @since 1.2
*/
private FileNotFoundException(String path, String reason) {
super(path + ((reason == null)
? ""
: " (" + reason + ")"));
}
}
|
Java
|
/*
* Copyright (c) 1995, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.util.Arrays;
/** {@collect.stats}
* {@description.open}
* The <code>StreamTokenizer</code> class takes an input stream and
* parses it into "tokens", allowing the tokens to be
* read one at a time. The parsing process is controlled by a table
* and a number of flags that can be set to various states. The
* stream tokenizer can recognize identifiers, numbers, quoted
* strings, and various comment styles.
* <p>
* Each byte read from the input stream is regarded as a character
* in the range <code>'\u0000'</code> through <code>'\u00FF'</code>.
* The character value is used to look up five possible attributes of
* the character: <i>white space</i>, <i>alphabetic</i>,
* <i>numeric</i>, <i>string quote</i>, and <i>comment character</i>.
* Each character can have zero or more of these attributes.
* <p>
* In addition, an instance has four flags. These flags indicate:
* <ul>
* <li>Whether line terminators are to be returned as tokens or treated
* as white space that merely separates tokens.
* <li>Whether C-style comments are to be recognized and skipped.
* <li>Whether C++-style comments are to be recognized and skipped.
* <li>Whether the characters of identifiers are converted to lowercase.
* </ul>
* <p>
* A typical application first constructs an instance of this class,
* sets up the syntax tables, and then repeatedly loops calling the
* <code>nextToken</code> method in each iteration of the loop until
* it returns the value <code>TT_EOF</code>.
* {@description.close}
*
* @author James Gosling
* @see java.io.StreamTokenizer#nextToken()
* @see java.io.StreamTokenizer#TT_EOF
* @since JDK1.0
*/
public class StreamTokenizer {
/* Only one of these will be non-null */
private Reader reader = null;
private InputStream input = null;
private char buf[] = new char[20];
/** {@collect.stats}
* {@description.open}
* The next character to be considered by the nextToken method. May also
* be NEED_CHAR to indicate that a new character should be read, or SKIP_LF
* to indicate that a new character should be read and, if it is a '\n'
* character, it should be discarded and a second new character should be
* read.
* {@description.close}
*/
private int peekc = NEED_CHAR;
private static final int NEED_CHAR = Integer.MAX_VALUE;
private static final int SKIP_LF = Integer.MAX_VALUE - 1;
private boolean pushedBack;
private boolean forceLower;
/** {@collect.stats}
* {@description.open}
* The line number of the last token read
* {@description.close}
*/
private int LINENO = 1;
private boolean eolIsSignificantP = false;
private boolean slashSlashCommentsP = false;
private boolean slashStarCommentsP = false;
private byte ctype[] = new byte[256];
private static final byte CT_WHITESPACE = 1;
private static final byte CT_DIGIT = 2;
private static final byte CT_ALPHA = 4;
private static final byte CT_QUOTE = 8;
private static final byte CT_COMMENT = 16;
/** {@collect.stats}
* {@description.open}
* After a call to the <code>nextToken</code> method, this field
* contains the type of the token just read. For a single character
* token, its value is the single character, converted to an integer.
* For a quoted string token, its value is the quote character.
* Otherwise, its value is one of the following:
* <ul>
* <li><code>TT_WORD</code> indicates that the token is a word.
* <li><code>TT_NUMBER</code> indicates that the token is a number.
* <li><code>TT_EOL</code> indicates that the end of line has been read.
* The field can only have this value if the
* <code>eolIsSignificant</code> method has been called with the
* argument <code>true</code>.
* <li><code>TT_EOF</code> indicates that the end of the input stream
* has been reached.
* </ul>
* <p>
* The initial value of this field is -4.
* {@description.close}
*
* @see java.io.StreamTokenizer#eolIsSignificant(boolean)
* @see java.io.StreamTokenizer#nextToken()
* @see java.io.StreamTokenizer#quoteChar(int)
* @see java.io.StreamTokenizer#TT_EOF
* @see java.io.StreamTokenizer#TT_EOL
* @see java.io.StreamTokenizer#TT_NUMBER
* @see java.io.StreamTokenizer#TT_WORD
*/
public int ttype = TT_NOTHING;
/** {@collect.stats}
* {@description.open}
* A constant indicating that the end of the stream has been read.
* {@description.close}
*/
public static final int TT_EOF = -1;
/** {@collect.stats}
* {@description.open}
* A constant indicating that the end of the line has been read.
* {@description.close}
*/
public static final int TT_EOL = '\n';
/** {@collect.stats}
* {@description.open}
* A constant indicating that a number token has been read.
* {@description.close}
*/
public static final int TT_NUMBER = -2;
/** {@collect.stats}
* {@description.open}
* A constant indicating that a word token has been read.
* {@description.close}
*/
public static final int TT_WORD = -3;
/* A constant indicating that no token has been read, used for
* initializing ttype. FIXME This could be made public and
* made available as the part of the API in a future release.
*/
private static final int TT_NOTHING = -4;
/** {@collect.stats}
* {@property.open runtime formal:java.io.StreamTokenizer_AccessInvalidField}
* If the current token is a word token, this field contains a
* string giving the characters of the word token. When the current
* token is a quoted string token, this field contains the body of
* the string.
* {@property.close}
* {@description.open}
* <p>
* The current token is a word when the value of the
* <code>ttype</code> field is <code>TT_WORD</code>. The current token is
* a quoted string token when the value of the <code>ttype</code> field is
* a quote character.
* <p>
* The initial value of this field is null.
* {@description.close}
*
* @see java.io.StreamTokenizer#quoteChar(int)
* @see java.io.StreamTokenizer#TT_WORD
* @see java.io.StreamTokenizer#ttype
*/
public String sval;
/** {@collect.stats}
* {@property.open runtime formal:java.io.StreamTokenizer_AccessInvalidField}
* If the current token is a number, this field contains the value
* of that number. The current token is a number when the value of
* the <code>ttype</code> field is <code>TT_NUMBER</code>.
* {@property.close}
* {@description.open}
* <p>
* The initial value of this field is 0.0.
* {@description.close}
*
* @see java.io.StreamTokenizer#TT_NUMBER
* @see java.io.StreamTokenizer#ttype
*/
public double nval;
/** {@collect.stats}
* {@description.open}
* Private constructor that initializes everything except the streams.
* {@description.close}
*/
private StreamTokenizer() {
wordChars('a', 'z');
wordChars('A', 'Z');
wordChars(128 + 32, 255);
whitespaceChars(0, ' ');
commentChar('/');
quoteChar('"');
quoteChar('\'');
parseNumbers();
}
/** {@collect.stats}
* {@description.open}
* Creates a stream tokenizer that parses the specified input
* stream. The stream tokenizer is initialized to the following
* default state:
* <ul>
* <li>All byte values <code>'A'</code> through <code>'Z'</code>,
* <code>'a'</code> through <code>'z'</code>, and
* <code>'\u00A0'</code> through <code>'\u00FF'</code> are
* considered to be alphabetic.
* <li>All byte values <code>'\u0000'</code> through
* <code>'\u0020'</code> are considered to be white space.
* <li><code>'/'</code> is a comment character.
* <li>Single quote <code>'\''</code> and double quote <code>'"'</code>
* are string quote characters.
* <li>Numbers are parsed.
* <li>Ends of lines are treated as white space, not as separate tokens.
* <li>C-style and C++-style comments are not recognized.
* </ul>
* {@description.close}
*
* @deprecated As of JDK version 1.1, the preferred way to tokenize an
* input stream is to convert it into a character stream, for example:
* <blockquote><pre>
* Reader r = new BufferedReader(new InputStreamReader(is));
* StreamTokenizer st = new StreamTokenizer(r);
* </pre></blockquote>
*
* @param is an input stream.
* @see java.io.BufferedReader
* @see java.io.InputStreamReader
* @see java.io.StreamTokenizer#StreamTokenizer(java.io.Reader)
*/
@Deprecated
public StreamTokenizer(InputStream is) {
this();
if (is == null) {
throw new NullPointerException();
}
input = is;
}
/** {@collect.stats}
* {@description.open}
* Create a tokenizer that parses the given character stream.
* {@description.close}
*
* @param r a Reader object providing the input stream.
* @since JDK1.1
*/
public StreamTokenizer(Reader r) {
this();
if (r == null) {
throw new NullPointerException();
}
reader = r;
}
/** {@collect.stats}
* {@description.open}
* Resets this tokenizer's syntax table so that all characters are
* "ordinary." See the <code>ordinaryChar</code> method
* for more information on a character being ordinary.
* {@description.close}
*
* @see java.io.StreamTokenizer#ordinaryChar(int)
*/
public void resetSyntax() {
for (int i = ctype.length; --i >= 0;)
ctype[i] = 0;
}
/** {@collect.stats}
* {@description.open}
* Specifies that all characters <i>c</i> in the range
* <code>low <= <i>c</i> <= high</code>
* are word constituents. A word token consists of a word constituent
* followed by zero or more word constituents or number constituents.
* {@description.close}
*
* @param low the low end of the range.
* @param hi the high end of the range.
*/
public void wordChars(int low, int hi) {
if (low < 0)
low = 0;
if (hi >= ctype.length)
hi = ctype.length - 1;
while (low <= hi)
ctype[low++] |= CT_ALPHA;
}
/** {@collect.stats}
* {@description.open}
* Specifies that all characters <i>c</i> in the range
* <code>low <= <i>c</i> <= high</code>
* are white space characters. White space characters serve only to
* separate tokens in the input stream.
*
* <p>Any other attribute settings for the characters in the specified
* range are cleared.
* {@description.close}
*
* @param low the low end of the range.
* @param hi the high end of the range.
*/
public void whitespaceChars(int low, int hi) {
if (low < 0)
low = 0;
if (hi >= ctype.length)
hi = ctype.length - 1;
while (low <= hi)
ctype[low++] = CT_WHITESPACE;
}
/** {@collect.stats}
* {@description.open}
* Specifies that all characters <i>c</i> in the range
* <code>low <= <i>c</i> <= high</code>
* are "ordinary" in this tokenizer. See the
* <code>ordinaryChar</code> method for more information on a
* character being ordinary.
* {@description.close}
*
* @param low the low end of the range.
* @param hi the high end of the range.
* @see java.io.StreamTokenizer#ordinaryChar(int)
*/
public void ordinaryChars(int low, int hi) {
if (low < 0)
low = 0;
if (hi >= ctype.length)
hi = ctype.length - 1;
while (low <= hi)
ctype[low++] = 0;
}
/** {@collect.stats}
* {@description.open}
* Specifies that the character argument is "ordinary"
* in this tokenizer. It removes any special significance the
* character has as a comment character, word component, string
* delimiter, white space, or number character. When such a character
* is encountered by the parser, the parser treats it as a
* single-character token and sets <code>ttype</code> field to the
* character value.
*
* <p>Making a line terminator character "ordinary" may interfere
* with the ability of a <code>StreamTokenizer</code> to count
* lines. The <code>lineno</code> method may no longer reflect
* the presence of such terminator characters in its line count.
* {@description.close}
*
* @param ch the character.
* @see java.io.StreamTokenizer#ttype
*/
public void ordinaryChar(int ch) {
if (ch >= 0 && ch < ctype.length)
ctype[ch] = 0;
}
/** {@collect.stats}
* {@description.open}
* Specified that the character argument starts a single-line
* comment. All characters from the comment character to the end of
* the line are ignored by this stream tokenizer.
*
* <p>Any other attribute settings for the specified character are cleared.
* {@description.close}
*
* @param ch the character.
*/
public void commentChar(int ch) {
if (ch >= 0 && ch < ctype.length)
ctype[ch] = CT_COMMENT;
}
/** {@collect.stats}
* {@description.open}
* Specifies that matching pairs of this character delimit string
* constants in this tokenizer.
* <p>
* When the <code>nextToken</code> method encounters a string
* constant, the <code>ttype</code> field is set to the string
* delimiter and the <code>sval</code> field is set to the body of
* the string.
* <p>
* If a string quote character is encountered, then a string is
* recognized, consisting of all characters after (but not including)
* the string quote character, up to (but not including) the next
* occurrence of that same string quote character, or a line
* terminator, or end of file. The usual escape sequences such as
* <code>"\n"</code> and <code>"\t"</code> are recognized and
* converted to single characters as the string is parsed.
*
* <p>Any other attribute settings for the specified character are cleared.
* {@description.close}
*
* @param ch the character.
* @see java.io.StreamTokenizer#nextToken()
* @see java.io.StreamTokenizer#sval
* @see java.io.StreamTokenizer#ttype
*/
public void quoteChar(int ch) {
if (ch >= 0 && ch < ctype.length)
ctype[ch] = CT_QUOTE;
}
/** {@collect.stats}
* {@description.open}
* Specifies that numbers should be parsed by this tokenizer. The
* syntax table of this tokenizer is modified so that each of the twelve
* characters:
* <blockquote><pre>
* 0 1 2 3 4 5 6 7 8 9 . -
* </pre></blockquote>
* <p>
* has the "numeric" attribute.
* <p>
* When the parser encounters a word token that has the format of a
* double precision floating-point number, it treats the token as a
* number rather than a word, by setting the <code>ttype</code>
* field to the value <code>TT_NUMBER</code> and putting the numeric
* value of the token into the <code>nval</code> field.
* {@description.close}
*
* @see java.io.StreamTokenizer#nval
* @see java.io.StreamTokenizer#TT_NUMBER
* @see java.io.StreamTokenizer#ttype
*/
public void parseNumbers() {
for (int i = '0'; i <= '9'; i++)
ctype[i] |= CT_DIGIT;
ctype['.'] |= CT_DIGIT;
ctype['-'] |= CT_DIGIT;
}
/** {@collect.stats}
* {@description.open}
* Determines whether or not ends of line are treated as tokens.
* If the flag argument is true, this tokenizer treats end of lines
* as tokens; the <code>nextToken</code> method returns
* <code>TT_EOL</code> and also sets the <code>ttype</code> field to
* this value when an end of line is read.
* <p>
* A line is a sequence of characters ending with either a
* carriage-return character (<code>'\r'</code>) or a newline
* character (<code>'\n'</code>). In addition, a carriage-return
* character followed immediately by a newline character is treated
* as a single end-of-line token.
* <p>
* If the <code>flag</code> is false, end-of-line characters are
* treated as white space and serve only to separate tokens.
* {@description.close}
*
* @param flag <code>true</code> indicates that end-of-line characters
* are separate tokens; <code>false</code> indicates that
* end-of-line characters are white space.
* @see java.io.StreamTokenizer#nextToken()
* @see java.io.StreamTokenizer#ttype
* @see java.io.StreamTokenizer#TT_EOL
*/
public void eolIsSignificant(boolean flag) {
eolIsSignificantP = flag;
}
/** {@collect.stats}
* {@description.open}
* Determines whether or not the tokenizer recognizes C-style comments.
* If the flag argument is <code>true</code>, this stream tokenizer
* recognizes C-style comments. All text between successive
* occurrences of <code>/*</code> and <code>*/</code> are discarded.
* <p>
* If the flag argument is <code>false</code>, then C-style comments
* are not treated specially.
* {@description.close}
*
* @param flag <code>true</code> indicates to recognize and ignore
* C-style comments.
*/
public void slashStarComments(boolean flag) {
slashStarCommentsP = flag;
}
/** {@collect.stats}
* {@description.open}
* Determines whether or not the tokenizer recognizes C++-style comments.
* If the flag argument is <code>true</code>, this stream tokenizer
* recognizes C++-style comments. Any occurrence of two consecutive
* slash characters (<code>'/'</code>) is treated as the beginning of
* a comment that extends to the end of the line.
* <p>
* If the flag argument is <code>false</code>, then C++-style
* comments are not treated specially.
* {@description.close}
*
* @param flag <code>true</code> indicates to recognize and ignore
* C++-style comments.
*/
public void slashSlashComments(boolean flag) {
slashSlashCommentsP = flag;
}
/** {@collect.stats}
* {@description.open}
* Determines whether or not word token are automatically lowercased.
* If the flag argument is <code>true</code>, then the value in the
* <code>sval</code> field is lowercased whenever a word token is
* returned (the <code>ttype</code> field has the
* value <code>TT_WORD</code> by the <code>nextToken</code> method
* of this tokenizer.
* <p>
* If the flag argument is <code>false</code>, then the
* <code>sval</code> field is not modified.
* {@description.close}
*
* @param fl <code>true</code> indicates that all word tokens should
* be lowercased.
* @see java.io.StreamTokenizer#nextToken()
* @see java.io.StreamTokenizer#ttype
* @see java.io.StreamTokenizer#TT_WORD
*/
public void lowerCaseMode(boolean fl) {
forceLower = fl;
}
/** {@collect.stats}
* {@description.open}
* Read the next character
* {@description.close}
*/
private int read() throws IOException {
if (reader != null)
return reader.read();
else if (input != null)
return input.read();
else
throw new IllegalStateException();
}
/** {@collect.stats}
* {@description.open}
* Parses the next token from the input stream of this tokenizer.
* {@description.close}
* {@property.open runtime formal:java.io.StreamTokenizer_AccessInvalidField}
* The type of the next token is returned in the <code>ttype</code>
* field. Additional information about the token may be in the
* <code>nval</code> field or the <code>sval</code> field of this
* tokenizer.
* {@property.close}
* {@description.open}
* <p>
* Typical clients of this
* class first set up the syntax tables and then sit in a loop
* calling nextToken to parse successive tokens until TT_EOF
* is returned.
* {@description.close}
*
* @return the value of the <code>ttype</code> field.
* @exception IOException if an I/O error occurs.
* @see java.io.StreamTokenizer#nval
* @see java.io.StreamTokenizer#sval
* @see java.io.StreamTokenizer#ttype
*/
public int nextToken() throws IOException {
if (pushedBack) {
pushedBack = false;
return ttype;
}
byte ct[] = ctype;
sval = null;
int c = peekc;
if (c < 0)
c = NEED_CHAR;
if (c == SKIP_LF) {
c = read();
if (c < 0)
return ttype = TT_EOF;
if (c == '\n')
c = NEED_CHAR;
}
if (c == NEED_CHAR) {
c = read();
if (c < 0)
return ttype = TT_EOF;
}
ttype = c; /* Just to be safe */
/* Set peekc so that the next invocation of nextToken will read
* another character unless peekc is reset in this invocation
*/
peekc = NEED_CHAR;
int ctype = c < 256 ? ct[c] : CT_ALPHA;
while ((ctype & CT_WHITESPACE) != 0) {
if (c == '\r') {
LINENO++;
if (eolIsSignificantP) {
peekc = SKIP_LF;
return ttype = TT_EOL;
}
c = read();
if (c == '\n')
c = read();
} else {
if (c == '\n') {
LINENO++;
if (eolIsSignificantP) {
return ttype = TT_EOL;
}
}
c = read();
}
if (c < 0)
return ttype = TT_EOF;
ctype = c < 256 ? ct[c] : CT_ALPHA;
}
if ((ctype & CT_DIGIT) != 0) {
boolean neg = false;
if (c == '-') {
c = read();
if (c != '.' && (c < '0' || c > '9')) {
peekc = c;
return ttype = '-';
}
neg = true;
}
double v = 0;
int decexp = 0;
int seendot = 0;
while (true) {
if (c == '.' && seendot == 0)
seendot = 1;
else if ('0' <= c && c <= '9') {
v = v * 10 + (c - '0');
decexp += seendot;
} else
break;
c = read();
}
peekc = c;
if (decexp != 0) {
double denom = 10;
decexp--;
while (decexp > 0) {
denom *= 10;
decexp--;
}
/* Do one division of a likely-to-be-more-accurate number */
v = v / denom;
}
nval = neg ? -v : v;
return ttype = TT_NUMBER;
}
if ((ctype & CT_ALPHA) != 0) {
int i = 0;
do {
if (i >= buf.length) {
buf = Arrays.copyOf(buf, buf.length * 2);
}
buf[i++] = (char) c;
c = read();
ctype = c < 0 ? CT_WHITESPACE : c < 256 ? ct[c] : CT_ALPHA;
} while ((ctype & (CT_ALPHA | CT_DIGIT)) != 0);
peekc = c;
sval = String.copyValueOf(buf, 0, i);
if (forceLower)
sval = sval.toLowerCase();
return ttype = TT_WORD;
}
if ((ctype & CT_QUOTE) != 0) {
ttype = c;
int i = 0;
/* Invariants (because \Octal needs a lookahead):
* (i) c contains char value
* (ii) d contains the lookahead
*/
int d = read();
while (d >= 0 && d != ttype && d != '\n' && d != '\r') {
if (d == '\\') {
c = read();
int first = c; /* To allow \377, but not \477 */
if (c >= '0' && c <= '7') {
c = c - '0';
int c2 = read();
if ('0' <= c2 && c2 <= '7') {
c = (c << 3) + (c2 - '0');
c2 = read();
if ('0' <= c2 && c2 <= '7' && first <= '3') {
c = (c << 3) + (c2 - '0');
d = read();
} else
d = c2;
} else
d = c2;
} else {
switch (c) {
case 'a':
c = 0x7;
break;
case 'b':
c = '\b';
break;
case 'f':
c = 0xC;
break;
case 'n':
c = '\n';
break;
case 'r':
c = '\r';
break;
case 't':
c = '\t';
break;
case 'v':
c = 0xB;
break;
}
d = read();
}
} else {
c = d;
d = read();
}
if (i >= buf.length) {
buf = Arrays.copyOf(buf, buf.length * 2);
}
buf[i++] = (char)c;
}
/* If we broke out of the loop because we found a matching quote
* character then arrange to read a new character next time
* around; otherwise, save the character.
*/
peekc = (d == ttype) ? NEED_CHAR : d;
sval = String.copyValueOf(buf, 0, i);
return ttype;
}
if (c == '/' && (slashSlashCommentsP || slashStarCommentsP)) {
c = read();
if (c == '*' && slashStarCommentsP) {
int prevc = 0;
while ((c = read()) != '/' || prevc != '*') {
if (c == '\r') {
LINENO++;
c = read();
if (c == '\n') {
c = read();
}
} else {
if (c == '\n') {
LINENO++;
c = read();
}
}
if (c < 0)
return ttype = TT_EOF;
prevc = c;
}
return nextToken();
} else if (c == '/' && slashSlashCommentsP) {
while ((c = read()) != '\n' && c != '\r' && c >= 0);
peekc = c;
return nextToken();
} else {
/* Now see if it is still a single line comment */
if ((ct['/'] & CT_COMMENT) != 0) {
while ((c = read()) != '\n' && c != '\r' && c >= 0);
peekc = c;
return nextToken();
} else {
peekc = c;
return ttype = '/';
}
}
}
if ((ctype & CT_COMMENT) != 0) {
while ((c = read()) != '\n' && c != '\r' && c >= 0);
peekc = c;
return nextToken();
}
return ttype = c;
}
/** {@collect.stats}
* {@description.open}
* Causes the next call to the <code>nextToken</code> method of this
* tokenizer to return the current value in the <code>ttype</code>
* field, and not to modify the value in the <code>nval</code> or
* <code>sval</code> field.
* {@description.close}
*
* @see java.io.StreamTokenizer#nextToken()
* @see java.io.StreamTokenizer#nval
* @see java.io.StreamTokenizer#sval
* @see java.io.StreamTokenizer#ttype
*/
public void pushBack() {
if (ttype != TT_NOTHING) /* No-op if nextToken() not called */
pushedBack = true;
}
/** {@collect.stats}
* {@description.open}
* Return the current line number.
* {@description.close}
*
* @return the current line number of this stream tokenizer.
*/
public int lineno() {
return LINENO;
}
/** {@collect.stats}
* {@description.open}
* Returns the string representation of the current stream token and
* the line number it occurs on.
*
* <p>The precise string returned is unspecified, although the following
* example can be considered typical:
*
* <blockquote><pre>Token['a'], line 10</pre></blockquote>
* {@description.close}
*
* @return a string representation of the token
* @see java.io.StreamTokenizer#nval
* @see java.io.StreamTokenizer#sval
* @see java.io.StreamTokenizer#ttype
*/
public String toString() {
String ret;
switch (ttype) {
case TT_EOF:
ret = "EOF";
break;
case TT_EOL:
ret = "EOL";
break;
case TT_WORD:
ret = sval;
break;
case TT_NUMBER:
ret = "n=" + nval;
break;
case TT_NOTHING:
ret = "NOTHING";
break;
default: {
/*
* ttype is the first character of either a quoted string or
* is an ordinary character. ttype can definitely not be less
* than 0, since those are reserved values used in the previous
* case statements
*/
if (ttype < 256 &&
((ctype[ttype] & CT_QUOTE) != 0)) {
ret = sval;
break;
}
char s[] = new char[3];
s[0] = s[2] = '\'';
s[1] = (char) ttype;
ret = new String(s);
break;
}
}
return "Token[" + ret + "], line " + LINENO;
}
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
/** {@collect.stats}
*
* {@description.open}
* Writes text to a character-output stream, buffering characters so as to
* provide for the efficient writing of single characters, arrays, and strings.
*
* <p> The buffer size may be specified, or the default size may be accepted.
* The default is large enough for most purposes.
*
* <p> A newLine() method is provided, which uses the platform's own notion of
* line separator as defined by the system property <tt>line.separator</tt>.
* Not all platforms use the newline character ('\n') to terminate lines.
* Calling this method to terminate each output line is therefore preferred to
* writing a newline character directly.
*
* <p> In general, a Writer sends its output immediately to the underlying
* character or byte stream. Unless prompt output is required, it is advisable
* to wrap a BufferedWriter around any Writer whose write() operations may be
* costly, such as FileWriters and OutputStreamWriters. For example,
*
* <pre>
* PrintWriter out
* = new PrintWriter(new BufferedWriter(new FileWriter("foo.out")));
* </pre>
*
* will buffer the PrintWriter's output to the file. Without buffering, each
* invocation of a print() method would cause characters to be converted into
* bytes that would then be written immediately to the file, which can be very
* inefficient.
* {@description.close}
*
* @see PrintWriter
* @see FileWriter
* @see OutputStreamWriter
*
* @author Mark Reinhold
* @since JDK1.1
*/
public class BufferedWriter extends Writer {
private Writer out;
private char cb[];
private int nChars, nextChar;
private static int defaultCharBufferSize = 8192;
/** {@collect.stats}
* {@description.open}
* Line separator string. This is the value of the line.separator
* property at the moment that the stream was created.
* {@description.close}
*/
private String lineSeparator;
/** {@collect.stats}
* {@description.open}
* Creates a buffered character-output stream that uses a default-sized
* output buffer.
* {@description.close}
*
* @param out A Writer
*/
public BufferedWriter(Writer out) {
this(out, defaultCharBufferSize);
}
/** {@collect.stats}
* {@description.open}
* Creates a new buffered character-output stream that uses an output
* buffer of the given size.
* {@description.close}
*
* @param out A Writer
* @param sz Output-buffer size, a positive integer
*
* @exception IllegalArgumentException If sz is <= 0
*/
public BufferedWriter(Writer out, int sz) {
super(out);
if (sz <= 0)
throw new IllegalArgumentException("Buffer size <= 0");
this.out = out;
cb = new char[sz];
nChars = sz;
nextChar = 0;
lineSeparator = java.security.AccessController.doPrivileged(
new sun.security.action.GetPropertyAction("line.separator"));
}
/** {@collect.stats}
* {@description.open}
* Checks to make sure that the stream has not been closed
* {@description.close}
*/
private void ensureOpen() throws IOException {
if (out == null)
throw new IOException("Stream closed");
}
/** {@collect.stats}
* {@description.open}
* Flushes the output buffer to the underlying character stream, without
* flushing the stream itself. This method is non-private only so that it
* may be invoked by PrintStream.
* {@description.close}
*/
void flushBuffer() throws IOException {
synchronized (lock) {
ensureOpen();
if (nextChar == 0)
return;
out.write(cb, 0, nextChar);
nextChar = 0;
}
}
/** {@collect.stats}
* {@description.open}
* Writes a single character.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public void write(int c) throws IOException {
synchronized (lock) {
ensureOpen();
if (nextChar >= nChars)
flushBuffer();
cb[nextChar++] = (char) c;
}
}
/** {@collect.stats}
* {@description.open}
* Our own little min method, to avoid loading java.lang.Math if we've run
* out of file descriptors and we're trying to print a stack trace.
* {@description.close}
*/
private int min(int a, int b) {
if (a < b) return a;
return b;
}
/** {@collect.stats}
* {@description.open}
* Writes a portion of an array of characters.
*
* <p> Ordinarily this method stores characters from the given array into
* this stream's buffer, flushing the buffer to the underlying stream as
* needed. If the requested length is at least as large as the buffer,
* however, then this method will flush the buffer and write the characters
* directly to the underlying stream. Thus redundant
* <code>BufferedWriter</code>s will not copy data unnecessarily.
* {@description.close}
*
* @param cbuf A character array
* @param off Offset from which to start reading characters
* @param len Number of characters to write
*
* @exception IOException If an I/O error occurs
*/
public void write(char cbuf[], int off, int len) throws IOException {
synchronized (lock) {
ensureOpen();
if ((off < 0) || (off > cbuf.length) || (len < 0) ||
((off + len) > cbuf.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
if (len >= nChars) {
/* If the request length exceeds the size of the output buffer,
flush the buffer and then write the data directly. In this
way buffered streams will cascade harmlessly. */
flushBuffer();
out.write(cbuf, off, len);
return;
}
int b = off, t = off + len;
while (b < t) {
int d = min(nChars - nextChar, t - b);
System.arraycopy(cbuf, b, cb, nextChar, d);
b += d;
nextChar += d;
if (nextChar >= nChars)
flushBuffer();
}
}
}
/** {@collect.stats}
* {@description.open}
* Writes a portion of a String.
*
* <p> If the value of the <tt>len</tt> parameter is negative then no
* characters are written. This is contrary to the specification of this
* method in the {@linkplain java.io.Writer#write(java.lang.String,int,int)
* superclass}, which requires that an {@link IndexOutOfBoundsException} be
* thrown.
* {@description.close}
*
* @param s String to be written
* @param off Offset from which to start reading characters
* @param len Number of characters to be written
*
* @exception IOException If an I/O error occurs
*/
public void write(String s, int off, int len) throws IOException {
synchronized (lock) {
ensureOpen();
int b = off, t = off + len;
while (b < t) {
int d = min(nChars - nextChar, t - b);
s.getChars(b, b + d, cb, nextChar);
b += d;
nextChar += d;
if (nextChar >= nChars)
flushBuffer();
}
}
}
/** {@collect.stats}
* {@description.open}
* Writes a line separator. The line separator string is defined by the
* system property <tt>line.separator</tt>, and is not necessarily a single
* newline ('\n') character.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public void newLine() throws IOException {
write(lineSeparator);
}
/** {@collect.stats}
* {@description.open}
* Flushes the stream.
* {@description.close}
*
* @exception IOException If an I/O error occurs
*/
public void flush() throws IOException {
synchronized (lock) {
flushBuffer();
out.flush();
}
}
public void close() throws IOException {
synchronized (lock) {
if (out == null) {
return;
}
try {
flushBuffer();
} finally {
out.close();
out = null;
cb = null;
}
}
}
}
|
Java
|
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.util.*;
import java.nio.charset.Charset;
import sun.nio.cs.StreamDecoder;
import sun.nio.cs.StreamEncoder;
/** {@collect.stats}
*
* {@description.open}
* Methods to access the character-based console device, if any, associated
* with the current Java virtual machine.
*
* <p> Whether a virtual machine has a console is dependent upon the
* underlying platform and also upon the manner in which the virtual
* machine is invoked. If the virtual machine is started from an
* interactive command line without redirecting the standard input and
* output streams then its console will exist and will typically be
* connected to the keyboard and display from which the virtual machine
* was launched. If the virtual machine is started automatically, for
* example by a background job scheduler, then it will typically not
* have a console.
* {@description.close}
* {@property.open}
* <p>
* If this virtual machine has a console then it is represented by a
* unique instance of this class which can be obtained by invoking the
* {@link java.lang.System#console()} method. If no console device is
* available then an invocation of that method will return <tt>null</tt>.
* {@property.close}
* {@description.open blocking}
* <p>
* Read and write operations are synchronized to guarantee the atomic
* completion of critical operations; therefore invoking methods
* {@link #readLine()}, {@link #readPassword()}, {@link #format format()},
* {@link #printf printf()} as well as the read, format and write operations
* on the objects returned by {@link #reader()} and {@link #writer()} may
* block in multithreaded scenarios.
* {@description.close}
* {@property.open runtime formal:java.io.Console_CloseReader formal:java.io.Console_CloseWriter}
* <p>
* Invoking <tt>close()</tt> on the objects returned by the {@link #reader()}
* and the {@link #writer()} will not close the underlying stream of those
* objects.
* {@property.close}
* {@description.open}
* <p>
* The console-read methods return <tt>null</tt> when the end of the
* console input stream is reached, for example by typing control-D on
* Unix or control-Z on Windows. Subsequent read operations will succeed
* if additional characters are later entered on the console's input
* device.
* <p>
* Unless otherwise specified, passing a <tt>null</tt> argument to any method
* in this class will cause a {@link NullPointerException} to be thrown.
* {@description.close}
* {@property.open}
* <p>
* <b>Security note:</b>
* If an application needs to read a password or other secure data, it should
* use {@link #readPassword()} or {@link #readPassword(String, Object...)}
* {@property.close}
* {@property.open runtime formal:java.io.Console_FillZeroPassword}
* and
* manually zero the returned character array after processing to minimize the
* lifetime of sensitive data in memory.
*
* <blockquote><pre>
* Console cons;
* char[] passwd;
* if ((cons = System.console()) != null &&
* (passwd = cons.readPassword("[%s]", "Password:")) != null) {
* ...
* java.util.Arrays.fill(passwd, ' ');
* }
* </pre></blockquote>
* {@property.close}
*
* @author Xueming Shen
* @since 1.6
*/
public final class Console implements Flushable
{
/** {@collect.stats}
* {@description.open}
* Retrieves the unique {@link java.io.PrintWriter PrintWriter} object
* associated with this console.
* {@description.close}
*
* @return The printwriter associated with this console
*/
public PrintWriter writer() {
return pw;
}
/** {@collect.stats}
* {@description.open}
* Retrieves the unique {@link java.io.Reader Reader} object associated
* with this console.
* <p>
* This method is intended to be used by sophisticated applications, for
* example, a {@link java.util.Scanner} object which utilizes the rich
* parsing/scanning functionality provided by the <tt>Scanner</tt>:
* <blockquote><pre>
* Console con = System.console();
* if (con != null) {
* Scanner sc = new Scanner(con.reader());
* ...
* }
* </pre></blockquote>
* <p>
* For simple applications requiring only line-oriented reading, use
* <tt>{@link #readLine}</tt>.
* {@description.close}
* {@property.open}
* <p>
* The bulk read operations {@link java.io.Reader#read(char[]) read(char[]) },
* {@link java.io.Reader#read(char[], int, int) read(char[], int, int) } and
* {@link java.io.Reader#read(java.nio.CharBuffer) read(java.nio.CharBuffer)}
* on the returned object will not read in characters beyond the line
* bound for each invocation, even if the destination buffer has space for
* more characters. A line bound is considered to be any one of a line feed
* (<tt>'\n'</tt>), a carriage return (<tt>'\r'</tt>), a carriage return
* followed immediately by a linefeed, or an end of stream.
* {@property.close}
*
* @return The reader associated with this console
*/
public Reader reader() {
return reader;
}
/** {@collect.stats}
* {@description.open}
* Writes a formatted string to this console's output stream using
* the specified format string and arguments.
* {@description.close}
*
* @param fmt
* A format string as described in <a
* href="../util/Formatter.html#syntax">Format string syntax</a>
*
* @param args
* Arguments referenced by the format specifiers in the format
* string. If there are more arguments than format specifiers, the
* extra arguments are ignored. The number of arguments is
* variable and may be zero. The maximum number of arguments is
* limited by the maximum dimension of a Java array as defined by
* the <a href="http://java.sun.com/docs/books/vmspec/">Java
* Virtual Machine Specification</a>. The behaviour on a
* <tt>null</tt> argument depends on the <a
* href="../util/Formatter.html#syntax">conversion</a>.
*
* @throws IllegalFormatException
* If a format string contains an illegal syntax, a format
* specifier that is incompatible with the given arguments,
* insufficient arguments given the format string, or other
* illegal conditions. For specification of all possible
* formatting errors, see the <a
* href="../util/Formatter.html#detail">Details</a> section
* of the formatter class specification.
*
* @return This console
*/
public Console format(String fmt, Object ...args) {
formatter.format(fmt, args).flush();
return this;
}
/** {@collect.stats}
* {@description.open}
* A convenience method to write a formatted string to this console's
* output stream using the specified format string and arguments.
*
* <p> An invocation of this method of the form <tt>con.printf(format,
* args)</tt> behaves in exactly the same way as the invocation of
* <pre>con.format(format, args)</pre>.
* {@description.close}
*
* @param format
* A format string as described in <a
* href="../util/Formatter.html#syntax">Format string syntax</a>.
*
* @param args
* Arguments referenced by the format specifiers in the format
* string. If there are more arguments than format specifiers, the
* extra arguments are ignored. The number of arguments is
* variable and may be zero. The maximum number of arguments is
* limited by the maximum dimension of a Java array as defined by
* the <a href="http://java.sun.com/docs/books/vmspec/">Java
* Virtual Machine Specification</a>. The behaviour on a
* <tt>null</tt> argument depends on the <a
* href="../util/Formatter.html#syntax">conversion</a>.
*
* @throws IllegalFormatException
* If a format string contains an illegal syntax, a format
* specifier that is incompatible with the given arguments,
* insufficient arguments given the format string, or other
* illegal conditions. For specification of all possible
* formatting errors, see the <a
* href="../util/Formatter.html#detail">Details</a> section of the
* formatter class specification.
*
* @return This console
*/
public Console printf(String format, Object ... args) {
return format(format, args);
}
/** {@collect.stats}
* {@description.open}
* Provides a formatted prompt, then reads a single line of text from the
* console.
* {@description.close}
*
* @param fmt
* A format string as described in <a
* href="../util/Formatter.html#syntax">Format string syntax</a>.
*
* @param args
* Arguments referenced by the format specifiers in the format
* string. If there are more arguments than format specifiers, the
* extra arguments are ignored. The maximum number of arguments is
* limited by the maximum dimension of a Java array as defined by
* the <a href="http://java.sun.com/docs/books/vmspec/">Java
* Virtual Machine Specification</a>.
*
* @throws IllegalFormatException
* If a format string contains an illegal syntax, a format
* specifier that is incompatible with the given arguments,
* insufficient arguments given the format string, or other
* illegal conditions. For specification of all possible
* formatting errors, see the <a
* href="../util/Formatter.html#detail">Details</a> section
* of the formatter class specification.
*
* @throws IOError
* If an I/O error occurs.
*
* @return A string containing the line read from the console, not
* including any line-termination characters, or <tt>null</tt>
* if an end of stream has been reached.
*/
public String readLine(String fmt, Object ... args) {
String line = null;
synchronized (writeLock) {
synchronized(readLock) {
if (fmt.length() != 0)
pw.format(fmt, args);
try {
char[] ca = readline(false);
if (ca != null)
line = new String(ca);
} catch (IOException x) {
throw new IOError(x);
}
}
}
return line;
}
/** {@collect.stats}
* {@description.open}
* Reads a single line of text from the console.
* {@description.close}
*
* @throws IOError
* If an I/O error occurs.
*
* @return A string containing the line read from the console, not
* including any line-termination characters, or <tt>null</tt>
* if an end of stream has been reached.
*/
public String readLine() {
return readLine("");
}
/** {@collect.stats}
* {@description.open}
* Provides a formatted prompt, then reads a password or passphrase from
* the console with echoing disabled.
* {@description.close}
*
* @param fmt
* A format string as described in <a
* href="../util/Formatter.html#syntax">Format string syntax</a>
* for the prompt text.
*
* @param args
* Arguments referenced by the format specifiers in the format
* string. If there are more arguments than format specifiers, the
* extra arguments are ignored. The maximum number of arguments is
* limited by the maximum dimension of a Java array as defined by
* the <a href="http://java.sun.com/docs/books/vmspec/">Java
* Virtual Machine Specification</a>.
*
* @throws IllegalFormatException
* If a format string contains an illegal syntax, a format
* specifier that is incompatible with the given arguments,
* insufficient arguments given the format string, or other
* illegal conditions. For specification of all possible
* formatting errors, see the <a
* href="../util/Formatter.html#detail">Details</a>
* section of the formatter class specification.
*
* @throws IOError
* If an I/O error occurs.
*
* @return A character array containing the password or passphrase read
* from the console, not including any line-termination characters,
* or <tt>null</tt> if an end of stream has been reached.
*/
public char[] readPassword(String fmt, Object ... args) {
char[] passwd = null;
synchronized (writeLock) {
synchronized(readLock) {
if (fmt.length() != 0)
pw.format(fmt, args);
try {
echoOff = echo(false);
passwd = readline(true);
} catch (IOException x) {
throw new IOError(x);
} finally {
try {
echoOff = echo(true);
} catch (IOException xx) {}
}
pw.println();
}
}
return passwd;
}
/** {@collect.stats}
* {@description.open}
* Reads a password or passphrase from the console with echoing disabled
* {@description.close}
*
* @throws IOError
* If an I/O error occurs.
*
* @return A character array containing the password or passphrase read
* from the console, not including any line-termination characters,
* or <tt>null</tt> if an end of stream has been reached.
*/
public char[] readPassword() {
return readPassword("");
}
/** {@collect.stats}
* {@description.open}
* Flushes the console and forces any buffered output to be written
* immediately .
* {@description.close}
*/
public void flush() {
pw.flush();
}
private Object readLock;
private Object writeLock;
private Reader reader;
private Writer out;
private PrintWriter pw;
private Formatter formatter;
private Charset cs;
private char[] rcb;
private static native String encoding();
private static native boolean echo(boolean on) throws IOException;
private static boolean echoOff;
private char[] readline(boolean zeroOut) throws IOException {
int len = reader.read(rcb, 0, rcb.length);
if (len < 0)
return null; //EOL
if (rcb[len-1] == '\r')
len--; //remove CR at end;
else if (rcb[len-1] == '\n') {
len--; //remove LF at end;
if (len > 0 && rcb[len-1] == '\r')
len--; //remove the CR, if there is one
}
char[] b = new char[len];
if (len > 0) {
System.arraycopy(rcb, 0, b, 0, len);
if (zeroOut) {
Arrays.fill(rcb, 0, len, ' ');
}
}
return b;
}
private char[] grow() {
assert Thread.holdsLock(readLock);
char[] t = new char[rcb.length * 2];
System.arraycopy(rcb, 0, t, 0, rcb.length);
rcb = t;
return rcb;
}
class LineReader extends Reader {
private Reader in;
private char[] cb;
private int nChars, nextChar;
boolean leftoverLF;
LineReader(Reader in) {
this.in = in;
cb = new char[1024];
nextChar = nChars = 0;
leftoverLF = false;
}
public void close () {}
public boolean ready() throws IOException {
//in.ready synchronizes on readLock already
return in.ready();
}
public int read(char cbuf[], int offset, int length)
throws IOException
{
int off = offset;
int end = offset + length;
if (offset < 0 || offset > cbuf.length || length < 0 ||
end < 0 || end > cbuf.length) {
throw new IndexOutOfBoundsException();
}
synchronized(readLock) {
boolean eof = false;
char c = 0;
for (;;) {
if (nextChar >= nChars) { //fill
int n = 0;
do {
n = in.read(cb, 0, cb.length);
} while (n == 0);
if (n > 0) {
nChars = n;
nextChar = 0;
if (n < cb.length &&
cb[n-1] != '\n' && cb[n-1] != '\r') {
/*
* we're in canonical mode so each "fill" should
* come back with an eol. if there no lf or nl at
* the end of returned bytes we reached an eof.
*/
eof = true;
}
} else { /*EOF*/
if (off - offset == 0)
return -1;
return off - offset;
}
}
if (leftoverLF && cbuf == rcb && cb[nextChar] == '\n') {
/*
* if invoked by our readline, skip the leftover, otherwise
* return the LF.
*/
nextChar++;
}
leftoverLF = false;
while (nextChar < nChars) {
c = cbuf[off++] = cb[nextChar];
cb[nextChar++] = 0;
if (c == '\n') {
return off - offset;
} else if (c == '\r') {
if (off == end) {
/* no space left even the next is LF, so return
* whatever we have if the invoker is not our
* readLine()
*/
if (cbuf == rcb) {
cbuf = grow();
end = cbuf.length;
} else {
leftoverLF = true;
return off - offset;
}
}
if (nextChar == nChars && in.ready()) {
/*
* we have a CR and we reached the end of
* the read in buffer, fill to make sure we
* don't miss a LF, if there is one, it's possible
* that it got cut off during last round reading
* simply because the read in buffer was full.
*/
nChars = in.read(cb, 0, cb.length);
nextChar = 0;
}
if (nextChar < nChars && cb[nextChar] == '\n') {
cbuf[off++] = '\n';
nextChar++;
}
return off - offset;
} else if (off == end) {
if (cbuf == rcb) {
cbuf = grow();
end = cbuf.length;
} else {
return off - offset;
}
}
}
if (eof)
return off - offset;
}
}
}
}
// Set up JavaIOAccess in SharedSecrets
static {
sun.misc.SharedSecrets.setJavaIOAccess(new sun.misc.JavaIOAccess() {
public Console console() {
if (istty()) {
if (cons == null)
cons = new Console();
return cons;
}
return null;
}
// Add a shutdown hook to restore console's echo state should
// it be necessary.
public Runnable consoleRestoreHook() {
return new Runnable() {
public void run() {
try {
if (echoOff) {
echo(true);
}
} catch (IOException x) {}
}
};
}
public Charset charset() {
// This method is called in sun.security.util.Password,
// cons already exists when this method is called
return cons.cs;
}
});
}
private static Console cons;
private native static boolean istty();
private Console() {
readLock = new Object();
writeLock = new Object();
String csname = encoding();
if (csname != null) {
try {
cs = Charset.forName(csname);
} catch (Exception x) {}
}
if (cs == null)
cs = Charset.defaultCharset();
out = StreamEncoder.forOutputStreamWriter(
new FileOutputStream(FileDescriptor.out),
writeLock,
cs);
pw = new PrintWriter(out, true) { public void close() {} };
formatter = new Formatter(out);
reader = new LineReader(StreamDecoder.forInputStreamReader(
new FileInputStream(FileDescriptor.in),
readLock,
cs));
rcb = new char[1024];
}
}
|
Java
|
/*
* Copyright (c) 1994, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.io;
import java.util.Arrays;
/** {@collect.stats}
* {@description.open}
* This class implements an output stream in which the data is
* written into a byte array. The buffer automatically grows as data
* is written to it.
* The data can be retrieved using <code>toByteArray()</code> and
* <code>toString()</code>.
* {@description.close}
* {@property.open runtime formal:java.io.Closeable_MeaninglessClose}
* <p>
* Closing a <tt>ByteArrayOutputStream</tt> has no effect. The methods in
* this class can be called after the stream has been closed without
* generating an <tt>IOException</tt>.
* {@property.close}
*
* @author Arthur van Hoff
* @since JDK1.0
*/
public class ByteArrayOutputStream extends OutputStream {
/** {@collect.stats}
* {@description.open}
* The buffer where data is stored.
* {@description.close}
*/
protected byte buf[];
/** {@collect.stats}
* {@description.open}
* The number of valid bytes in the buffer.
* {@description.close}
*/
protected int count;
/** {@collect.stats}
* {@description.open}
* Creates a new byte array output stream. The buffer capacity is
* initially 32 bytes, though its size increases if necessary.
* {@description.close}
*/
public ByteArrayOutputStream() {
this(32);
}
/** {@collect.stats}
* {@description.open}
* Creates a new byte array output stream, with a buffer capacity of
* the specified size, in bytes.
* {@description.close}
*
* @param size the initial size.
* @exception IllegalArgumentException if size is negative.
*/
public ByteArrayOutputStream(int size) {
if (size < 0) {
throw new IllegalArgumentException("Negative initial size: "
+ size);
}
buf = new byte[size];
}
/** {@collect.stats}
* {@description.open}
* Writes the specified byte to this byte array output stream.
* {@description.close}
*
* @param b the byte to be written.
*/
public synchronized void write(int b) {
int newcount = count + 1;
if (newcount > buf.length) {
buf = Arrays.copyOf(buf, Math.max(buf.length << 1, newcount));
}
buf[count] = (byte)b;
count = newcount;
}
/** {@collect.stats}
* {@description.open}
* Writes <code>len</code> bytes from the specified byte array
* starting at offset <code>off</code> to this byte array output stream.
* {@description.close}
*
* @param b the data.
* @param off the start offset in the data.
* @param len the number of bytes to write.
*/
public synchronized void write(byte b[], int off, int len) {
if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
int newcount = count + len;
if (newcount > buf.length) {
buf = Arrays.copyOf(buf, Math.max(buf.length << 1, newcount));
}
System.arraycopy(b, off, buf, count, len);
count = newcount;
}
/** {@collect.stats}
* {@description.open}
* Writes the complete contents of this byte array output stream to
* the specified output stream argument, as if by calling the output
* stream's write method using <code>out.write(buf, 0, count)</code>.
* {@description.close}
*
* {@property.open runtime formal:java.io.ByteArrayOutputStream_FlushBeforeRetrieve}
* When an OutputStream (or its subclass) instance is built on top of an
* underlying ByteArrayOutputStream instance, it should be flushed or closed
* before the contents of the ByteArrayOutputStream instance is retrieved.
* {@property.close}
*
* @param out the output stream to which to write the data.
* @exception IOException if an I/O error occurs.
*/
public synchronized void writeTo(OutputStream out) throws IOException {
out.write(buf, 0, count);
}
/** {@collect.stats}
* {@description.open}
* Resets the <code>count</code> field of this byte array output
* stream to zero, so that all currently accumulated output in the
* output stream is discarded. The output stream can be used again,
* reusing the already allocated buffer space.
* {@description.close}
*
* @see java.io.ByteArrayInputStream#count
*/
public synchronized void reset() {
count = 0;
}
/** {@collect.stats}
* {@description.open}
* Creates a newly allocated byte array. Its size is the current
* size of this output stream and the valid contents of the buffer
* have been copied into it.
* {@description.close}
*
* {@property.open runtime formal:java.io.ByteArrayOutputStream_FlushBeforeRetrieve}
* {@property.close}
*
* @return the current contents of this output stream, as a byte array.
* @see java.io.ByteArrayOutputStream#size()
*/
public synchronized byte toByteArray()[] {
return Arrays.copyOf(buf, count);
}
/** {@collect.stats}
* {@description.open}
* Returns the current size of the buffer.
* {@description.close}
*
* @return the value of the <code>count</code> field, which is the number
* of valid bytes in this output stream.
* @see java.io.ByteArrayOutputStream#count
*/
public synchronized int size() {
return count;
}
/** {@collect.stats}
* {@description.open}
* Converts the buffer's contents into a string decoding bytes using the
* platform's default character set. The length of the new <tt>String</tt>
* is a function of the character set, and hence may not be equal to the
* size of the buffer.
*
* <p> This method always replaces malformed-input and unmappable-character
* sequences with the default replacement string for the platform's
* default character set. The {@linkplain java.nio.charset.CharsetDecoder}
* class should be used when more control over the decoding process is
* required.
* {@description.close}
*
* {@property.open runtime formal:java.io.ByteArrayOutputStream_FlushBeforeRetrieve}
* {@property.close}
*
* @return String decoded from the buffer's contents.
* @since JDK1.1
*/
public synchronized String toString() {
return new String(buf, 0, count);
}
/** {@collect.stats}
* {@description.open}
* Converts the buffer's contents into a string by decoding the bytes using
* the specified {@link java.nio.charset.Charset charsetName}. The length of
* the new <tt>String</tt> is a function of the charset, and hence may not be
* equal to the length of the byte array.
*
* <p> This method always replaces malformed-input and unmappable-character
* sequences with this charset's default replacement string. The {@link
* java.nio.charset.CharsetDecoder} class should be used when more control
* over the decoding process is required.
* {@description.close}
*
* {@property.open runtime formal:java.io.ByteArrayOutputStream_FlushBeforeRetrieve}
* {@property.close}
*
* @param charsetName the name of a supported
* {@linkplain java.nio.charset.Charset </code>charset<code>}
* @return String decoded from the buffer's contents.
* @exception UnsupportedEncodingException
* If the named charset is not supported
* @since JDK1.1
*/
public synchronized String toString(String charsetName)
throws UnsupportedEncodingException
{
return new String(buf, 0, count, charsetName);
}
/** {@collect.stats}
* {@description.open}
* Creates a newly allocated string. Its size is the current size of
* the output stream and the valid contents of the buffer have been
* copied into it. Each character <i>c</i> in the resulting string is
* constructed from the corresponding element <i>b</i> in the byte
* array such that:
* <blockquote><pre>
* c == (char)(((hibyte & 0xff) << 8) | (b & 0xff))
* </pre></blockquote>
* {@description.close}
*
* {@property.open runtime formal:java.io.ByteArrayOutputStream_FlushBeforeRetrieve}
* {@property.close}
*
* @deprecated This method does not properly convert bytes into characters.
* As of JDK 1.1, the preferred way to do this is via the
* <code>toString(String enc)</code> method, which takes an encoding-name
* argument, or the <code>toString()</code> method, which uses the
* platform's default character encoding.
*
* @param hibyte the high byte of each resulting Unicode character.
* @return the current contents of the output stream, as a string.
* @see java.io.ByteArrayOutputStream#size()
* @see java.io.ByteArrayOutputStream#toString(String)
* @see java.io.ByteArrayOutputStream#toString()
*/
@Deprecated
public synchronized String toString(int hibyte) {
return new String(buf, hibyte, 0, count);
}
/** {@collect.stats}
* {@description.open}
* Closing a <tt>ByteArrayOutputStream</tt> has no effect.
* {@description.close}
* {@property.open runtime formal:java.io.Closeable_MeaninglessClose}
* The methods in
* this class can be called after the stream has been closed without
* generating an <tt>IOException</tt>.
* <p>
* {@property.close}
*/
public void close() throws IOException {
}
}
|
Java
|
/*
* Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.applet;
import java.awt.Image;
import java.awt.Graphics;
import java.awt.image.ColorModel;
import java.net.URL;
import java.util.Enumeration;
import java.io.InputStream;
import java.io.IOException;
import java.util.Iterator;
/** {@collect.stats}
* This interface corresponds to an applet's environment: the
* document containing the applet and the other applets in the same
* document.
* <p>
* The methods in this interface can be used by an applet to obtain
* information about its environment.
*
* @author Arthur van Hoff
* @since JDK1.0
*/
public interface AppletContext {
/** {@collect.stats}
* Creates an audio clip.
*
* @param url an absolute URL giving the location of the audio clip.
* @return the audio clip at the specified URL.
*/
AudioClip getAudioClip(URL url);
/** {@collect.stats}
* Returns an <code>Image</code> object that can then be painted on
* the screen. The <code>url</code> argument<code> </code>that is
* passed as an argument must specify an absolute URL.
* <p>
* This method always returns immediately, whether or not the image
* exists. When the applet attempts to draw the image on the screen,
* the data will be loaded. The graphics primitives that draw the
* image will incrementally paint on the screen.
*
* @param url an absolute URL giving the location of the image.
* @return the image at the specified URL.
* @see java.awt.Image
*/
Image getImage(URL url);
/** {@collect.stats}
* Finds and returns the applet in the document represented by this
* applet context with the given name. The name can be set in the
* HTML tag by setting the <code>name</code> attribute.
*
* @param name an applet name.
* @return the applet with the given name, or <code>null</code> if
* not found.
*/
Applet getApplet(String name);
/** {@collect.stats}
* Finds all the applets in the document represented by this applet
* context.
*
* @return an enumeration of all applets in the document represented by
* this applet context.
*/
Enumeration<Applet> getApplets();
/** {@collect.stats}
* Requests that the browser or applet viewer show the Web page
* indicated by the <code>url</code> argument. The browser or
* applet viewer determines which window or frame to display the
* Web page. This method may be ignored by applet contexts that
* are not browsers.
*
* @param url an absolute URL giving the location of the document.
*/
void showDocument(URL url);
/** {@collect.stats}
* Requests that the browser or applet viewer show the Web page
* indicated by the <code>url</code> argument. The
* <code>target</code> argument indicates in which HTML frame the
* document is to be displayed.
* The target argument is interpreted as follows:
* <p>
* <center><table border="3" summary="Target arguments and their descriptions">
* <tr><th>Target Argument</th><th>Description</th></tr>
* <tr><td><code>"_self"</code> <td>Show in the window and frame that
* contain the applet.</tr>
* <tr><td><code>"_parent"</code><td>Show in the applet's parent frame. If
* the applet's frame has no parent frame,
* acts the same as "_self".</tr>
* <tr><td><code>"_top"</code> <td>Show in the top-level frame of the applet's
* window. If the applet's frame is the
* top-level frame, acts the same as "_self".</tr>
* <tr><td><code>"_blank"</code> <td>Show in a new, unnamed
* top-level window.</tr>
* <tr><td><i>name</i><td>Show in the frame or window named <i>name</i>. If
* a target named <i>name</i> does not already exist, a
* new top-level window with the specified name is created,
* and the document is shown there.</tr>
* </table> </center>
* <p>
* An applet viewer or browser is free to ignore <code>showDocument</code>.
*
* @param url an absolute URL giving the location of the document.
* @param target a <code>String</code> indicating where to display
* the page.
*/
public void showDocument(URL url, String target);
/** {@collect.stats}
* Requests that the argument string be displayed in the
* "status window". Many browsers and applet viewers
* provide such a window, where the application can inform users of
* its current state.
*
* @param status a string to display in the status window.
*/
void showStatus(String status);
/** {@collect.stats}
* Associates the specified stream with the specified key in this
* applet context. If the applet context previously contained a mapping
* for this key, the old value is replaced.
* <p>
* For security reasons, mapping of streams and keys exists for each
* codebase. In other words, applet from one codebase cannot access
* the streams created by an applet from a different codebase
* <p>
* @param key key with which the specified value is to be associated.
* @param stream stream to be associated with the specified key. If this
* parameter is <code>null</code>, the specified key is removed
* in this applet context.
* @throws <code>IOException</code> if the stream size exceeds a certain
* size limit. Size limit is decided by the implementor of this
* interface.
* @since 1.4
*/
public void setStream(String key, InputStream stream)throws IOException;
/** {@collect.stats}
* Returns the stream to which specified key is associated within this
* applet context. Returns <tt>null</tt> if the applet context contains
* no stream for this key.
* <p>
* For security reasons, mapping of streams and keys exists for each
* codebase. In other words, applet from one codebase cannot access
* the streams created by an applet from a different codebase
* <p>
* @return the stream to which this applet context maps the key
* @param key key whose associated stream is to be returned.
* @since 1.4
*/
public InputStream getStream(String key);
/** {@collect.stats}
* Finds all the keys of the streams in this applet context.
* <p>
* For security reasons, mapping of streams and keys exists for each
* codebase. In other words, applet from one codebase cannot access
* the streams created by an applet from a different codebase
* <p>
* @return an Iterator of all the names of the streams in this applet
* context.
* @since 1.4
*/
public Iterator<String> getStreamKeys();
}
|
Java
|
/*
* Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.applet;
import java.awt.*;
import java.awt.image.ColorModel;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.Hashtable;
import java.util.Locale;
import javax.accessibility.*;
/** {@collect.stats}
* An applet is a small program that is intended not to be run on
* its own, but rather to be embedded inside another application.
* <p>
* The <code>Applet</code> class must be the superclass of any
* applet that is to be embedded in a Web page or viewed by the Java
* Applet Viewer. The <code>Applet</code> class provides a standard
* interface between applets and their environment.
*
* @author Arthur van Hoff
* @author Chris Warth
* @since JDK1.0
*/
public class Applet extends Panel {
/** {@collect.stats}
* Constructs a new Applet.
* <p>
* Note: Many methods in <code>java.applet.Applet</code>
* may be invoked by the applet only after the applet is
* fully constructed; applet should avoid calling methods
* in <code>java.applet.Applet</code> in the constructor.
*
* @exception HeadlessException if GraphicsEnvironment.isHeadless()
* returns true.
* @see java.awt.GraphicsEnvironment#isHeadless
* @since 1.4
*/
public Applet() throws HeadlessException {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
}
/** {@collect.stats}
* Applets can be serialized but the following conventions MUST be followed:
*
* Before Serialization:
* An applet must be in STOPPED state.
*
* After Deserialization:
* The applet will be restored in STOPPED state (and most clients will
* likely move it into RUNNING state).
* The stub field will be restored by the reader.
*/
transient private AppletStub stub;
/* version ID for serialized form. */
private static final long serialVersionUID = -5836846270535785031L;
/** {@collect.stats}
* Read an applet from an object input stream.
* @exception HeadlessException if
* <code>GraphicsEnvironment.isHeadless()</code> returns
* <code>true</code>
* @serial
* @see java.awt.GraphicsEnvironment#isHeadless
* @since 1.4
*/
private void readObject(ObjectInputStream s)
throws ClassNotFoundException, IOException, HeadlessException {
if (GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
s.defaultReadObject();
}
/** {@collect.stats}
* Sets this applet's stub. This is done automatically by the system.
* <p>If there is a security manager, its <code> checkPermission </code>
* method is called with the
* <code>AWTPermission("setAppletStub")</code>
* permission if a stub has already been set.
* @param stub the new stub.
* @exception SecurityException if the caller cannot set the stub
*/
public final void setStub(AppletStub stub) {
if (this.stub != null) {
SecurityManager s = System.getSecurityManager();
if (s != null) {
s.checkPermission(new AWTPermission("setAppletStub"));
}
}
this.stub = (AppletStub)stub;
}
/** {@collect.stats}
* Determines if this applet is active. An applet is marked active
* just before its <code>start</code> method is called. It becomes
* inactive just before its <code>stop</code> method is called.
*
* @return <code>true</code> if the applet is active;
* <code>false</code> otherwise.
* @see java.applet.Applet#start()
* @see java.applet.Applet#stop()
*/
public boolean isActive() {
if (stub != null) {
return stub.isActive();
} else { // If stub field not filled in, applet never active
return false;
}
}
/** {@collect.stats}
* Gets the URL of the document in which this applet is embedded.
* For example, suppose an applet is contained
* within the document:
* <blockquote><pre>
* http://java.sun.com/products/jdk/1.2/index.html
* </pre></blockquote>
* The document base is:
* <blockquote><pre>
* http://java.sun.com/products/jdk/1.2/index.html
* </pre></blockquote>
*
* @return the {@link java.net.URL} of the document that contains this
* applet.
* @see java.applet.Applet#getCodeBase()
*/
public URL getDocumentBase() {
return stub.getDocumentBase();
}
/** {@collect.stats}
* Gets the base URL. This is the URL of the directory which contains this applet.
*
* @return the base {@link java.net.URL} of
* the directory which contains this applet.
* @see java.applet.Applet#getDocumentBase()
*/
public URL getCodeBase() {
return stub.getCodeBase();
}
/** {@collect.stats}
* Returns the value of the named parameter in the HTML tag. For
* example, if this applet is specified as
* <blockquote><pre>
* <applet code="Clock" width=50 height=50>
* <param name=Color value="blue">
* </applet>
* </pre></blockquote>
* <p>
* then a call to <code>getParameter("Color")</code> returns the
* value <code>"blue"</code>.
* <p>
* The <code>name</code> argument is case insensitive.
*
* @param name a parameter name.
* @return the value of the named parameter,
* or <code>null</code> if not set.
*/
public String getParameter(String name) {
return stub.getParameter(name);
}
/** {@collect.stats}
* Determines this applet's context, which allows the applet to
* query and affect the environment in which it runs.
* <p>
* This environment of an applet represents the document that
* contains the applet.
*
* @return the applet's context.
*/
public AppletContext getAppletContext() {
return stub.getAppletContext();
}
/** {@collect.stats}
* Requests that this applet be resized.
*
* @param width the new requested width for the applet.
* @param height the new requested height for the applet.
*/
public void resize(int width, int height) {
Dimension d = size();
if ((d.width != width) || (d.height != height)) {
super.resize(width, height);
if (stub != null) {
stub.appletResize(width, height);
}
}
}
/** {@collect.stats}
* Requests that this applet be resized.
*
* @param d an object giving the new width and height.
*/
public void resize(Dimension d) {
resize(d.width, d.height);
}
/** {@collect.stats}
* Requests that the argument string be displayed in the
* "status window". Many browsers and applet viewers
* provide such a window, where the application can inform users of
* its current state.
*
* @param msg a string to display in the status window.
*/
public void showStatus(String msg) {
getAppletContext().showStatus(msg);
}
/** {@collect.stats}
* Returns an <code>Image</code> object that can then be painted on
* the screen. The <code>url</code> that is passed as an argument
* must specify an absolute URL.
* <p>
* This method always returns immediately, whether or not the image
* exists. When this applet attempts to draw the image on the screen,
* the data will be loaded. The graphics primitives that draw the
* image will incrementally paint on the screen.
*
* @param url an absolute URL giving the location of the image.
* @return the image at the specified URL.
* @see java.awt.Image
*/
public Image getImage(URL url) {
return getAppletContext().getImage(url);
}
/** {@collect.stats}
* Returns an <code>Image</code> object that can then be painted on
* the screen. The <code>url</code> argument must specify an absolute
* URL. The <code>name</code> argument is a specifier that is
* relative to the <code>url</code> argument.
* <p>
* This method always returns immediately, whether or not the image
* exists. When this applet attempts to draw the image on the screen,
* the data will be loaded. The graphics primitives that draw the
* image will incrementally paint on the screen.
*
* @param url an absolute URL giving the base location of the image.
* @param name the location of the image, relative to the
* <code>url</code> argument.
* @return the image at the specified URL.
* @see java.awt.Image
*/
public Image getImage(URL url, String name) {
try {
return getImage(new URL(url, name));
} catch (MalformedURLException e) {
return null;
}
}
/** {@collect.stats}
* Get an audio clip from the given URL.
*
* @param url points to the audio clip
* @return the audio clip at the specified URL.
*
* @since 1.2
*/
public final static AudioClip newAudioClip(URL url) {
return new sun.applet.AppletAudioClip(url);
}
/** {@collect.stats}
* Returns the <code>AudioClip</code> object specified by the
* <code>URL</code> argument.
* <p>
* This method always returns immediately, whether or not the audio
* clip exists. When this applet attempts to play the audio clip, the
* data will be loaded.
*
* @param url an absolute URL giving the location of the audio clip.
* @return the audio clip at the specified URL.
* @see java.applet.AudioClip
*/
public AudioClip getAudioClip(URL url) {
return getAppletContext().getAudioClip(url);
}
/** {@collect.stats}
* Returns the <code>AudioClip</code> object specified by the
* <code>URL</code> and <code>name</code> arguments.
* <p>
* This method always returns immediately, whether or not the audio
* clip exists. When this applet attempts to play the audio clip, the
* data will be loaded.
*
* @param url an absolute URL giving the base location of the
* audio clip.
* @param name the location of the audio clip, relative to the
* <code>url</code> argument.
* @return the audio clip at the specified URL.
* @see java.applet.AudioClip
*/
public AudioClip getAudioClip(URL url, String name) {
try {
return getAudioClip(new URL(url, name));
} catch (MalformedURLException e) {
return null;
}
}
/** {@collect.stats}
* Returns information about this applet. An applet should override
* this method to return a <code>String</code> containing information
* about the author, version, and copyright of the applet.
* <p>
* The implementation of this method provided by the
* <code>Applet</code> class returns <code>null</code>.
*
* @return a string containing information about the author, version, and
* copyright of the applet.
*/
public String getAppletInfo() {
return null;
}
/** {@collect.stats}
* Gets the locale of the applet. It allows the applet
* to maintain its own locale separated from the locale
* of the browser or appletviewer.
*
* @return the locale of the applet; if no locale has
* been set, the default locale is returned.
* @since JDK1.1
*/
public Locale getLocale() {
Locale locale = super.getLocale();
if (locale == null) {
return Locale.getDefault();
}
return locale;
}
/** {@collect.stats}
* Returns information about the parameters that are understood by
* this applet. An applet should override this method to return an
* array of <code>Strings</code> describing these parameters.
* <p>
* Each element of the array should be a set of three
* <code>Strings</code> containing the name, the type, and a
* description. For example:
* <p><blockquote><pre>
* String pinfo[][] = {
* {"fps", "1-10", "frames per second"},
* {"repeat", "boolean", "repeat image loop"},
* {"imgs", "url", "images directory"}
* };
* </pre></blockquote>
* <p>
* The implementation of this method provided by the
* <code>Applet</code> class returns <code>null</code>.
*
* @return an array describing the parameters this applet looks for.
*/
public String[][] getParameterInfo() {
return null;
}
/** {@collect.stats}
* Plays the audio clip at the specified absolute URL. Nothing
* happens if the audio clip cannot be found.
*
* @param url an absolute URL giving the location of the audio clip.
*/
public void play(URL url) {
AudioClip clip = getAudioClip(url);
if (clip != null) {
clip.play();
}
}
/** {@collect.stats}
* Plays the audio clip given the URL and a specifier that is
* relative to it. Nothing happens if the audio clip cannot be found.
*
* @param url an absolute URL giving the base location of the
* audio clip.
* @param name the location of the audio clip, relative to the
* <code>url</code> argument.
*/
public void play(URL url, String name) {
AudioClip clip = getAudioClip(url, name);
if (clip != null) {
clip.play();
}
}
/** {@collect.stats}
* Called by the browser or applet viewer to inform
* this applet that it has been loaded into the system. It is always
* called before the first time that the <code>start</code> method is
* called.
* <p>
* A subclass of <code>Applet</code> should override this method if
* it has initialization to perform. For example, an applet with
* threads would use the <code>init</code> method to create the
* threads and the <code>destroy</code> method to kill them.
* <p>
* The implementation of this method provided by the
* <code>Applet</code> class does nothing.
*
* @see java.applet.Applet#destroy()
* @see java.applet.Applet#start()
* @see java.applet.Applet#stop()
*/
public void init() {
}
/** {@collect.stats}
* Called by the browser or applet viewer to inform
* this applet that it should start its execution. It is called after
* the <code>init</code> method and each time the applet is revisited
* in a Web page.
* <p>
* A subclass of <code>Applet</code> should override this method if
* it has any operation that it wants to perform each time the Web
* page containing it is visited. For example, an applet with
* animation might want to use the <code>start</code> method to
* resume animation, and the <code>stop</code> method to suspend the
* animation.
* <p>
* Note: some methods, such as <code>getLocationOnScreen</code>, can only
* provide meaningful results if the applet is showing. Because
* <code>isShowing</code> returns <code>false</code> when the applet's
* <code>start</code> is first called, methods requiring
* <code>isShowing</code> to return <code>true</code> should be called from
* a <code>ComponentListener</code>.
* <p>
* The implementation of this method provided by the
* <code>Applet</code> class does nothing.
*
* @see java.applet.Applet#destroy()
* @see java.applet.Applet#init()
* @see java.applet.Applet#stop()
* @see java.awt.Component#isShowing()
* @see java.awt.event.ComponentListener#componentShown(java.awt.event.ComponentEvent)
*/
public void start() {
}
/** {@collect.stats}
* Called by the browser or applet viewer to inform
* this applet that it should stop its execution. It is called when
* the Web page that contains this applet has been replaced by
* another page, and also just before the applet is to be destroyed.
* <p>
* A subclass of <code>Applet</code> should override this method if
* it has any operation that it wants to perform each time the Web
* page containing it is no longer visible. For example, an applet
* with animation might want to use the <code>start</code> method to
* resume animation, and the <code>stop</code> method to suspend the
* animation.
* <p>
* The implementation of this method provided by the
* <code>Applet</code> class does nothing.
*
* @see java.applet.Applet#destroy()
* @see java.applet.Applet#init()
*/
public void stop() {
}
/** {@collect.stats}
* Called by the browser or applet viewer to inform
* this applet that it is being reclaimed and that it should destroy
* any resources that it has allocated. The <code>stop</code> method
* will always be called before <code>destroy</code>.
* <p>
* A subclass of <code>Applet</code> should override this method if
* it has any operation that it wants to perform before it is
* destroyed. For example, an applet with threads would use the
* <code>init</code> method to create the threads and the
* <code>destroy</code> method to kill them.
* <p>
* The implementation of this method provided by the
* <code>Applet</code> class does nothing.
*
* @see java.applet.Applet#init()
* @see java.applet.Applet#start()
* @see java.applet.Applet#stop()
*/
public void destroy() {
}
//
// Accessibility support
//
AccessibleContext accessibleContext = null;
/** {@collect.stats}
* Gets the AccessibleContext associated with this Applet.
* For applets, the AccessibleContext takes the form of an
* AccessibleApplet.
* A new AccessibleApplet instance is created if necessary.
*
* @return an AccessibleApplet that serves as the
* AccessibleContext of this Applet
* @since 1.3
*/
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleApplet();
}
return accessibleContext;
}
/** {@collect.stats}
* This class implements accessibility support for the
* <code>Applet</code> class. It provides an implementation of the
* Java Accessibility API appropriate to applet user-interface elements.
* @since 1.3
*/
protected class AccessibleApplet extends AccessibleAWTPanel {
private static final long serialVersionUID = 8127374778187708896L;
/** {@collect.stats}
* Get the role of this object.
*
* @return an instance of AccessibleRole describing the role of the
* object
*/
public AccessibleRole getAccessibleRole() {
return AccessibleRole.FRAME;
}
/** {@collect.stats}
* Get the state of this object.
*
* @return an instance of AccessibleStateSet containing the current
* state set of the object
* @see AccessibleState
*/
public AccessibleStateSet getAccessibleStateSet() {
AccessibleStateSet states = super.getAccessibleStateSet();
states.add(AccessibleState.ACTIVE);
return states;
}
}
}
|
Java
|
/*
* Copyright (c) 1995, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.applet;
import java.net.URL;
/** {@collect.stats}
* When an applet is first created, an applet stub is attached to it
* using the applet's <code>setStub</code> method. This stub
* serves as the interface between the applet and the browser
* environment or applet viewer environment in which the application
* is running.
*
* @author Arthur van Hoff
* @see java.applet.Applet#setStub(java.applet.AppletStub)
* @since JDK1.0
*/
public interface AppletStub {
/** {@collect.stats}
* Determines if the applet is active. An applet is active just
* before its <code>start</code> method is called. It becomes
* inactive just before its <code>stop</code> method is called.
*
* @return <code>true</code> if the applet is active;
* <code>false</code> otherwise.
*/
boolean isActive();
/** {@collect.stats}
* Gets the URL of the document in which the applet is embedded.
* For example, suppose an applet is contained
* within the document:
* <blockquote><pre>
* http://java.sun.com/products/jdk/1.2/index.html
* </pre></blockquote>
* The document base is:
* <blockquote><pre>
* http://java.sun.com/products/jdk/1.2/index.html
* </pre></blockquote>
*
* @return the {@link java.net.URL} of the document that contains the
* applet.
* @see java.applet.AppletStub#getCodeBase()
*/
URL getDocumentBase();
/** {@collect.stats}
* Gets the base URL. This is the URL of the directory which contains the applet.
*
* @return the base {@link java.net.URL} of
* the directory which contains the applet.
* @see java.applet.AppletStub#getDocumentBase()
*/
URL getCodeBase();
/** {@collect.stats}
* Returns the value of the named parameter in the HTML tag. For
* example, if an applet is specified as
* <blockquote><pre>
* <applet code="Clock" width=50 height=50>
* <param name=Color value="blue">
* </applet>
* </pre></blockquote>
* <p>
* then a call to <code>getParameter("Color")</code> returns the
* value <code>"blue"</code>.
*
* @param name a parameter name.
* @return the value of the named parameter,
* or <tt>null</tt> if not set.
*/
String getParameter(String name);
/** {@collect.stats}
* Returns the applet's context.
*
* @return the applet's context.
*/
AppletContext getAppletContext();
/** {@collect.stats}
* Called when the applet wants to be resized.
*
* @param width the new requested width for the applet.
* @param height the new requested height for the applet.
*/
void appletResize(int width, int height);
}
|
Java
|
/*
* Copyright (c) 1995, 1997, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.applet;
/** {@collect.stats}
* The <code>AudioClip</code> interface is a simple abstraction for
* playing a sound clip. Multiple <code>AudioClip</code> items can be
* playing at the same time, and the resulting sound is mixed
* together to produce a composite.
*
* @author Arthur van Hoff
* @since JDK1.0
*/
public interface AudioClip {
/** {@collect.stats}
* Starts playing this audio clip. Each time this method is called,
* the clip is restarted from the beginning.
*/
void play();
/** {@collect.stats}
* Starts playing this audio clip in a loop.
*/
void loop();
/** {@collect.stats}
* Stops playing this audio clip.
*/
void stop();
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
import java.math.BigDecimal;
import java.util.Calendar;
import java.io.Reader;
import java.io.InputStream;
/** {@collect.stats}
* The interface used to execute SQL stored procedures. The JDBC API
* provides a stored procedure SQL escape syntax that allows stored procedures
* to be called in a standard way for all RDBMSs. This escape syntax has one
* form that includes a result parameter and one that does not. If used, the result
* parameter must be registered as an OUT parameter. The other parameters
* can be used for input, output or both. Parameters are referred to
* sequentially, by number, with the first parameter being 1.
* <PRE>
* {?= call <procedure-name>[(<arg1>,<arg2>, ...)]}
* {call <procedure-name>[(<arg1>,<arg2>, ...)]}
* </PRE>
* <P>
* IN parameter values are set using the <code>set</code> methods inherited from
* {@link PreparedStatement}. The type of all OUT parameters must be
* registered prior to executing the stored procedure; their values
* are retrieved after execution via the <code>get</code> methods provided here.
* <P>
* A <code>CallableStatement</code> can return one {@link ResultSet} object or
* multiple <code>ResultSet</code> objects. Multiple
* <code>ResultSet</code> objects are handled using operations
* inherited from {@link Statement}.
* <P>
* For maximum portability, a call's <code>ResultSet</code> objects and
* update counts should be processed prior to getting the values of output
* parameters.
* <P>
*
* @see Connection#prepareCall
* @see ResultSet
*/
public interface CallableStatement extends PreparedStatement {
/** {@collect.stats}
* Registers the OUT parameter in ordinal position
* <code>parameterIndex</code> to the JDBC type
* <code>sqlType</code>. All OUT parameters must be registered
* before a stored procedure is executed.
* <p>
* The JDBC type specified by <code>sqlType</code> for an OUT
* parameter determines the Java type that must be used
* in the <code>get</code> method to read the value of that parameter.
* <p>
* If the JDBC type expected to be returned to this output parameter
* is specific to this particular database, <code>sqlType</code>
* should be <code>java.sql.Types.OTHER</code>. The method
* {@link #getObject} retrieves the value.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @param sqlType the JDBC type code defined by <code>java.sql.Types</code>.
* If the parameter is of JDBC type <code>NUMERIC</code>
* or <code>DECIMAL</code>, the version of
* <code>registerOutParameter</code> that accepts a scale value
* should be used.
*
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if <code>sqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type
* @see Types
*/
void registerOutParameter(int parameterIndex, int sqlType)
throws SQLException;
/** {@collect.stats}
* Registers the parameter in ordinal position
* <code>parameterIndex</code> to be of JDBC type
* <code>sqlType</code>. All OUT parameters must be registered
* before a stored procedure is executed.
* <p>
* The JDBC type specified by <code>sqlType</code> for an OUT
* parameter determines the Java type that must be used
* in the <code>get</code> method to read the value of that parameter.
* <p>
* This version of <code>registerOutParameter</code> should be
* used when the parameter is of JDBC type <code>NUMERIC</code>
* or <code>DECIMAL</code>.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @param sqlType the SQL type code defined by <code>java.sql.Types</code>.
* @param scale the desired number of digits to the right of the
* decimal point. It must be greater than or equal to zero.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if <code>sqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type
* @see Types
*/
void registerOutParameter(int parameterIndex, int sqlType, int scale)
throws SQLException;
/** {@collect.stats}
* Retrieves whether the last OUT parameter read had the value of
* SQL <code>NULL</code>. Note that this method should be called only after
* calling a getter method; otherwise, there is no value to use in
* determining whether it is <code>null</code> or not.
*
* @return <code>true</code> if the last parameter read was SQL
* <code>NULL</code>; <code>false</code> otherwise
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
*/
boolean wasNull() throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>CHAR</code>,
* <code>VARCHAR</code>, or <code>LONGVARCHAR</code> parameter as a
* <code>String</code> in the Java programming language.
* <p>
* For the fixed-length type JDBC <code>CHAR</code>,
* the <code>String</code> object
* returned has exactly the same value the SQL
* <code>CHAR</code> value had in the
* database, including any padding added by the database.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value. If the value is SQL <code>NULL</code>,
* the result
* is <code>null</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setString
*/
String getString(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>BIT</code>
* or <code>BOOLEAN</code> parameter as a
* <code>boolean</code> in the Java programming language.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value. If the value is SQL <code>NULL</code>,
* the result is <code>false</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setBoolean
*/
boolean getBoolean(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>TINYINT</code> parameter
* as a <code>byte</code> in the Java programming language.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>0</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setByte
*/
byte getByte(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>SMALLINT</code> parameter
* as a <code>short</code> in the Java programming language.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>0</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setShort
*/
short getShort(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>INTEGER</code> parameter
* as an <code>int</code> in the Java programming language.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>0</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setInt
*/
int getInt(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>BIGINT</code> parameter
* as a <code>long</code> in the Java programming language.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>0</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setLong
*/
long getLong(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>FLOAT</code> parameter
* as a <code>float</code> in the Java programming language.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>0</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setFloat
*/
float getFloat(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>DOUBLE</code> parameter as a <code>double</code>
* in the Java programming language.
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>0</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setDouble
*/
double getDouble(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>NUMERIC</code> parameter as a
* <code>java.math.BigDecimal</code> object with <i>scale</i> digits to
* the right of the decimal point.
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @param scale the number of digits to the right of the decimal point
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>null</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @deprecated use <code>getBigDecimal(int parameterIndex)</code>
* or <code>getBigDecimal(String parameterName)</code>
* @see #setBigDecimal
*/
BigDecimal getBigDecimal(int parameterIndex, int scale)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>BINARY</code> or
* <code>VARBINARY</code> parameter as an array of <code>byte</code>
* values in the Java programming language.
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>null</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setBytes
*/
byte[] getBytes(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>DATE</code> parameter as a
* <code>java.sql.Date</code> object.
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>null</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setDate
*/
java.sql.Date getDate(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>TIME</code> parameter as a
* <code>java.sql.Time</code> object.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>null</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setTime
*/
java.sql.Time getTime(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>TIMESTAMP</code> parameter as a
* <code>java.sql.Timestamp</code> object.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>null</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setTimestamp
*/
java.sql.Timestamp getTimestamp(int parameterIndex)
throws SQLException;
//----------------------------------------------------------------------
// Advanced features:
/** {@collect.stats}
* Retrieves the value of the designated parameter as an <code>Object</code>
* in the Java programming language. If the value is an SQL <code>NULL</code>,
* the driver returns a Java <code>null</code>.
* <p>
* This method returns a Java object whose type corresponds to the JDBC
* type that was registered for this parameter using the method
* <code>registerOutParameter</code>. By registering the target JDBC
* type as <code>java.sql.Types.OTHER</code>, this method can be used
* to read database-specific abstract data types.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return A <code>java.lang.Object</code> holding the OUT parameter value
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see Types
* @see #setObject
*/
Object getObject(int parameterIndex) throws SQLException;
//--------------------------JDBC 2.0-----------------------------
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>NUMERIC</code> parameter as a
* <code>java.math.BigDecimal</code> object with as many digits to the
* right of the decimal point as the value contains.
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value in full precision. If the value is
* SQL <code>NULL</code>, the result is <code>null</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setBigDecimal
* @since 1.2
*/
BigDecimal getBigDecimal(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Returns an object representing the value of OUT parameter
* <code>parameterIndex</code> and uses <code>map</code> for the custom
* mapping of the parameter value.
* <p>
* This method returns a Java object whose type corresponds to the
* JDBC type that was registered for this parameter using the method
* <code>registerOutParameter</code>. By registering the target
* JDBC type as <code>java.sql.Types.OTHER</code>, this method can
* be used to read database-specific abstract data types.
* @param parameterIndex the first parameter is 1, the second is 2, and so on
* @param map the mapping from SQL type names to Java classes
* @return a <code>java.lang.Object</code> holding the OUT parameter value
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setObject
* @since 1.2
*/
Object getObject(int parameterIndex, java.util.Map<String,Class<?>> map)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>REF(<structured-type>)</code>
* parameter as a {@link java.sql.Ref} object in the Java programming language.
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @return the parameter value as a <code>Ref</code> object in the
* Java programming language. If the value was SQL <code>NULL</code>, the value
* <code>null</code> is returned.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Ref getRef (int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>BLOB</code> parameter as a
* {@link java.sql.Blob} object in the Java programming language.
* @param parameterIndex the first parameter is 1, the second is 2, and so on
* @return the parameter value as a <code>Blob</code> object in the
* Java programming language. If the value was SQL <code>NULL</code>, the value
* <code>null</code> is returned.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Blob getBlob (int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>CLOB</code> parameter as a
* <code>java.sql.Clob</code> object in the Java programming language.
* @param parameterIndex the first parameter is 1, the second is 2, and
* so on
* @return the parameter value as a <code>Clob</code> object in the
* Java programming language. If the value was SQL <code>NULL</code>, the
* value <code>null</code> is returned.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Clob getClob (int parameterIndex) throws SQLException;
/** {@collect.stats}
*
* Retrieves the value of the designated JDBC <code>ARRAY</code> parameter as an
* {@link java.sql.Array} object in the Java programming language.
* @param parameterIndex the first parameter is 1, the second is 2, and
* so on
* @return the parameter value as an <code>Array</code> object in
* the Java programming language. If the value was SQL <code>NULL</code>, the
* value <code>null</code> is returned.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Array getArray (int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>DATE</code> parameter as a
* <code>java.sql.Date</code> object, using
* the given <code>Calendar</code> object
* to construct the date.
* With a <code>Calendar</code> object, the driver
* can calculate the date taking into account a custom timezone and locale.
* If no <code>Calendar</code> object is specified, the driver uses the
* default timezone and locale.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @param cal the <code>Calendar</code> object the driver will use
* to construct the date
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>null</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setDate
* @since 1.2
*/
java.sql.Date getDate(int parameterIndex, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>TIME</code> parameter as a
* <code>java.sql.Time</code> object, using
* the given <code>Calendar</code> object
* to construct the time.
* With a <code>Calendar</code> object, the driver
* can calculate the time taking into account a custom timezone and locale.
* If no <code>Calendar</code> object is specified, the driver uses the
* default timezone and locale.
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @param cal the <code>Calendar</code> object the driver will use
* to construct the time
* @return the parameter value; if the value is SQL <code>NULL</code>, the result
* is <code>null</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setTime
* @since 1.2
*/
java.sql.Time getTime(int parameterIndex, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>TIMESTAMP</code> parameter as a
* <code>java.sql.Timestamp</code> object, using
* the given <code>Calendar</code> object to construct
* the <code>Timestamp</code> object.
* With a <code>Calendar</code> object, the driver
* can calculate the timestamp taking into account a custom timezone and locale.
* If no <code>Calendar</code> object is specified, the driver uses the
* default timezone and locale.
*
*
* @param parameterIndex the first parameter is 1, the second is 2,
* and so on
* @param cal the <code>Calendar</code> object the driver will use
* to construct the timestamp
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>null</code>.
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #setTimestamp
* @since 1.2
*/
java.sql.Timestamp getTimestamp(int parameterIndex, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Registers the designated output parameter.
* This version of
* the method <code>registerOutParameter</code>
* should be used for a user-defined or <code>REF</code> output parameter. Examples
* of user-defined types include: <code>STRUCT</code>, <code>DISTINCT</code>,
* <code>JAVA_OBJECT</code>, and named array types.
*<p>
* All OUT parameters must be registered
* before a stored procedure is executed.
* <p> For a user-defined parameter, the fully-qualified SQL
* type name of the parameter should also be given, while a <code>REF</code>
* parameter requires that the fully-qualified type name of the
* referenced type be given. A JDBC driver that does not need the
* type code and type name information may ignore it. To be portable,
* however, applications should always provide these values for
* user-defined and <code>REF</code> parameters.
*
* Although it is intended for user-defined and <code>REF</code> parameters,
* this method may be used to register a parameter of any JDBC type.
* If the parameter does not have a user-defined or <code>REF</code> type, the
* <i>typeName</i> parameter is ignored.
*
* <P><B>Note:</B> When reading the value of an out parameter, you
* must use the getter method whose Java type corresponds to the
* parameter's registered SQL type.
*
* @param parameterIndex the first parameter is 1, the second is 2,...
* @param sqlType a value from {@link java.sql.Types}
* @param typeName the fully-qualified name of an SQL structured type
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if <code>sqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type
* @see Types
* @since 1.2
*/
void registerOutParameter (int parameterIndex, int sqlType, String typeName)
throws SQLException;
//--------------------------JDBC 3.0-----------------------------
/** {@collect.stats}
* Registers the OUT parameter named
* <code>parameterName</code> to the JDBC type
* <code>sqlType</code>. All OUT parameters must be registered
* before a stored procedure is executed.
* <p>
* The JDBC type specified by <code>sqlType</code> for an OUT
* parameter determines the Java type that must be used
* in the <code>get</code> method to read the value of that parameter.
* <p>
* If the JDBC type expected to be returned to this output parameter
* is specific to this particular database, <code>sqlType</code>
* should be <code>java.sql.Types.OTHER</code>. The method
* {@link #getObject} retrieves the value.
* @param parameterName the name of the parameter
* @param sqlType the JDBC type code defined by <code>java.sql.Types</code>.
* If the parameter is of JDBC type <code>NUMERIC</code>
* or <code>DECIMAL</code>, the version of
* <code>registerOutParameter</code> that accepts a scale value
* should be used.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if <code>sqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type or if the JDBC driver does not support
* this method
* @since 1.4
* @see Types
*/
void registerOutParameter(String parameterName, int sqlType)
throws SQLException;
/** {@collect.stats}
* Registers the parameter named
* <code>parameterName</code> to be of JDBC type
* <code>sqlType</code>. All OUT parameters must be registered
* before a stored procedure is executed.
* <p>
* The JDBC type specified by <code>sqlType</code> for an OUT
* parameter determines the Java type that must be used
* in the <code>get</code> method to read the value of that parameter.
* <p>
* This version of <code>registerOutParameter</code> should be
* used when the parameter is of JDBC type <code>NUMERIC</code>
* or <code>DECIMAL</code>.
*
* @param parameterName the name of the parameter
* @param sqlType SQL type code defined by <code>java.sql.Types</code>.
* @param scale the desired number of digits to the right of the
* decimal point. It must be greater than or equal to zero.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if <code>sqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type or if the JDBC driver does not support
* this method
* @since 1.4
* @see Types
*/
void registerOutParameter(String parameterName, int sqlType, int scale)
throws SQLException;
/** {@collect.stats}
* Registers the designated output parameter. This version of
* the method <code>registerOutParameter</code>
* should be used for a user-named or REF output parameter. Examples
* of user-named types include: STRUCT, DISTINCT, JAVA_OBJECT, and
* named array types.
*<p>
* All OUT parameters must be registered
* before a stored procedure is executed.
* <p>
* For a user-named parameter the fully-qualified SQL
* type name of the parameter should also be given, while a REF
* parameter requires that the fully-qualified type name of the
* referenced type be given. A JDBC driver that does not need the
* type code and type name information may ignore it. To be portable,
* however, applications should always provide these values for
* user-named and REF parameters.
*
* Although it is intended for user-named and REF parameters,
* this method may be used to register a parameter of any JDBC type.
* If the parameter does not have a user-named or REF type, the
* typeName parameter is ignored.
*
* <P><B>Note:</B> When reading the value of an out parameter, you
* must use the <code>getXXX</code> method whose Java type XXX corresponds to the
* parameter's registered SQL type.
*
* @param parameterName the name of the parameter
* @param sqlType a value from {@link java.sql.Types}
* @param typeName the fully-qualified name of an SQL structured type
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if <code>sqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type or if the JDBC driver does not support
* this method
* @see Types
* @since 1.4
*/
void registerOutParameter (String parameterName, int sqlType, String typeName)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>DATALINK</code> parameter as a
* <code>java.net.URL</code> object.
*
* @param parameterIndex the first parameter is 1, the second is 2,...
* @return a <code>java.net.URL</code> object that represents the
* JDBC <code>DATALINK</code> value used as the designated
* parameter
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs,
* this method is called on a closed <code>CallableStatement</code>,
* or if the URL being returned is
* not a valid URL on the Java platform
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setURL
* @since 1.4
*/
java.net.URL getURL(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.net.URL</code> object.
* The driver converts this to an SQL <code>DATALINK</code> value when
* it sends it to the database.
*
* @param parameterName the name of the parameter
* @param val the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs;
* this method is called on a closed <code>CallableStatement</code>
* or if a URL is malformed
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getURL
* @since 1.4
*/
void setURL(String parameterName, java.net.URL val) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to SQL <code>NULL</code>.
*
* <P><B>Note:</B> You must specify the parameter's SQL type.
*
* @param parameterName the name of the parameter
* @param sqlType the SQL type code defined in <code>java.sql.Types</code>
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void setNull(String parameterName, int sqlType) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>boolean</code> value.
* The driver converts this
* to an SQL <code>BIT</code> or <code>BOOLEAN</code> value when it sends it to the database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @see #getBoolean
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void setBoolean(String parameterName, boolean x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>byte</code> value.
* The driver converts this
* to an SQL <code>TINYINT</code> value when it sends it to the database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getByte
* @since 1.4
*/
void setByte(String parameterName, byte x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>short</code> value.
* The driver converts this
* to an SQL <code>SMALLINT</code> value when it sends it to the database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getShort
* @since 1.4
*/
void setShort(String parameterName, short x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>int</code> value.
* The driver converts this
* to an SQL <code>INTEGER</code> value when it sends it to the database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getInt
* @since 1.4
*/
void setInt(String parameterName, int x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>long</code> value.
* The driver converts this
* to an SQL <code>BIGINT</code> value when it sends it to the database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getLong
* @since 1.4
*/
void setLong(String parameterName, long x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>float</code> value.
* The driver converts this
* to an SQL <code>FLOAT</code> value when it sends it to the database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getFloat
* @since 1.4
*/
void setFloat(String parameterName, float x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>double</code> value.
* The driver converts this
* to an SQL <code>DOUBLE</code> value when it sends it to the database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getDouble
* @since 1.4
*/
void setDouble(String parameterName, double x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given
* <code>java.math.BigDecimal</code> value.
* The driver converts this to an SQL <code>NUMERIC</code> value when
* it sends it to the database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getBigDecimal
* @since 1.4
*/
void setBigDecimal(String parameterName, BigDecimal x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>String</code> value.
* The driver converts this
* to an SQL <code>VARCHAR</code> or <code>LONGVARCHAR</code> value
* (depending on the argument's
* size relative to the driver's limits on <code>VARCHAR</code> values)
* when it sends it to the database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getString
* @since 1.4
*/
void setString(String parameterName, String x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java array of bytes.
* The driver converts this to an SQL <code>VARBINARY</code> or
* <code>LONGVARBINARY</code> (depending on the argument's size relative
* to the driver's limits on <code>VARBINARY</code> values) when it sends
* it to the database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getBytes
* @since 1.4
*/
void setBytes(String parameterName, byte x[]) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Date</code> value
* using the default time zone of the virtual machine that is running
* the application.
* The driver converts this
* to an SQL <code>DATE</code> value when it sends it to the database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getDate
* @since 1.4
*/
void setDate(String parameterName, java.sql.Date x)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Time</code> value.
* The driver converts this
* to an SQL <code>TIME</code> value when it sends it to the database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getTime
* @since 1.4
*/
void setTime(String parameterName, java.sql.Time x)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Timestamp</code> value.
* The driver
* converts this to an SQL <code>TIMESTAMP</code> value when it sends it to the
* database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getTimestamp
* @since 1.4
*/
void setTimestamp(String parameterName, java.sql.Timestamp x)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given input stream, which will have
* the specified number of bytes.
* When a very large ASCII value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code>. Data will be read from the stream
* as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from ASCII to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterName the name of the parameter
* @param x the Java input stream that contains the ASCII parameter value
* @param length the number of bytes in the stream
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void setAsciiStream(String parameterName, java.io.InputStream x, int length)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given input stream, which will have
* the specified number of bytes.
* When a very large binary value is input to a <code>LONGVARBINARY</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code> object. The data will be read from the stream
* as needed until end-of-file is reached.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterName the name of the parameter
* @param x the java input stream which contains the binary parameter value
* @param length the number of bytes in the stream
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void setBinaryStream(String parameterName, java.io.InputStream x,
int length) throws SQLException;
/** {@collect.stats}
* Sets the value of the designated parameter with the given object. The second
* argument must be an object type; for integral values, the
* <code>java.lang</code> equivalent objects should be used.
*
* <p>The given Java object will be converted to the given targetSqlType
* before being sent to the database.
*
* If the object has a custom mapping (is of a class implementing the
* interface <code>SQLData</code>),
* the JDBC driver should call the method <code>SQLData.writeSQL</code> to write it
* to the SQL data stream.
* If, on the other hand, the object is of a class implementing
* <code>Ref</code>, <code>Blob</code>, <code>Clob</code>, <code>NClob</code>,
* <code>Struct</code>, <code>java.net.URL</code>,
* or <code>Array</code>, the driver should pass it to the database as a
* value of the corresponding SQL type.
* <P>
* Note that this method may be used to pass datatabase-
* specific abstract data types.
*
* @param parameterName the name of the parameter
* @param x the object containing the input parameter value
* @param targetSqlType the SQL type (as defined in java.sql.Types) to be
* sent to the database. The scale argument may further qualify this type.
* @param scale for java.sql.Types.DECIMAL or java.sql.Types.NUMERIC types,
* this is the number of digits after the decimal point. For all other
* types, this value will be ignored.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if <code>targetSqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type
* @see Types
* @see #getObject
* @since 1.4
*/
void setObject(String parameterName, Object x, int targetSqlType, int scale)
throws SQLException;
/** {@collect.stats}
* Sets the value of the designated parameter with the given object.
* This method is like the method <code>setObject</code>
* above, except that it assumes a scale of zero.
*
* @param parameterName the name of the parameter
* @param x the object containing the input parameter value
* @param targetSqlType the SQL type (as defined in java.sql.Types) to be
* sent to the database
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if <code>targetSqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type
* @see #getObject
* @since 1.4
*/
void setObject(String parameterName, Object x, int targetSqlType)
throws SQLException;
/** {@collect.stats}
* Sets the value of the designated parameter with the given object.
* The second parameter must be of type <code>Object</code>; therefore, the
* <code>java.lang</code> equivalent objects should be used for built-in types.
*
* <p>The JDBC specification specifies a standard mapping from
* Java <code>Object</code> types to SQL types. The given argument
* will be converted to the corresponding SQL type before being
* sent to the database.
* <p>Note that this method may be used to pass datatabase-
* specific abstract data types, by using a driver-specific Java
* type.
*
* If the object is of a class implementing the interface <code>SQLData</code>,
* the JDBC driver should call the method <code>SQLData.writeSQL</code>
* to write it to the SQL data stream.
* If, on the other hand, the object is of a class implementing
* <code>Ref</code>, <code>Blob</code>, <code>Clob</code>, <code>NClob</code>,
* <code>Struct</code>, <code>java.net.URL</code>,
* or <code>Array</code>, the driver should pass it to the database as a
* value of the corresponding SQL type.
* <P>
* This method throws an exception if there is an ambiguity, for example, if the
* object is of a class implementing more than one of the interfaces named above.
*<p>
*<b>Note:</b> Not all databases allow for a non-typed Null to be sent to
* the backend. For maximum portability, the <code>setNull</code> or the
* <code>setObject(String parameterName, Object x, int sqlType)</code>
* method should be used
* instead of <code>setObject(String parameterName, Object x)</code>.
*<p>
* @param parameterName the name of the parameter
* @param x the object containing the input parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs,
* this method is called on a closed <code>CallableStatement</code> or if the given
* <code>Object</code> parameter is ambiguous
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getObject
* @since 1.4
*/
void setObject(String parameterName, Object x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>Reader</code>
* object, which is the given number of characters long.
* When a very large UNICODE value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.Reader</code> object. The data will be read from the stream
* as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterName the name of the parameter
* @param reader the <code>java.io.Reader</code> object that
* contains the UNICODE data used as the designated parameter
* @param length the number of characters in the stream
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void setCharacterStream(String parameterName,
java.io.Reader reader,
int length) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Date</code> value,
* using the given <code>Calendar</code> object. The driver uses
* the <code>Calendar</code> object to construct an SQL <code>DATE</code> value,
* which the driver then sends to the database. With a
* a <code>Calendar</code> object, the driver can calculate the date
* taking into account a custom timezone. If no
* <code>Calendar</code> object is specified, the driver uses the default
* timezone, which is that of the virtual machine running the application.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @param cal the <code>Calendar</code> object the driver will use
* to construct the date
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getDate
* @since 1.4
*/
void setDate(String parameterName, java.sql.Date x, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Time</code> value,
* using the given <code>Calendar</code> object. The driver uses
* the <code>Calendar</code> object to construct an SQL <code>TIME</code> value,
* which the driver then sends to the database. With a
* a <code>Calendar</code> object, the driver can calculate the time
* taking into account a custom timezone. If no
* <code>Calendar</code> object is specified, the driver uses the default
* timezone, which is that of the virtual machine running the application.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @param cal the <code>Calendar</code> object the driver will use
* to construct the time
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getTime
* @since 1.4
*/
void setTime(String parameterName, java.sql.Time x, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Timestamp</code> value,
* using the given <code>Calendar</code> object. The driver uses
* the <code>Calendar</code> object to construct an SQL <code>TIMESTAMP</code> value,
* which the driver then sends to the database. With a
* a <code>Calendar</code> object, the driver can calculate the timestamp
* taking into account a custom timezone. If no
* <code>Calendar</code> object is specified, the driver uses the default
* timezone, which is that of the virtual machine running the application.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @param cal the <code>Calendar</code> object the driver will use
* to construct the timestamp
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #getTimestamp
* @since 1.4
*/
void setTimestamp(String parameterName, java.sql.Timestamp x, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to SQL <code>NULL</code>.
* This version of the method <code>setNull</code> should
* be used for user-defined types and REF type parameters. Examples
* of user-defined types include: STRUCT, DISTINCT, JAVA_OBJECT, and
* named array types.
*
* <P><B>Note:</B> To be portable, applications must give the
* SQL type code and the fully-qualified SQL type name when specifying
* a NULL user-defined or REF parameter. In the case of a user-defined type
* the name is the type name of the parameter itself. For a REF
* parameter, the name is the type name of the referenced type.
* <p>
* Although it is intended for user-defined and Ref parameters,
* this method may be used to set a null parameter of any JDBC type.
* If the parameter does not have a user-defined or REF type, the given
* typeName is ignored.
*
*
* @param parameterName the name of the parameter
* @param sqlType a value from <code>java.sql.Types</code>
* @param typeName the fully-qualified name of an SQL user-defined type;
* ignored if the parameter is not a user-defined type or
* SQL <code>REF</code> value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void setNull (String parameterName, int sqlType, String typeName)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>CHAR</code>, <code>VARCHAR</code>,
* or <code>LONGVARCHAR</code> parameter as a <code>String</code> in
* the Java programming language.
* <p>
* For the fixed-length type JDBC <code>CHAR</code>,
* the <code>String</code> object
* returned has exactly the same value the SQL
* <code>CHAR</code> value had in the
* database, including any padding added by the database.
* @param parameterName the name of the parameter
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>null</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setString
* @since 1.4
*/
String getString(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>BIT</code> or <code>BOOLEAN</code>
* parameter as a
* <code>boolean</code> in the Java programming language.
* @param parameterName the name of the parameter
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>false</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setBoolean
* @since 1.4
*/
boolean getBoolean(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>TINYINT</code> parameter as a <code>byte</code>
* in the Java programming language.
* @param parameterName the name of the parameter
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>0</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setByte
* @since 1.4
*/
byte getByte(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>SMALLINT</code> parameter as a <code>short</code>
* in the Java programming language.
* @param parameterName the name of the parameter
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>0</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setShort
* @since 1.4
*/
short getShort(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>INTEGER</code> parameter as an <code>int</code>
* in the Java programming language.
*
* @param parameterName the name of the parameter
* @return the parameter value. If the value is SQL <code>NULL</code>,
* the result is <code>0</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setInt
* @since 1.4
*/
int getInt(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>BIGINT</code> parameter as a <code>long</code>
* in the Java programming language.
*
* @param parameterName the name of the parameter
* @return the parameter value. If the value is SQL <code>NULL</code>,
* the result is <code>0</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setLong
* @since 1.4
*/
long getLong(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>FLOAT</code> parameter as a <code>float</code>
* in the Java programming language.
* @param parameterName the name of the parameter
* @return the parameter value. If the value is SQL <code>NULL</code>,
* the result is <code>0</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setFloat
* @since 1.4
*/
float getFloat(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>DOUBLE</code> parameter as a <code>double</code>
* in the Java programming language.
* @param parameterName the name of the parameter
* @return the parameter value. If the value is SQL <code>NULL</code>,
* the result is <code>0</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setDouble
* @since 1.4
*/
double getDouble(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>BINARY</code> or <code>VARBINARY</code>
* parameter as an array of <code>byte</code> values in the Java
* programming language.
* @param parameterName the name of the parameter
* @return the parameter value. If the value is SQL <code>NULL</code>, the result is
* <code>null</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setBytes
* @since 1.4
*/
byte[] getBytes(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>DATE</code> parameter as a
* <code>java.sql.Date</code> object.
* @param parameterName the name of the parameter
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>null</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setDate
* @since 1.4
*/
java.sql.Date getDate(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>TIME</code> parameter as a
* <code>java.sql.Time</code> object.
* @param parameterName the name of the parameter
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>null</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setTime
* @since 1.4
*/
java.sql.Time getTime(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>TIMESTAMP</code> parameter as a
* <code>java.sql.Timestamp</code> object.
* @param parameterName the name of the parameter
* @return the parameter value. If the value is SQL <code>NULL</code>, the result
* is <code>null</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setTimestamp
* @since 1.4
*/
java.sql.Timestamp getTimestamp(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a parameter as an <code>Object</code> in the Java
* programming language. If the value is an SQL <code>NULL</code>, the
* driver returns a Java <code>null</code>.
* <p>
* This method returns a Java object whose type corresponds to the JDBC
* type that was registered for this parameter using the method
* <code>registerOutParameter</code>. By registering the target JDBC
* type as <code>java.sql.Types.OTHER</code>, this method can be used
* to read database-specific abstract data types.
* @param parameterName the name of the parameter
* @return A <code>java.lang.Object</code> holding the OUT parameter value.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see Types
* @see #setObject
* @since 1.4
*/
Object getObject(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>NUMERIC</code> parameter as a
* <code>java.math.BigDecimal</code> object with as many digits to the
* right of the decimal point as the value contains.
* @param parameterName the name of the parameter
* @return the parameter value in full precision. If the value is
* SQL <code>NULL</code>, the result is <code>null</code>.
* @exception SQLExceptionif parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setBigDecimal
* @since 1.4
*/
BigDecimal getBigDecimal(String parameterName) throws SQLException;
/** {@collect.stats}
* Returns an object representing the value of OUT parameter
* <code>parameterName</code> and uses <code>map</code> for the custom
* mapping of the parameter value.
* <p>
* This method returns a Java object whose type corresponds to the
* JDBC type that was registered for this parameter using the method
* <code>registerOutParameter</code>. By registering the target
* JDBC type as <code>java.sql.Types.OTHER</code>, this method can
* be used to read database-specific abstract data types.
* @param parameterName the name of the parameter
* @param map the mapping from SQL type names to Java classes
* @return a <code>java.lang.Object</code> holding the OUT parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setObject
* @since 1.4
*/
Object getObject(String parameterName, java.util.Map<String,Class<?>> map)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>REF(<structured-type>)</code>
* parameter as a {@link java.sql.Ref} object in the Java programming language.
*
* @param parameterName the name of the parameter
* @return the parameter value as a <code>Ref</code> object in the
* Java programming language. If the value was SQL <code>NULL</code>,
* the value <code>null</code> is returned.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
Ref getRef (String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>BLOB</code> parameter as a
* {@link java.sql.Blob} object in the Java programming language.
*
* @param parameterName the name of the parameter
* @return the parameter value as a <code>Blob</code> object in the
* Java programming language. If the value was SQL <code>NULL</code>,
* the value <code>null</code> is returned.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
Blob getBlob (String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>CLOB</code> parameter as a
* <code>java.sql.Clob</code> object in the Java programming language.
* @param parameterName the name of the parameter
* @return the parameter value as a <code>Clob</code> object in the
* Java programming language. If the value was SQL <code>NULL</code>,
* the value <code>null</code> is returned.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
Clob getClob (String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>ARRAY</code> parameter as an
* {@link java.sql.Array} object in the Java programming language.
*
* @param parameterName the name of the parameter
* @return the parameter value as an <code>Array</code> object in
* Java programming language. If the value was SQL <code>NULL</code>,
* the value <code>null</code> is returned.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
Array getArray (String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>DATE</code> parameter as a
* <code>java.sql.Date</code> object, using
* the given <code>Calendar</code> object
* to construct the date.
* With a <code>Calendar</code> object, the driver
* can calculate the date taking into account a custom timezone and locale.
* If no <code>Calendar</code> object is specified, the driver uses the
* default timezone and locale.
*
* @param parameterName the name of the parameter
* @param cal the <code>Calendar</code> object the driver will use
* to construct the date
* @return the parameter value. If the value is SQL <code>NULL</code>,
* the result is <code>null</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setDate
* @since 1.4
*/
java.sql.Date getDate(String parameterName, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>TIME</code> parameter as a
* <code>java.sql.Time</code> object, using
* the given <code>Calendar</code> object
* to construct the time.
* With a <code>Calendar</code> object, the driver
* can calculate the time taking into account a custom timezone and locale.
* If no <code>Calendar</code> object is specified, the driver uses the
* default timezone and locale.
*
* @param parameterName the name of the parameter
* @param cal the <code>Calendar</code> object the driver will use
* to construct the time
* @return the parameter value; if the value is SQL <code>NULL</code>, the result is
* <code>null</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setTime
* @since 1.4
*/
java.sql.Time getTime(String parameterName, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>TIMESTAMP</code> parameter as a
* <code>java.sql.Timestamp</code> object, using
* the given <code>Calendar</code> object to construct
* the <code>Timestamp</code> object.
* With a <code>Calendar</code> object, the driver
* can calculate the timestamp taking into account a custom timezone and locale.
* If no <code>Calendar</code> object is specified, the driver uses the
* default timezone and locale.
*
*
* @param parameterName the name of the parameter
* @param cal the <code>Calendar</code> object the driver will use
* to construct the timestamp
* @return the parameter value. If the value is SQL <code>NULL</code>, the result is
* <code>null</code>.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setTimestamp
* @since 1.4
*/
java.sql.Timestamp getTimestamp(String parameterName, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>DATALINK</code> parameter as a
* <code>java.net.URL</code> object.
*
* @param parameterName the name of the parameter
* @return the parameter value as a <code>java.net.URL</code> object in the
* Java programming language. If the value was SQL <code>NULL</code>, the
* value <code>null</code> is returned.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs,
* this method is called on a closed <code>CallableStatement</code>,
* or if there is a problem with the URL
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see #setURL
* @since 1.4
*/
java.net.URL getURL(String parameterName) throws SQLException;
//------------------------- JDBC 4.0 -----------------------------------
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>ROWID</code> parameter as a
* <code>java.sql.RowId</code> object.
*
* @param parameterIndex the first parameter is 1, the second is 2,...
* @return a <code>RowId</code> object that represents the JDBC <code>ROWID</code>
* value is used as the designated parameter. If the parameter contains
* a SQL <code>NULL</code>, then a <code>null</code> value is returned.
* @throws SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
RowId getRowId(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>ROWID</code> parameter as a
* <code>java.sql.RowId</code> object.
*
* @param parameterName the name of the parameter
* @return a <code>RowId</code> object that represents the JDBC <code>ROWID</code>
* value is used as the designated parameter. If the parameter contains
* a SQL <code>NULL</code>, then a <code>null</code> value is returned.
* @throws SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
RowId getRowId(String parameterName) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.RowId</code> object. The
* driver converts this to a SQL <code>ROWID</code> when it sends it to the
* database.
*
* @param parameterName the name of the parameter
* @param x the parameter value
* @throws SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void setRowId(String parameterName, RowId x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>String</code> object.
* The driver converts this to a SQL <code>NCHAR</code> or
* <code>NVARCHAR</code> or <code>LONGNVARCHAR</code>
* @param parameterName the name of the parameter to be set
* @param value the parameter value
* @throws SQLException if parameterName does not correspond to a named
* parameter; if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void setNString(String parameterName, String value)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>Reader</code> object. The
* <code>Reader</code> reads the data till end-of-file is reached. The
* driver does the necessary conversion from Java character format to
* the national character set in the database.
* @param parameterName the name of the parameter to be set
* @param value the parameter value
* @param length the number of characters in the parameter data.
* @throws SQLException if parameterName does not correspond to a named
* parameter; if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void setNCharacterStream(String parameterName, Reader value, long length)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>java.sql.NClob</code> object. The object
* implements the <code>java.sql.NClob</code> interface. This <code>NClob</code>
* object maps to a SQL <code>NCLOB</code>.
* @param parameterName the name of the parameter to be set
* @param value the parameter value
* @throws SQLException if parameterName does not correspond to a named
* parameter; if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void setNClob(String parameterName, NClob value) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>Reader</code> object. The <code>reader</code> must contain the number
* of characters specified by length otherwise a <code>SQLException</code> will be
* generated when the <code>CallableStatement</code> is executed.
* This method differs from the <code>setCharacterStream (int, Reader, int)</code> method
* because it informs the driver that the parameter value should be sent to
* the server as a <code>CLOB</code>. When the <code>setCharacterStream</code> method is used, the
* driver may have to do extra work to determine whether the parameter
* data should be send to the server as a <code>LONGVARCHAR</code> or a <code>CLOB</code>
* @param parameterName the name of the parameter to be set
* @param reader An object that contains the data to set the parameter value to.
* @param length the number of characters in the parameter data.
* @throws SQLException if parameterName does not correspond to a named
* parameter; if the length specified is less than zero;
* a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
*
* @since 1.6
*/
void setClob(String parameterName, Reader reader, long length)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>InputStream</code> object. The <code>inputstream</code> must contain the number
* of characters specified by length, otherwise a <code>SQLException</code> will be
* generated when the <code>CallableStatement</code> is executed.
* This method differs from the <code>setBinaryStream (int, InputStream, int)</code>
* method because it informs the driver that the parameter value should be
* sent to the server as a <code>BLOB</code>. When the <code>setBinaryStream</code> method is used,
* the driver may have to do extra work to determine whether the parameter
* data should be sent to the server as a <code>LONGVARBINARY</code> or a <code>BLOB</code>
*
* @param parameterName the name of the parameter to be set
* the second is 2, ...
*
* @param inputStream An object that contains the data to set the parameter
* value to.
* @param length the number of bytes in the parameter data.
* @throws SQLException if parameterName does not correspond to a named
* parameter; if the length specified
* is less than zero; if the number of bytes in the inputstream does not match
* the specfied length; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
*
* @since 1.6
*/
void setBlob(String parameterName, InputStream inputStream, long length)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>Reader</code> object. The <code>reader</code> must contain the number
* of characters specified by length otherwise a <code>SQLException</code> will be
* generated when the <code>CallableStatement</code> is executed.
* This method differs from the <code>setCharacterStream (int, Reader, int)</code> method
* because it informs the driver that the parameter value should be sent to
* the server as a <code>NCLOB</code>. When the <code>setCharacterStream</code> method is used, the
* driver may have to do extra work to determine whether the parameter
* data should be send to the server as a <code>LONGNVARCHAR</code> or a <code>NCLOB</code>
*
* @param parameterName the name of the parameter to be set
* @param reader An object that contains the data to set the parameter value to.
* @param length the number of characters in the parameter data.
* @throws SQLException if parameterName does not correspond to a named
* parameter; if the length specified is less than zero;
* if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void setNClob(String parameterName, Reader reader, long length)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated JDBC <code>NCLOB</code> parameter as a
* <code>java.sql.NClob</code> object in the Java programming language.
*
* @param parameterIndex the first parameter is 1, the second is 2, and
* so on
* @return the parameter value as a <code>NClob</code> object in the
* Java programming language. If the value was SQL <code>NULL</code>, the
* value <code>null</code> is returned.
* @exception SQLException if the parameterIndex is not valid;
* if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
NClob getNClob (int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of a JDBC <code>NCLOB</code> parameter as a
* <code>java.sql.NClob</code> object in the Java programming language.
* @param parameterName the name of the parameter
* @return the parameter value as a <code>NClob</code> object in the
* Java programming language. If the value was SQL <code>NULL</code>,
* the value <code>null</code> is returned.
* @exception SQLException if parameterName does not correspond to a named
* parameter; if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
NClob getNClob (String parameterName) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.SQLXML</code> object. The driver converts this to an
* <code>SQL XML</code> value when it sends it to the database.
*
* @param parameterName the name of the parameter
* @param xmlObject a <code>SQLXML</code> object that maps an <code>SQL XML</code> value
* @throws SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs;
* this method is called on a closed <code>CallableStatement</code> or
* the <code>java.xml.transform.Result</code>,
* <code>Writer</code> or <code>OutputStream</code> has not been closed for the <code>SQLXML</code> object
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
*
* @since 1.6
*/
void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated <code>SQL XML</code> parameter as a
* <code>java.sql.SQLXML</code> object in the Java programming language.
* @param parameterIndex index of the first parameter is 1, the second is 2, ...
* @return a <code>SQLXML</code> object that maps an <code>SQL XML</code> value
* @throws SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
SQLXML getSQLXML(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated <code>SQL XML</code> parameter as a
* <code>java.sql.SQLXML</code> object in the Java programming language.
* @param parameterName the name of the parameter
* @return a <code>SQLXML</code> object that maps an <code>SQL XML</code> value
* @throws SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
SQLXML getSQLXML(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated <code>NCHAR</code>,
* <code>NVARCHAR</code>
* or <code>LONGNVARCHAR</code> parameter as
* a <code>String</code> in the Java programming language.
* <p>
* For the fixed-length type JDBC <code>NCHAR</code>,
* the <code>String</code> object
* returned has exactly the same value the SQL
* <code>NCHAR</code> value had in the
* database, including any padding added by the database.
*
* @param parameterIndex index of the first parameter is 1, the second is 2, ...
* @return a <code>String</code> object that maps an
* <code>NCHAR</code>, <code>NVARCHAR</code> or <code>LONGNVARCHAR</code> value
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
* @see #setNString
*/
String getNString(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated <code>NCHAR</code>,
* <code>NVARCHAR</code>
* or <code>LONGNVARCHAR</code> parameter as
* a <code>String</code> in the Java programming language.
* <p>
* For the fixed-length type JDBC <code>NCHAR</code>,
* the <code>String</code> object
* returned has exactly the same value the SQL
* <code>NCHAR</code> value had in the
* database, including any padding added by the database.
*
* @param parameterName the name of the parameter
* @return a <code>String</code> object that maps an
* <code>NCHAR</code>, <code>NVARCHAR</code> or <code>LONGNVARCHAR</code> value
* @exception SQLException if parameterName does not correspond to a named
* parameter;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
* @see #setNString
*/
String getNString(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated parameter as a
* <code>java.io.Reader</code> object in the Java programming language.
* It is intended for use when
* accessing <code>NCHAR</code>,<code>NVARCHAR</code>
* and <code>LONGNVARCHAR</code> parameters.
*
* @return a <code>java.io.Reader</code> object that contains the parameter
* value; if the value is SQL <code>NULL</code>, the value returned is
* <code>null</code> in the Java programming language.
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @exception SQLException if the parameterIndex is not valid;
* if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
java.io.Reader getNCharacterStream(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated parameter as a
* <code>java.io.Reader</code> object in the Java programming language.
* It is intended for use when
* accessing <code>NCHAR</code>,<code>NVARCHAR</code>
* and <code>LONGNVARCHAR</code> parameters.
*
* @param parameterName the name of the parameter
* @return a <code>java.io.Reader</code> object that contains the parameter
* value; if the value is SQL <code>NULL</code>, the value returned is
* <code>null</code> in the Java programming language
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
java.io.Reader getNCharacterStream(String parameterName) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated parameter as a
* <code>java.io.Reader</code> object in the Java programming language.
*
* @return a <code>java.io.Reader</code> object that contains the parameter
* value; if the value is SQL <code>NULL</code>, the value returned is
* <code>null</code> in the Java programming language.
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @exception SQLException if the parameterIndex is not valid; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @since 1.6
*/
java.io.Reader getCharacterStream(int parameterIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated parameter as a
* <code>java.io.Reader</code> object in the Java programming language.
*
* @param parameterName the name of the parameter
* @return a <code>java.io.Reader</code> object that contains the parameter
* value; if the value is SQL <code>NULL</code>, the value returned is
* <code>null</code> in the Java programming language
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
java.io.Reader getCharacterStream(String parameterName) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Blob</code> object.
* The driver converts this to an SQL <code>BLOB</code> value when it
* sends it to the database.
*
* @param parameterName the name of the parameter
* @param x a <code>Blob</code> object that maps an SQL <code>BLOB</code> value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void setBlob (String parameterName, Blob x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Clob</code> object.
* The driver converts this to an SQL <code>CLOB</code> value when it
* sends it to the database.
*
* @param parameterName the name of the parameter
* @param x a <code>Clob</code> object that maps an SQL <code>CLOB</code> value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void setClob (String parameterName, Clob x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given input stream, which will have
* the specified number of bytes.
* When a very large ASCII value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code>. Data will be read from the stream
* as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from ASCII to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterName the name of the parameter
* @param x the Java input stream that contains the ASCII parameter value
* @param length the number of bytes in the stream
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void setAsciiStream(String parameterName, java.io.InputStream x, long length)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given input stream, which will have
* the specified number of bytes.
* When a very large binary value is input to a <code>LONGVARBINARY</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code> object. The data will be read from the stream
* as needed until end-of-file is reached.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterName the name of the parameter
* @param x the java input stream which contains the binary parameter value
* @param length the number of bytes in the stream
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void setBinaryStream(String parameterName, java.io.InputStream x,
long length) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>Reader</code>
* object, which is the given number of characters long.
* When a very large UNICODE value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.Reader</code> object. The data will be read from the stream
* as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterName the name of the parameter
* @param reader the <code>java.io.Reader</code> object that
* contains the UNICODE data used as the designated parameter
* @param length the number of characters in the stream
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void setCharacterStream(String parameterName,
java.io.Reader reader,
long length) throws SQLException;
//--
/** {@collect.stats}
* Sets the designated parameter to the given input stream.
* When a very large ASCII value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code>. Data will be read from the stream
* as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from ASCII to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setAsciiStream</code> which takes a length parameter.
*
* @param parameterName the name of the parameter
* @param x the Java input stream that contains the ASCII parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setAsciiStream(String parameterName, java.io.InputStream x)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given input stream.
* When a very large binary value is input to a <code>LONGVARBINARY</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code> object. The data will be read from the
* stream as needed until end-of-file is reached.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setBinaryStream</code> which takes a length parameter.
*
* @param parameterName the name of the parameter
* @param x the java input stream which contains the binary parameter value
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setBinaryStream(String parameterName, java.io.InputStream x)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>Reader</code>
* object.
* When a very large UNICODE value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.Reader</code> object. The data will be read from the stream
* as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setCharacterStream</code> which takes a length parameter.
*
* @param parameterName the name of the parameter
* @param reader the <code>java.io.Reader</code> object that contains the
* Unicode data
* @exception SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setCharacterStream(String parameterName,
java.io.Reader reader) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>Reader</code> object. The
* <code>Reader</code> reads the data till end-of-file is reached. The
* driver does the necessary conversion from Java character format to
* the national character set in the database.
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setNCharacterStream</code> which takes a length parameter.
*
* @param parameterName the name of the parameter
* @param value the parameter value
* @throws SQLException if parameterName does not correspond to a named
* parameter; if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; if a database access error occurs; or
* this method is called on a closed <code>CallableStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setNCharacterStream(String parameterName, Reader value) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>Reader</code> object.
* This method differs from the <code>setCharacterStream (int, Reader)</code> method
* because it informs the driver that the parameter value should be sent to
* the server as a <code>CLOB</code>. When the <code>setCharacterStream</code> method is used, the
* driver may have to do extra work to determine whether the parameter
* data should be send to the server as a <code>LONGVARCHAR</code> or a <code>CLOB</code>
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setClob</code> which takes a length parameter.
*
* @param parameterName the name of the parameter
* @param reader An object that contains the data to set the parameter value to.
* @throws SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or this method is called on
* a closed <code>CallableStatement</code>
*
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setClob(String parameterName, Reader reader)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>InputStream</code> object.
* This method differs from the <code>setBinaryStream (int, InputStream)</code>
* method because it informs the driver that the parameter value should be
* sent to the server as a <code>BLOB</code>. When the <code>setBinaryStream</code> method is used,
* the driver may have to do extra work to determine whether the parameter
* data should be send to the server as a <code>LONGVARBINARY</code> or a <code>BLOB</code>
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setBlob</code> which takes a length parameter.
*
* @param parameterName the name of the parameter
* @param inputStream An object that contains the data to set the parameter
* value to.
* @throws SQLException if parameterName does not correspond to a named
* parameter; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
*
* @since 1.6
*/
void setBlob(String parameterName, InputStream inputStream)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>Reader</code> object.
* This method differs from the <code>setCharacterStream (int, Reader)</code> method
* because it informs the driver that the parameter value should be sent to
* the server as a <code>NCLOB</code>. When the <code>setCharacterStream</code> method is used, the
* driver may have to do extra work to determine whether the parameter
* data should be send to the server as a <code>LONGNVARCHAR</code> or a <code>NCLOB</code>
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setNClob</code> which takes a length parameter.
*
* @param parameterName the name of the parameter
* @param reader An object that contains the data to set the parameter value to.
* @throws SQLException if parameterName does not correspond to a named
* parameter; if the driver does not support national character sets;
* if the driver can detect that a data conversion
* error could occur; if a database access error occurs or
* this method is called on a closed <code>CallableStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
*
* @since 1.6
*/
void setNClob(String parameterName, Reader reader)
throws SQLException;
}
|
Java
|
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* The subclass of {@link SQLException} thrown when an instance where a retry
* of the same operation would fail unless the cause of the <code>SQLException</code>
* is corrected.
*<p>
*
* @since 1.6
*/
public class SQLNonTransientException extends java.sql.SQLException {
/** {@collect.stats}
* Constructs a <code>SQLNonTransientException</code> object.
* The <code>reason</code>, <code>SQLState</code> are initialized
* to <code>null</code> and the vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
*
* @since 1.6
*/
public SQLNonTransientException() {
super();
}
/** {@collect.stats}
* Constructs a <code>SQLNonTransientException</code> object
* with a given <code>reason</code>. The <code>SQLState</code>
* is initialized to <code>null</code> and the vender code is initialized
* to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
*
* @param reason a description of the exception
* @since 1.6
*/
public SQLNonTransientException(String reason) {
super(reason);
}
/** {@collect.stats}
* Constructs a <code>SQLNonTransientException</code> object
* with a given <code>reason</code> and <code>SQLState</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
* is initialized to 0.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @since 1.6
*/
public SQLNonTransientException(String reason, String SQLState) {
super(reason,SQLState);
}
/** {@collect.stats}
* Constructs a <code>SQLNonTransientException</code> object
* with a given <code>reason</code>, <code>SQLState</code> and
* <code>vendorCode</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor specific exception code
* @since 1.6
*/
public SQLNonTransientException(String reason, String SQLState, int vendorCode) {
super(reason,SQLState,vendorCode);
}
/** {@collect.stats}
* Constructs a <code>SQLNonTransientException</code> object
* with a given <code>cause</code>.
* The <code>SQLState</code> is initialized
* to <code>null</code> and the vendor code is initialized to 0.
* The <code>reason</code> is initialized to <code>null</code> if
* <code>cause==null</code> or to <code>cause.toString()</code> if
* <code>cause!=null</code>.
* <p>
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLNonTransientException(Throwable cause) {
super(cause);
}
/** {@collect.stats}
* Constructs a <code>SQLTransientException</code> object
* with a given
* <code>reason</code> and <code>cause</code>.
* The <code>SQLState</code> is initialized to <code>null</code>
* and the vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLNonTransientException(String reason, Throwable cause) {
super(reason,cause);
}
/** {@collect.stats}
* Constructs a <code>SQLNonTransientException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code> and <code>cause</code>.
* The vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLNonTransientException(String reason, String SQLState, Throwable cause) {
super(reason,SQLState,cause);
}
/** {@collect.stats}
* Constructs a <code>SQLNonTransientException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
* and <code>cause</code>.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor-specific exception code
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLNonTransientException(String reason, String SQLState, int vendorCode, Throwable cause) {
super(reason,SQLState,vendorCode,cause);
}
private static final long serialVersionUID = -9104382843534716547L;
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
import java.math.BigDecimal;
import java.util.Calendar;
import java.io.Reader;
import java.io.InputStream;
/** {@collect.stats}
* A table of data representing a database result set, which
* is usually generated by executing a statement that queries the database.
*
* <P>A <code>ResultSet</code> object maintains a cursor pointing
* to its current row of data. Initially the cursor is positioned
* before the first row. The <code>next</code> method moves the
* cursor to the next row, and because it returns <code>false</code>
* when there are no more rows in the <code>ResultSet</code> object,
* it can be used in a <code>while</code> loop to iterate through
* the result set.
* <P>
* A default <code>ResultSet</code> object is not updatable and
* has a cursor that moves forward only. Thus, you can
* iterate through it only once and only from the first row to the
* last row. It is possible to
* produce <code>ResultSet</code> objects that are scrollable and/or
* updatable. The following code fragment, in which <code>con</code>
* is a valid <code>Connection</code> object, illustrates how to make
* a result set that is scrollable and insensitive to updates by others, and
* that is updatable. See <code>ResultSet</code> fields for other
* options.
* <PRE>
*
* Statement stmt = con.createStatement(
* ResultSet.TYPE_SCROLL_INSENSITIVE,
* ResultSet.CONCUR_UPDATABLE);
* ResultSet rs = stmt.executeQuery("SELECT a, b FROM TABLE2");
* // rs will be scrollable, will not show changes made by others,
* // and will be updatable
*
* </PRE>
* The <code>ResultSet</code> interface provides
* <i>getter</i> methods (<code>getBoolean</code>, <code>getLong</code>, and so on)
* for retrieving column values from the current row.
* Values can be retrieved using either the index number of the
* column or the name of the column. In general, using the
* column index will be more efficient. Columns are numbered from 1.
* For maximum portability, result set columns within each row should be
* read in left-to-right order, and each column should be read only once.
*
* <P>For the getter methods, a JDBC driver attempts
* to convert the underlying data to the Java type specified in the
* getter method and returns a suitable Java value. The JDBC specification
* has a table showing the allowable mappings from SQL types to Java types
* that can be used by the <code>ResultSet</code> getter methods.
* <P>
* <P>Column names used as input to getter methods are case
* insensitive. When a getter method is called with
* a column name and several columns have the same name,
* the value of the first matching column will be returned.
* The column name option is
* designed to be used when column names are used in the SQL
* query that generated the result set.
* For columns that are NOT explicitly named in the query, it
* is best to use column numbers. If column names are used, the
* programmer should take care to guarantee that they uniquely refer to
* the intended columns, which can be assured with the SQL <i>AS</i> clause.
* <P>
* A set of updater methods were added to this interface
* in the JDBC 2.0 API (Java<sup><font size=-2>TM</font></sup> 2 SDK,
* Standard Edition, version 1.2). The comments regarding parameters
* to the getter methods also apply to parameters to the
* updater methods.
*<P>
* The updater methods may be used in two ways:
* <ol>
* <LI>to update a column value in the current row. In a scrollable
* <code>ResultSet</code> object, the cursor can be moved backwards
* and forwards, to an absolute position, or to a position
* relative to the current row.
* The following code fragment updates the <code>NAME</code> column
* in the fifth row of the <code>ResultSet</code> object
* <code>rs</code> and then uses the method <code>updateRow</code>
* to update the data source table from which <code>rs</code> was derived.
* <PRE>
*
* rs.absolute(5); // moves the cursor to the fifth row of rs
* rs.updateString("NAME", "AINSWORTH"); // updates the
* // <code>NAME</code> column of row 5 to be <code>AINSWORTH</code>
* rs.updateRow(); // updates the row in the data source
*
* </PRE>
* <LI>to insert column values into the insert row. An updatable
* <code>ResultSet</code> object has a special row associated with
* it that serves as a staging area for building a row to be inserted.
* The following code fragment moves the cursor to the insert row, builds
* a three-column row, and inserts it into <code>rs</code> and into
* the data source table using the method <code>insertRow</code>.
* <PRE>
*
* rs.moveToInsertRow(); // moves cursor to the insert row
* rs.updateString(1, "AINSWORTH"); // updates the
* // first column of the insert row to be <code>AINSWORTH</code>
* rs.updateInt(2,35); // updates the second column to be <code>35</code>
* rs.updateBoolean(3, true); // updates the third column to <code>true</code>
* rs.insertRow();
* rs.moveToCurrentRow();
*
* </PRE>
* </ol>
* <P>A <code>ResultSet</code> object is automatically closed when the
* <code>Statement</code> object that
* generated it is closed, re-executed, or used
* to retrieve the next result from a sequence of multiple results.
*
* <P>The number, types and properties of a <code>ResultSet</code>
* object's columns are provided by the <code>ResulSetMetaData</code>
* object returned by the <code>ResultSet.getMetaData</code> method.
*
* @see Statement#executeQuery
* @see Statement#getResultSet
* @see ResultSetMetaData
*/
public interface ResultSet extends Wrapper {
/** {@collect.stats}
* Moves the cursor froward one row from its current position.
* A <code>ResultSet</code> cursor is initially positioned
* before the first row; the first call to the method
* <code>next</code> makes the first row the current row; the
* second call makes the second row the current row, and so on.
* <p>
* When a call to the <code>next</code> method returns <code>false</code>,
* the cursor is positioned after the last row. Any
* invocation of a <code>ResultSet</code> method which requires a
* current row will result in a <code>SQLException</code> being thrown.
* If the result set type is <code>TYPE_FORWARD_ONLY</code>, it is vendor specified
* whether their JDBC driver implementation will return <code>false</code> or
* throw an <code>SQLException</code> on a
* subsequent call to <code>next</code>.
*
* <P>If an input stream is open for the current row, a call
* to the method <code>next</code> will
* implicitly close it. A <code>ResultSet</code> object's
* warning chain is cleared when a new row is read.
*
* @return <code>true</code> if the new current row is valid;
* <code>false</code> if there are no more rows
* @exception SQLException if a database access error occurs or this method is
* called on a closed result set
*/
boolean next() throws SQLException;
/** {@collect.stats}
* Releases this <code>ResultSet</code> object's database and
* JDBC resources immediately instead of waiting for
* this to happen when it is automatically closed.
*
* <P>The closing of a <code>ResultSet</code> object does <strong>not</strong> close the <code>Blob</code>,
* <code>Clob</code> or <code>NClob</code> objects created by the <code>ResultSet</code>. <code>Blob</code>,
* <code>Clob</code> or <code>NClob</code> objects remain valid for at least the duration of the
* transaction in which they are creataed, unless their <code>free</code> method is invoked.
*<p>
* When a <code>ResultSet</code> is closed, any <code>ResultSetMetaData</code>
* instances that were created by calling the <code>getMetaData</code>
* method remain accessible.
*
* <P><B>Note:</B> A <code>ResultSet</code> object
* is automatically closed by the
* <code>Statement</code> object that generated it when
* that <code>Statement</code> object is closed,
* re-executed, or is used to retrieve the next result from a
* sequence of multiple results.
*<p>
* Calling the method <code>close</code> on a <code>ResultSet</code>
* object that is already closed is a no-op.
* <P>
* <p>
*
* @exception SQLException if a database access error occurs
*/
void close() throws SQLException;
/** {@collect.stats}
* Reports whether
* the last column read had a value of SQL <code>NULL</code>.
* Note that you must first call one of the getter methods
* on a column to try to read its value and then call
* the method <code>wasNull</code> to see if the value read was
* SQL <code>NULL</code>.
*
* @return <code>true</code> if the last column value read was SQL
* <code>NULL</code> and <code>false</code> otherwise
* @exception SQLException if a database access error occurs or this method is
* called on a closed result set
*/
boolean wasNull() throws SQLException;
// Methods for accessing results by column index
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>String</code> in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
String getString(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>boolean</code> in the Java programming language.
*
* <P>If the designated column has a datatype of CHAR or VARCHAR
* and contains a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT
* and contains a 0, a value of <code>false</code> is returned. If the designated column has a datatype
* of CHAR or VARCHAR
* and contains a "1" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT
* and contains a 1, a value of <code>true</code> is returned.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>false</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
boolean getBoolean(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>byte</code> in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>0</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
byte getByte(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>short</code> in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>0</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
short getShort(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* an <code>int</code> in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>0</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
int getInt(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>long</code> in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>0</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
long getLong(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>float</code> in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>0</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
float getFloat(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>double</code> in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>0</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
double getDouble(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>java.sql.BigDecimal</code> in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param scale the number of digits to the right of the decimal point
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @deprecated
*/
BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>byte</code> array in the Java programming language.
* The bytes represent the raw values returned by the driver.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
byte[] getBytes(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>java.sql.Date</code> object in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
java.sql.Date getDate(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>java.sql.Time</code> object in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
java.sql.Time getTime(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>java.sql.Timestamp</code> object in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
java.sql.Timestamp getTimestamp(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a stream of ASCII characters. The value can then be read in chunks from the
* stream. This method is particularly
* suitable for retrieving large <char>LONGVARCHAR</char> values.
* The JDBC driver will
* do any necessary conversion from the database format into ASCII.
*
* <P><B>Note:</B> All the data in the returned stream must be
* read prior to getting the value of any other column. The next
* call to a getter method implicitly closes the stream. Also, a
* stream may return <code>0</code> when the method
* <code>InputStream.available</code>
* is called whether there is data available or not.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return a Java input stream that delivers the database column value
* as a stream of one-byte ASCII characters;
* if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
java.io.InputStream getAsciiStream(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* as a stream of two-byte 3 characters. The first byte is
* the high byte; the second byte is the low byte.
*
* The value can then be read in chunks from the
* stream. This method is particularly
* suitable for retrieving large <code>LONGVARCHAR</code>values. The
* JDBC driver will do any necessary conversion from the database
* format into Unicode.
*
* <P><B>Note:</B> All the data in the returned stream must be
* read prior to getting the value of any other column. The next
* call to a getter method implicitly closes the stream.
* Also, a stream may return <code>0</code> when the method
* <code>InputStream.available</code>
* is called, whether there is data available or not.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return a Java input stream that delivers the database column value
* as a stream of two-byte Unicode characters;
* if the value is SQL <code>NULL</code>, the value returned is
* <code>null</code>
*
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @deprecated use <code>getCharacterStream</code> in place of
* <code>getUnicodeStream</code>
*/
java.io.InputStream getUnicodeStream(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a stream of
* uninterpreted bytes. The value can then be read in chunks from the
* stream. This method is particularly
* suitable for retrieving large <code>LONGVARBINARY</code> values.
*
* <P><B>Note:</B> All the data in the returned stream must be
* read prior to getting the value of any other column. The next
* call to a getter method implicitly closes the stream. Also, a
* stream may return <code>0</code> when the method
* <code>InputStream.available</code>
* is called whether there is data available or not.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return a Java input stream that delivers the database column value
* as a stream of uninterpreted bytes;
* if the value is SQL <code>NULL</code>, the value returned is
* <code>null</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
java.io.InputStream getBinaryStream(int columnIndex)
throws SQLException;
// Methods for accessing results by column label
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>String</code> in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
String getString(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>boolean</code> in the Java programming language.
*
* <P>If the designated column has a datatype of CHAR or VARCHAR
* and contains a "0" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT
* and contains a 0, a value of <code>false</code> is returned. If the designated column has a datatype
* of CHAR or VARCHAR
* and contains a "1" or has a datatype of BIT, TINYINT, SMALLINT, INTEGER or BIGINT
* and contains a 1, a value of <code>true</code> is returned.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>false</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
boolean getBoolean(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>byte</code> in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>0</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
byte getByte(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>short</code> in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>0</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
short getShort(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* an <code>int</code> in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>0</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
int getInt(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>long</code> in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>0</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
long getLong(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>float</code> in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>0</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
float getFloat(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>double</code> in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>0</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
double getDouble(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>java.math.BigDecimal</code> in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param scale the number of digits to the right of the decimal point
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @deprecated
*/
BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>byte</code> array in the Java programming language.
* The bytes represent the raw values returned by the driver.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
byte[] getBytes(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>java.sql.Date</code> object in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
java.sql.Date getDate(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>java.sql.Time</code> object in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value;
* if the value is SQL <code>NULL</code>,
* the value returned is <code>null</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
java.sql.Time getTime(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>java.sql.Timestamp</code> object in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
java.sql.Timestamp getTimestamp(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a stream of
* ASCII characters. The value can then be read in chunks from the
* stream. This method is particularly
* suitable for retrieving large <code>LONGVARCHAR</code> values.
* The JDBC driver will
* do any necessary conversion from the database format into ASCII.
*
* <P><B>Note:</B> All the data in the returned stream must be
* read prior to getting the value of any other column. The next
* call to a getter method implicitly closes the stream. Also, a
* stream may return <code>0</code> when the method <code>available</code>
* is called whether there is data available or not.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return a Java input stream that delivers the database column value
* as a stream of one-byte ASCII characters.
* If the value is SQL <code>NULL</code>,
* the value returned is <code>null</code>.
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
java.io.InputStream getAsciiStream(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a stream of two-byte
* Unicode characters. The first byte is the high byte; the second
* byte is the low byte.
*
* The value can then be read in chunks from the
* stream. This method is particularly
* suitable for retrieving large <code>LONGVARCHAR</code> values.
* The JDBC technology-enabled driver will
* do any necessary conversion from the database format into Unicode.
*
* <P><B>Note:</B> All the data in the returned stream must be
* read prior to getting the value of any other column. The next
* call to a getter method implicitly closes the stream.
* Also, a stream may return <code>0</code> when the method
* <code>InputStream.available</code> is called, whether there
* is data available or not.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return a Java input stream that delivers the database column value
* as a stream of two-byte Unicode characters.
* If the value is SQL <code>NULL</code>, the value returned
* is <code>null</code>.
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @deprecated use <code>getCharacterStream</code> instead
*/
java.io.InputStream getUnicodeStream(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a stream of uninterpreted
* <code>byte</code>s.
* The value can then be read in chunks from the
* stream. This method is particularly
* suitable for retrieving large <code>LONGVARBINARY</code>
* values.
*
* <P><B>Note:</B> All the data in the returned stream must be
* read prior to getting the value of any other column. The next
* call to a getter method implicitly closes the stream. Also, a
* stream may return <code>0</code> when the method <code>available</code>
* is called whether there is data available or not.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return a Java input stream that delivers the database column value
* as a stream of uninterpreted bytes;
* if the value is SQL <code>NULL</code>, the result is <code>null</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
java.io.InputStream getBinaryStream(String columnLabel)
throws SQLException;
// Advanced features:
/** {@collect.stats}
* Retrieves the first warning reported by calls on this
* <code>ResultSet</code> object.
* Subsequent warnings on this <code>ResultSet</code> object
* will be chained to the <code>SQLWarning</code> object that
* this method returns.
*
* <P>The warning chain is automatically cleared each time a new
* row is read. This method may not be called on a <code>ResultSet</code>
* object that has been closed; doing so will cause an
* <code>SQLException</code> to be thrown.
* <P>
* <B>Note:</B> This warning chain only covers warnings caused
* by <code>ResultSet</code> methods. Any warning caused by
* <code>Statement</code> methods
* (such as reading OUT parameters) will be chained on the
* <code>Statement</code> object.
*
* @return the first <code>SQLWarning</code> object reported or
* <code>null</code> if there are none
* @exception SQLException if a database access error occurs or this method is
* called on a closed result set
*/
SQLWarning getWarnings() throws SQLException;
/** {@collect.stats}
* Clears all warnings reported on this <code>ResultSet</code> object.
* After this method is called, the method <code>getWarnings</code>
* returns <code>null</code> until a new warning is
* reported for this <code>ResultSet</code> object.
*
* @exception SQLException if a database access error occurs or this method is
* called on a closed result set
*/
void clearWarnings() throws SQLException;
/** {@collect.stats}
* Retrieves the name of the SQL cursor used by this <code>ResultSet</code>
* object.
*
* <P>In SQL, a result table is retrieved through a cursor that is
* named. The current row of a result set can be updated or deleted
* using a positioned update/delete statement that references the
* cursor name. To insure that the cursor has the proper isolation
* level to support update, the cursor's <code>SELECT</code> statement
* should be of the form <code>SELECT FOR UPDATE</code>. If
* <code>FOR UPDATE</code> is omitted, the positioned updates may fail.
*
* <P>The JDBC API supports this SQL feature by providing the name of the
* SQL cursor used by a <code>ResultSet</code> object.
* The current row of a <code>ResultSet</code> object
* is also the current row of this SQL cursor.
*
* @return the SQL name for this <code>ResultSet</code> object's cursor
* @exception SQLException if a database access error occurs or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
*/
String getCursorName() throws SQLException;
/** {@collect.stats}
* Retrieves the number, types and properties of
* this <code>ResultSet</code> object's columns.
*
* @return the description of this <code>ResultSet</code> object's columns
* @exception SQLException if a database access error occurs or this method is
* called on a closed result set
*/
ResultSetMetaData getMetaData() throws SQLException;
/** {@collect.stats}
* <p>Gets the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* an <code>Object</code> in the Java programming language.
*
* <p>This method will return the value of the given column as a
* Java object. The type of the Java object will be the default
* Java object type corresponding to the column's SQL type,
* following the mapping for built-in types specified in the JDBC
* specification. If the value is an SQL <code>NULL</code>,
* the driver returns a Java <code>null</code>.
*
* <p>This method may also be used to read database-specific
* abstract data types.
*
* In the JDBC 2.0 API, the behavior of method
* <code>getObject</code> is extended to materialize
* data of SQL user-defined types.
* <p>
* If <code>Connection.getTypeMap</code> does not throw a
* <code>SQLFeatureNotSupportedException</code>,
* then when a column contains a structured or distinct value,
* the behavior of this method is as
* if it were a call to: <code>getObject(columnIndex,
* this.getStatement().getConnection().getTypeMap())</code>.
*
* If <code>Connection.getTypeMap</code> does throw a
* <code>SQLFeatureNotSupportedException</code>,
* then structured values are not supported, and distinct values
* are mapped to the default Java class as determined by the
* underlying SQL type of the DISTINCT type.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return a <code>java.lang.Object</code> holding the column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
Object getObject(int columnIndex) throws SQLException;
/** {@collect.stats}
* <p>Gets the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* an <code>Object</code> in the Java programming language.
*
* <p>This method will return the value of the given column as a
* Java object. The type of the Java object will be the default
* Java object type corresponding to the column's SQL type,
* following the mapping for built-in types specified in the JDBC
* specification. If the value is an SQL <code>NULL</code>,
* the driver returns a Java <code>null</code>.
* <P>
* This method may also be used to read database-specific
* abstract data types.
* <P>
* In the JDBC 2.0 API, the behavior of the method
* <code>getObject</code> is extended to materialize
* data of SQL user-defined types. When a column contains
* a structured or distinct value, the behavior of this method is as
* if it were a call to: <code>getObject(columnIndex,
* this.getStatement().getConnection().getTypeMap())</code>.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return a <code>java.lang.Object</code> holding the column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
*/
Object getObject(String columnLabel) throws SQLException;
//----------------------------------------------------------------
/** {@collect.stats}
* Maps the given <code>ResultSet</code> column label to its
* <code>ResultSet</code> column index.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column index of the given column name
* @exception SQLException if the <code>ResultSet</code> object
* does not contain a column labeled <code>columnLabel</code>, a database access error occurs
* or this method is called on a closed result set
*/
int findColumn(String columnLabel) throws SQLException;
//--------------------------JDBC 2.0-----------------------------------
//---------------------------------------------------------------------
// Getters and Setters
//---------------------------------------------------------------------
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a
* <code>java.io.Reader</code> object.
* @return a <code>java.io.Reader</code> object that contains the column
* value; if the value is SQL <code>NULL</code>, the value returned is
* <code>null</code> in the Java programming language.
* @param columnIndex the first column is 1, the second is 2, ...
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
* @since 1.2
*/
java.io.Reader getCharacterStream(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a
* <code>java.io.Reader</code> object.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return a <code>java.io.Reader</code> object that contains the column
* value; if the value is SQL <code>NULL</code>, the value returned is
* <code>null</code> in the Java programming language
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
* @since 1.2
*/
java.io.Reader getCharacterStream(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a
* <code>java.math.BigDecimal</code> with full precision.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value (full precision);
* if the value is SQL <code>NULL</code>, the value returned is
* <code>null</code> in the Java programming language.
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs or this method is
* called on a closed result set
* @since 1.2
*/
BigDecimal getBigDecimal(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a
* <code>java.math.BigDecimal</code> with full precision.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value (full precision);
* if the value is SQL <code>NULL</code>, the value returned is
* <code>null</code> in the Java programming language.
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs or this method is
* called on a closed result set
* @since 1.2
*
*/
BigDecimal getBigDecimal(String columnLabel) throws SQLException;
//---------------------------------------------------------------------
// Traversal/Positioning
//---------------------------------------------------------------------
/** {@collect.stats}
* Retrieves whether the cursor is before the first row in
* this <code>ResultSet</code> object.
* <p>
* <strong>Note:</strong>Support for the <code>isBeforeFirst</code> method
* is optional for <code>ResultSet</code>s with a result
* set type of <code>TYPE_FORWARD_ONLY</code>
*
* @return <code>true</code> if the cursor is before the first row;
* <code>false</code> if the cursor is at any other position or the
* result set contains no rows
* @exception SQLException if a database access error occurs or this method is
* called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
boolean isBeforeFirst() throws SQLException;
/** {@collect.stats}
* Retrieves whether the cursor is after the last row in
* this <code>ResultSet</code> object.
* <p>
* <strong>Note:</strong>Support for the <code>isAfterLast</code> method
* is optional for <code>ResultSet</code>s with a result
* set type of <code>TYPE_FORWARD_ONLY</code>
*
* @return <code>true</code> if the cursor is after the last row;
* <code>false</code> if the cursor is at any other position or the
* result set contains no rows
* @exception SQLException if a database access error occurs or this method is
* called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
boolean isAfterLast() throws SQLException;
/** {@collect.stats}
* Retrieves whether the cursor is on the first row of
* this <code>ResultSet</code> object.
* <p>
* <strong>Note:</strong>Support for the <code>isFirst</code> method
* is optional for <code>ResultSet</code>s with a result
* set type of <code>TYPE_FORWARD_ONLY</code>
*
* @return <code>true</code> if the cursor is on the first row;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs or this method is
* called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
boolean isFirst() throws SQLException;
/** {@collect.stats}
* Retrieves whether the cursor is on the last row of
* this <code>ResultSet</code> object.
* <strong>Note:</strong> Calling the method <code>isLast</code> may be expensive
* because the JDBC driver
* might need to fetch ahead one row in order to determine
* whether the current row is the last row in the result set.
* <p>
* <strong>Note:</strong> Support for the <code>isLast</code> method
* is optional for <code>ResultSet</code>s with a result
* set type of <code>TYPE_FORWARD_ONLY</code>
* @return <code>true</code> if the cursor is on the last row;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs or this method is
* called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
boolean isLast() throws SQLException;
/** {@collect.stats}
* Moves the cursor to the front of
* this <code>ResultSet</code> object, just before the
* first row. This method has no effect if the result set contains no rows.
*
* @exception SQLException if a database access error
* occurs; this method is called on a closed result set or the
* result set type is <code>TYPE_FORWARD_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void beforeFirst() throws SQLException;
/** {@collect.stats}
* Moves the cursor to the end of
* this <code>ResultSet</code> object, just after the
* last row. This method has no effect if the result set contains no rows.
* @exception SQLException if a database access error
* occurs; this method is called on a closed result set
* or the result set type is <code>TYPE_FORWARD_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void afterLast() throws SQLException;
/** {@collect.stats}
* Moves the cursor to the first row in
* this <code>ResultSet</code> object.
*
* @return <code>true</code> if the cursor is on a valid row;
* <code>false</code> if there are no rows in the result set
* @exception SQLException if a database access error
* occurs; this method is called on a closed result set
* or the result set type is <code>TYPE_FORWARD_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
boolean first() throws SQLException;
/** {@collect.stats}
* Moves the cursor to the last row in
* this <code>ResultSet</code> object.
*
* @return <code>true</code> if the cursor is on a valid row;
* <code>false</code> if there are no rows in the result set
* @exception SQLException if a database access error
* occurs; this method is called on a closed result set
* or the result set type is <code>TYPE_FORWARD_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
boolean last() throws SQLException;
/** {@collect.stats}
* Retrieves the current row number. The first row is number 1, the
* second number 2, and so on.
* <p>
* <strong>Note:</strong>Support for the <code>getRow</code> method
* is optional for <code>ResultSet</code>s with a result
* set type of <code>TYPE_FORWARD_ONLY</code>
*
* @return the current row number; <code>0</code> if there is no current row
* @exception SQLException if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
int getRow() throws SQLException;
/** {@collect.stats}
* Moves the cursor to the given row number in
* this <code>ResultSet</code> object.
*
* <p>If the row number is positive, the cursor moves to
* the given row number with respect to the
* beginning of the result set. The first row is row 1, the second
* is row 2, and so on.
*
* <p>If the given row number is negative, the cursor moves to
* an absolute row position with respect to
* the end of the result set. For example, calling the method
* <code>absolute(-1)</code> positions the
* cursor on the last row; calling the method <code>absolute(-2)</code>
* moves the cursor to the next-to-last row, and so on.
*
* <p>An attempt to position the cursor beyond the first/last row in
* the result set leaves the cursor before the first row or after
* the last row.
*
* <p><B>Note:</B> Calling <code>absolute(1)</code> is the same
* as calling <code>first()</code>. Calling <code>absolute(-1)</code>
* is the same as calling <code>last()</code>.
*
* @param row the number of the row to which the cursor should move.
* A positive number indicates the row number counting from the
* beginning of the result set; a negative number indicates the
* row number counting from the end of the result set
* @return <code>true</code> if the cursor is moved to a position in this
* <code>ResultSet</code> object;
* <code>false</code> if the cursor is before the first row or after the
* last row
* @exception SQLException if a database access error
* occurs; this method is called on a closed result set
* or the result set type is <code>TYPE_FORWARD_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
boolean absolute( int row ) throws SQLException;
/** {@collect.stats}
* Moves the cursor a relative number of rows, either positive or negative.
* Attempting to move beyond the first/last row in the
* result set positions the cursor before/after the
* the first/last row. Calling <code>relative(0)</code> is valid, but does
* not change the cursor position.
*
* <p>Note: Calling the method <code>relative(1)</code>
* is identical to calling the method <code>next()</code> and
* calling the method <code>relative(-1)</code> is identical
* to calling the method <code>previous()</code>.
*
* @param rows an <code>int</code> specifying the number of rows to
* move from the current row; a positive number moves the cursor
* forward; a negative number moves the cursor backward
* @return <code>true</code> if the cursor is on a row;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs; this method
* is called on a closed result set or the result set type is
* <code>TYPE_FORWARD_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
boolean relative( int rows ) throws SQLException;
/** {@collect.stats}
* Moves the cursor to the previous row in this
* <code>ResultSet</code> object.
*<p>
* When a call to the <code>previous</code> method returns <code>false</code>,
* the cursor is positioned before the first row. Any invocation of a
* <code>ResultSet</code> method which requires a current row will result in a
* <code>SQLException</code> being thrown.
*<p>
* If an input stream is open for the current row, a call to the method
* <code>previous</code> will implicitly close it. A <code>ResultSet</code>
* object's warning change is cleared when a new row is read.
*<p>
*
* @return <code>true</code> if the cursor is now positioned on a valid row;
* <code>false</code> if the cursor is positioned before the first row
* @exception SQLException if a database access error
* occurs; this method is called on a closed result set
* or the result set type is <code>TYPE_FORWARD_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
boolean previous() throws SQLException;
//---------------------------------------------------------------------
// Properties
//---------------------------------------------------------------------
/** {@collect.stats}
* The constant indicating that the rows in a result set will be
* processed in a forward direction; first-to-last.
* This constant is used by the method <code>setFetchDirection</code>
* as a hint to the driver, which the driver may ignore.
* @since 1.2
*/
int FETCH_FORWARD = 1000;
/** {@collect.stats}
* The constant indicating that the rows in a result set will be
* processed in a reverse direction; last-to-first.
* This constant is used by the method <code>setFetchDirection</code>
* as a hint to the driver, which the driver may ignore.
* @since 1.2
*/
int FETCH_REVERSE = 1001;
/** {@collect.stats}
* The constant indicating that the order in which rows in a
* result set will be processed is unknown.
* This constant is used by the method <code>setFetchDirection</code>
* as a hint to the driver, which the driver may ignore.
*/
int FETCH_UNKNOWN = 1002;
/** {@collect.stats}
* Gives a hint as to the direction in which the rows in this
* <code>ResultSet</code> object will be processed.
* The initial value is determined by the
* <code>Statement</code> object
* that produced this <code>ResultSet</code> object.
* The fetch direction may be changed at any time.
*
* @param direction an <code>int</code> specifying the suggested
* fetch direction; one of <code>ResultSet.FETCH_FORWARD</code>,
* <code>ResultSet.FETCH_REVERSE</code>, or
* <code>ResultSet.FETCH_UNKNOWN</code>
* @exception SQLException if a database access error occurs; this
* method is called on a closed result set or
* the result set type is <code>TYPE_FORWARD_ONLY</code> and the fetch
* direction is not <code>FETCH_FORWARD</code>
* @since 1.2
* @see Statement#setFetchDirection
* @see #getFetchDirection
*/
void setFetchDirection(int direction) throws SQLException;
/** {@collect.stats}
* Retrieves the fetch direction for this
* <code>ResultSet</code> object.
*
* @return the current fetch direction for this <code>ResultSet</code> object
* @exception SQLException if a database access error occurs
* or this method is called on a closed result set
* @since 1.2
* @see #setFetchDirection
*/
int getFetchDirection() throws SQLException;
/** {@collect.stats}
* Gives the JDBC driver a hint as to the number of rows that should
* be fetched from the database when more rows are needed for this
* <code>ResultSet</code> object.
* If the fetch size specified is zero, the JDBC driver
* ignores the value and is free to make its own best guess as to what
* the fetch size should be. The default value is set by the
* <code>Statement</code> object
* that created the result set. The fetch size may be changed at any time.
*
* @param rows the number of rows to fetch
* @exception SQLException if a database access error occurs; this method
* is called on a closed result set or the
* condition <code>rows >= 0 </code> is not satisfied
* @since 1.2
* @see #getFetchSize
*/
void setFetchSize(int rows) throws SQLException;
/** {@collect.stats}
* Retrieves the fetch size for this
* <code>ResultSet</code> object.
*
* @return the current fetch size for this <code>ResultSet</code> object
* @exception SQLException if a database access error occurs
* or this method is called on a closed result set
* @since 1.2
* @see #setFetchSize
*/
int getFetchSize() throws SQLException;
/** {@collect.stats}
* The constant indicating the type for a <code>ResultSet</code> object
* whose cursor may move only forward.
* @since 1.2
*/
int TYPE_FORWARD_ONLY = 1003;
/** {@collect.stats}
* The constant indicating the type for a <code>ResultSet</code> object
* that is scrollable but generally not sensitive to changes to the data
* that underlies the <code>ResultSet</code>.
* @since 1.2
*/
int TYPE_SCROLL_INSENSITIVE = 1004;
/** {@collect.stats}
* The constant indicating the type for a <code>ResultSet</code> object
* that is scrollable and generally sensitive to changes to the data
* that underlies the <code>ResultSet</code>.
* @since 1.2
*/
int TYPE_SCROLL_SENSITIVE = 1005;
/** {@collect.stats}
* Retrieves the type of this <code>ResultSet</code> object.
* The type is determined by the <code>Statement</code> object
* that created the result set.
*
* @return <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>,
* or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @exception SQLException if a database access error occurs
* or this method is called on a closed result set
* @since 1.2
*/
int getType() throws SQLException;
/** {@collect.stats}
* The constant indicating the concurrency mode for a
* <code>ResultSet</code> object that may NOT be updated.
* @since 1.2
*/
int CONCUR_READ_ONLY = 1007;
/** {@collect.stats}
* The constant indicating the concurrency mode for a
* <code>ResultSet</code> object that may be updated.
* @since 1.2
*/
int CONCUR_UPDATABLE = 1008;
/** {@collect.stats}
* Retrieves the concurrency mode of this <code>ResultSet</code> object.
* The concurrency used is determined by the
* <code>Statement</code> object that created the result set.
*
* @return the concurrency type, either
* <code>ResultSet.CONCUR_READ_ONLY</code>
* or <code>ResultSet.CONCUR_UPDATABLE</code>
* @exception SQLException if a database access error occurs
* or this method is called on a closed result set
* @since 1.2
*/
int getConcurrency() throws SQLException;
//---------------------------------------------------------------------
// Updates
//---------------------------------------------------------------------
/** {@collect.stats}
* Retrieves whether the current row has been updated. The value returned
* depends on whether or not the result set can detect updates.
* <p>
* <strong>Note:</strong> Support for the <code>rowUpdated</code> method is optional with a result set
* concurrency of <code>CONCUR_READ_ONLY</code>
* @return <code>true</code> if the current row is detected to
* have been visibly updated by the owner or another; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see DatabaseMetaData#updatesAreDetected
* @since 1.2
*/
boolean rowUpdated() throws SQLException;
/** {@collect.stats}
* Retrieves whether the current row has had an insertion.
* The value returned depends on whether or not this
* <code>ResultSet</code> object can detect visible inserts.
* <p>
* <strong>Note:</strong> Support for the <code>rowInserted</code> method is optional with a result set
* concurrency of <code>CONCUR_READ_ONLY</code>
* @return <code>true</code> if the current row is detected to
* have been inserted; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
*
* @see DatabaseMetaData#insertsAreDetected
* @since 1.2
*/
boolean rowInserted() throws SQLException;
/** {@collect.stats}
* Retrieves whether a row has been deleted. A deleted row may leave
* a visible "hole" in a result set. This method can be used to
* detect holes in a result set. The value returned depends on whether
* or not this <code>ResultSet</code> object can detect deletions.
* <p>
* <strong>Note:</strong> Support for the <code>rowDeleted</code> method is optional with a result set
* concurrency of <code>CONCUR_READ_ONLY</code>
* @return <code>true</code> if the current row is detected to
* have been deleted by the owner or another; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
*
* @see DatabaseMetaData#deletesAreDetected
* @since 1.2
*/
boolean rowDeleted() throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>null</code> value.
*
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code>
* or <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateNull(int columnIndex) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>boolean</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateBoolean(int columnIndex, boolean x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>byte</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateByte(int columnIndex, byte x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>short</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateShort(int columnIndex, short x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with an <code>int</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateInt(int columnIndex, int x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>long</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateLong(int columnIndex, long x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>float</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateFloat(int columnIndex, float x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>double</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateDouble(int columnIndex, double x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.math.BigDecimal</code>
* value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>String</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateString(int columnIndex, String x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>byte</code> array value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateBytes(int columnIndex, byte x[]) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Date</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateDate(int columnIndex, java.sql.Date x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Time</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateTime(int columnIndex, java.sql.Time x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Timestamp</code>
* value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateTimestamp(int columnIndex, java.sql.Timestamp x)
throws SQLException;
/** {@collect.stats}
* Updates the designated column with an ascii stream value, which will have
* the specified number of bytes.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @param length the length of the stream
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateAsciiStream(int columnIndex,
java.io.InputStream x,
int length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a binary stream value, which will have
* the specified number of bytes.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @param length the length of the stream
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateBinaryStream(int columnIndex,
java.io.InputStream x,
int length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a character stream value, which will have
* the specified number of bytes.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @param length the length of the stream
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateCharacterStream(int columnIndex,
java.io.Reader x,
int length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with an <code>Object</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*<p>
* If the second argument is an <code>InputStream</code> then the stream must contain
* the number of bytes specified by scaleOrLength. If the second argument is a
* <code>Reader</code> then the reader must contain the number of characters specified
* by scaleOrLength. If these conditions are not true the driver will generate a
* <code>SQLException</code> when the statement is executed.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @param scaleOrLength for an object of <code>java.math.BigDecimal</code> ,
* this is the number of digits after the decimal point. For
* Java Object types <code>InputStream</code> and <code>Reader</code>,
* this is the length
* of the data in the stream or reader. For all other types,
* this value will be ignored.
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateObject(int columnIndex, Object x, int scaleOrLength)
throws SQLException;
/** {@collect.stats}
* Updates the designated column with an <code>Object</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateObject(int columnIndex, Object x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>null</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateNull(String columnLabel) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>boolean</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateBoolean(String columnLabel, boolean x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>byte</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateByte(String columnLabel, byte x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>short</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateShort(String columnLabel, short x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with an <code>int</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateInt(String columnLabel, int x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>long</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateLong(String columnLabel, long x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>float </code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateFloat(String columnLabel, float x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>double</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateDouble(String columnLabel, double x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.BigDecimal</code>
* value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>String</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateString(String columnLabel, String x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a byte array value.
*
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code>
* or <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateBytes(String columnLabel, byte x[]) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Date</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateDate(String columnLabel, java.sql.Date x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Time</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateTime(String columnLabel, java.sql.Time x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Timestamp</code>
* value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateTimestamp(String columnLabel, java.sql.Timestamp x)
throws SQLException;
/** {@collect.stats}
* Updates the designated column with an ascii stream value, which will have
* the specified number of bytes.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @param length the length of the stream
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateAsciiStream(String columnLabel,
java.io.InputStream x,
int length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a binary stream value, which will have
* the specified number of bytes.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @param length the length of the stream
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateBinaryStream(String columnLabel,
java.io.InputStream x,
int length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a character stream value, which will have
* the specified number of bytes.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param reader the <code>java.io.Reader</code> object containing
* the new column value
* @param length the length of the stream
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateCharacterStream(String columnLabel,
java.io.Reader reader,
int length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with an <code>Object</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*<p>
* If the second argument is an <code>InputStream</code> then the stream must contain
* the number of bytes specified by scaleOrLength. If the second argument is a
* <code>Reader</code> then the reader must contain the number of characters specified
* by scaleOrLength. If these conditions are not true the driver will generate a
* <code>SQLException</code> when the statement is executed.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @param scaleOrLength for an object of <code>java.math.BigDecimal</code> ,
* this is the number of digits after the decimal point. For
* Java Object types <code>InputStream</code> and <code>Reader</code>,
* this is the length
* of the data in the stream or reader. For all other types,
* this value will be ignored.
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateObject(String columnLabel, Object x, int scaleOrLength)
throws SQLException;
/** {@collect.stats}
* Updates the designated column with an <code>Object</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateObject(String columnLabel, Object x) throws SQLException;
/** {@collect.stats}
* Inserts the contents of the insert row into this
* <code>ResultSet</code> object and into the database.
* The cursor must be on the insert row when this method is called.
*
* @exception SQLException if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>,
* this method is called on a closed result set,
* if this method is called when the cursor is not on the insert row,
* or if not all of non-nullable columns in
* the insert row have been given a non-null value
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void insertRow() throws SQLException;
/** {@collect.stats}
* Updates the underlying database with the new contents of the
* current row of this <code>ResultSet</code> object.
* This method cannot be called when the cursor is on the insert row.
*
* @exception SQLException if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>;
* this method is called on a closed result set or
* if this method is called when the cursor is on the insert row
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void updateRow() throws SQLException;
/** {@collect.stats}
* Deletes the current row from this <code>ResultSet</code> object
* and from the underlying database. This method cannot be called when
* the cursor is on the insert row.
*
* @exception SQLException if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>;
* this method is called on a closed result set
* or if this method is called when the cursor is on the insert row
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void deleteRow() throws SQLException;
/** {@collect.stats}
* Refreshes the current row with its most recent value in
* the database. This method cannot be called when
* the cursor is on the insert row.
*
* <P>The <code>refreshRow</code> method provides a way for an
* application to
* explicitly tell the JDBC driver to refetch a row(s) from the
* database. An application may want to call <code>refreshRow</code> when
* caching or prefetching is being done by the JDBC driver to
* fetch the latest value of a row from the database. The JDBC driver
* may actually refresh multiple rows at once if the fetch size is
* greater than one.
*
* <P> All values are refetched subject to the transaction isolation
* level and cursor sensitivity. If <code>refreshRow</code> is called after
* calling an updater method, but before calling
* the method <code>updateRow</code>, then the
* updates made to the row are lost. Calling the method
* <code>refreshRow</code> frequently will likely slow performance.
*
* @exception SQLException if a database access error
* occurs; this method is called on a closed result set;
* the result set type is <code>TYPE_FORWARD_ONLY</code> or if this
* method is called when the cursor is on the insert row
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method or this method is not supported for the specified result
* set type and result set concurrency.
* @since 1.2
*/
void refreshRow() throws SQLException;
/** {@collect.stats}
* Cancels the updates made to the current row in this
* <code>ResultSet</code> object.
* This method may be called after calling an
* updater method(s) and before calling
* the method <code>updateRow</code> to roll back
* the updates made to a row. If no updates have been made or
* <code>updateRow</code> has already been called, this method has no
* effect.
*
* @exception SQLException if a database access error
* occurs; this method is called on a closed result set;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or if this method is called when the cursor is
* on the insert row
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void cancelRowUpdates() throws SQLException;
/** {@collect.stats}
* Moves the cursor to the insert row. The current cursor position is
* remembered while the cursor is positioned on the insert row.
*
* The insert row is a special row associated with an updatable
* result set. It is essentially a buffer where a new row may
* be constructed by calling the updater methods prior to
* inserting the row into the result set.
*
* Only the updater, getter,
* and <code>insertRow</code> methods may be
* called when the cursor is on the insert row. All of the columns in
* a result set must be given a value each time this method is
* called before calling <code>insertRow</code>.
* An updater method must be called before a
* getter method can be called on a column value.
*
* @exception SQLException if a database access error occurs; this
* method is called on a closed result set
* or the result set concurrency is <code>CONCUR_READ_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void moveToInsertRow() throws SQLException;
/** {@collect.stats}
* Moves the cursor to the remembered cursor position, usually the
* current row. This method has no effect if the cursor is not on
* the insert row.
*
* @exception SQLException if a database access error occurs; this
* method is called on a closed result set
* or the result set concurrency is <code>CONCUR_READ_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
void moveToCurrentRow() throws SQLException;
/** {@collect.stats}
* Retrieves the <code>Statement</code> object that produced this
* <code>ResultSet</code> object.
* If the result set was generated some other way, such as by a
* <code>DatabaseMetaData</code> method, this method may return
* <code>null</code>.
*
* @return the <code>Statment</code> object that produced
* this <code>ResultSet</code> object or <code>null</code>
* if the result set was produced some other way
* @exception SQLException if a database access error occurs
* or this method is called on a closed result set
* @since 1.2
*/
Statement getStatement() throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as an <code>Object</code>
* in the Java programming language.
* If the value is an SQL <code>NULL</code>,
* the driver returns a Java <code>null</code>.
* This method uses the given <code>Map</code> object
* for the custom mapping of the
* SQL structured or distinct type that is being retrieved.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param map a <code>java.util.Map</code> object that contains the mapping
* from SQL type names to classes in the Java programming language
* @return an <code>Object</code> in the Java programming language
* representing the SQL value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Object getObject(int columnIndex, java.util.Map<String,Class<?>> map)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>Ref</code> object
* in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return a <code>Ref</code> object representing an SQL <code>REF</code>
* value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Ref getRef(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>Blob</code> object
* in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return a <code>Blob</code> object representing the SQL
* <code>BLOB</code> value in the specified column
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Blob getBlob(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>Clob</code> object
* in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return a <code>Clob</code> object representing the SQL
* <code>CLOB</code> value in the specified column
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Clob getClob(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as an <code>Array</code> object
* in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return an <code>Array</code> object representing the SQL
* <code>ARRAY</code> value in the specified column
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Array getArray(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as an <code>Object</code>
* in the Java programming language.
* If the value is an SQL <code>NULL</code>,
* the driver returns a Java <code>null</code>.
* This method uses the specified <code>Map</code> object for
* custom mapping if appropriate.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param map a <code>java.util.Map</code> object that contains the mapping
* from SQL type names to classes in the Java programming language
* @return an <code>Object</code> representing the SQL value in the
* specified column
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Object getObject(String columnLabel, java.util.Map<String,Class<?>> map)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>Ref</code> object
* in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return a <code>Ref</code> object representing the SQL <code>REF</code>
* value in the specified column
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Ref getRef(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>Blob</code> object
* in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return a <code>Blob</code> object representing the SQL <code>BLOB</code>
* value in the specified column
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Blob getBlob(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>Clob</code> object
* in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return a <code>Clob</code> object representing the SQL <code>CLOB</code>
* value in the specified column
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Clob getClob(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as an <code>Array</code> object
* in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return an <code>Array</code> object representing the SQL <code>ARRAY</code> value in
* the specified column
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Array getArray(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>java.sql.Date</code> object
* in the Java programming language.
* This method uses the given calendar to construct an appropriate millisecond
* value for the date if the underlying database does not store
* timezone information.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param cal the <code>java.util.Calendar</code> object
* to use in constructing the date
* @return the column value as a <code>java.sql.Date</code> object;
* if the value is SQL <code>NULL</code>,
* the value returned is <code>null</code> in the Java programming language
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @since 1.2
*/
java.sql.Date getDate(int columnIndex, Calendar cal) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>java.sql.Date</code> object
* in the Java programming language.
* This method uses the given calendar to construct an appropriate millisecond
* value for the date if the underlying database does not store
* timezone information.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param cal the <code>java.util.Calendar</code> object
* to use in constructing the date
* @return the column value as a <code>java.sql.Date</code> object;
* if the value is SQL <code>NULL</code>,
* the value returned is <code>null</code> in the Java programming language
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @since 1.2
*/
java.sql.Date getDate(String columnLabel, Calendar cal) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>java.sql.Time</code> object
* in the Java programming language.
* This method uses the given calendar to construct an appropriate millisecond
* value for the time if the underlying database does not store
* timezone information.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param cal the <code>java.util.Calendar</code> object
* to use in constructing the time
* @return the column value as a <code>java.sql.Time</code> object;
* if the value is SQL <code>NULL</code>,
* the value returned is <code>null</code> in the Java programming language
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @since 1.2
*/
java.sql.Time getTime(int columnIndex, Calendar cal) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>java.sql.Time</code> object
* in the Java programming language.
* This method uses the given calendar to construct an appropriate millisecond
* value for the time if the underlying database does not store
* timezone information.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param cal the <code>java.util.Calendar</code> object
* to use in constructing the time
* @return the column value as a <code>java.sql.Time</code> object;
* if the value is SQL <code>NULL</code>,
* the value returned is <code>null</code> in the Java programming language
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @since 1.2
*/
java.sql.Time getTime(String columnLabel, Calendar cal) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>java.sql.Timestamp</code> object
* in the Java programming language.
* This method uses the given calendar to construct an appropriate millisecond
* value for the timestamp if the underlying database does not store
* timezone information.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param cal the <code>java.util.Calendar</code> object
* to use in constructing the timestamp
* @return the column value as a <code>java.sql.Timestamp</code> object;
* if the value is SQL <code>NULL</code>,
* the value returned is <code>null</code> in the Java programming language
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @since 1.2
*/
java.sql.Timestamp getTimestamp(int columnIndex, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>java.sql.Timestamp</code> object
* in the Java programming language.
* This method uses the given calendar to construct an appropriate millisecond
* value for the timestamp if the underlying database does not store
* timezone information.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param cal the <code>java.util.Calendar</code> object
* to use in constructing the date
* @return the column value as a <code>java.sql.Timestamp</code> object;
* if the value is SQL <code>NULL</code>,
* the value returned is <code>null</code> in the Java programming language
* @exception SQLException if the columnLabel is not valid or
* if a database access error occurs
* or this method is called on a closed result set
* @since 1.2
*/
java.sql.Timestamp getTimestamp(String columnLabel, Calendar cal)
throws SQLException;
//-------------------------- JDBC 3.0 ----------------------------------------
/** {@collect.stats}
* The constant indicating that open <code>ResultSet</code> objects with this
* holdability will remain open when the current transaction is commited.
*
* @since 1.4
*/
int HOLD_CURSORS_OVER_COMMIT = 1;
/** {@collect.stats}
* The constant indicating that open <code>ResultSet</code> objects with this
* holdability will be closed when the current transaction is commited.
*
* @since 1.4
*/
int CLOSE_CURSORS_AT_COMMIT = 2;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>java.net.URL</code>
* object in the Java programming language.
*
* @param columnIndex the index of the column 1 is the first, 2 is the second,...
* @return the column value as a <code>java.net.URL</code> object;
* if the value is SQL <code>NULL</code>,
* the value returned is <code>null</code> in the Java programming language
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs; this method
* is called on a closed result set or if a URL is malformed
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
java.net.URL getURL(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>java.net.URL</code>
* object in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value as a <code>java.net.URL</code> object;
* if the value is SQL <code>NULL</code>,
* the value returned is <code>null</code> in the Java programming language
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs; this method
* is called on a closed result set or if a URL is malformed
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
java.net.URL getURL(String columnLabel) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Ref</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void updateRef(int columnIndex, java.sql.Ref x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Ref</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void updateRef(String columnLabel, java.sql.Ref x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Blob</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void updateBlob(int columnIndex, java.sql.Blob x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Blob</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void updateBlob(String columnLabel, java.sql.Blob x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Clob</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void updateClob(int columnIndex, java.sql.Clob x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Clob</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void updateClob(String columnLabel, java.sql.Clob x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Array</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void updateArray(int columnIndex, java.sql.Array x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.Array</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void updateArray(String columnLabel, java.sql.Array x) throws SQLException;
//------------------------- JDBC 4.0 -----------------------------------
/** {@collect.stats}
* Retrieves the value of the designated column in the current row of this
* <code>ResultSet</code> object as a <code>java.sql.RowId</code> object in the Java
* programming language.
*
* @param columnIndex the first column is 1, the second 2, ...
* @return the column value; if the value is a SQL <code>NULL</code> the
* value returned is <code>null</code>
* @throws SQLException if the columnIndex is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
RowId getRowId(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row of this
* <code>ResultSet</code> object as a <code>java.sql.RowId</code> object in the Java
* programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value ; if the value is a SQL <code>NULL</code> the
* value returned is <code>null</code>
* @throws SQLException if the columnLabel is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
RowId getRowId(String columnLabel) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>RowId</code> value. The updater
* methods are used to update column values in the current row or the insert
* row. The updater methods do not update the underlying database; instead
* the <code>updateRow</code> or <code>insertRow</code> methods are called
* to update the database.
*
* @param columnIndex the first column is 1, the second 2, ...
* @param x the column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateRowId(int columnIndex, RowId x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>RowId</code> value. The updater
* methods are used to update column values in the current row or the insert
* row. The updater methods do not update the underlying database; instead
* the <code>updateRow</code> or <code>insertRow</code> methods are called
* to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateRowId(String columnLabel, RowId x) throws SQLException;
/** {@collect.stats}
* Retrieves the holdability of this <code>ResultSet</code> object
* @return either <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
* @throws SQLException if a database access error occurs
* or this method is called on a closed result set
* @since 1.6
*/
int getHoldability() throws SQLException;
/** {@collect.stats}
* Retrieves whether this <code>ResultSet</code> object has been closed. A <code>ResultSet</code> is closed if the
* method close has been called on it, or if it is automatically closed.
*
* @return true if this <code>ResultSet</code> object is closed; false if it is still open
* @throws SQLException if a database access error occurs
* @since 1.6
*/
boolean isClosed() throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>String</code> value.
* It is intended for use when updating <code>NCHAR</code>,<code>NVARCHAR</code>
* and <code>LONGNVARCHAR</code> columns.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second 2, ...
* @param nString the value for the column to be updated
* @throws SQLException if the columnIndex is not valid;
* if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; this method is called on a closed result set;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or if a database access error occurs
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateNString(int columnIndex, String nString) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>String</code> value.
* It is intended for use when updating <code>NCHAR</code>,<code>NVARCHAR</code>
* and <code>LONGNVARCHAR</code> columns.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param nString the value for the column to be updated
* @throws SQLException if the columnLabel is not valid;
* if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; this method is called on a closed result set;
* the result set concurrency is <CODE>CONCUR_READ_ONLY</code>
* or if a database access error occurs
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateNString(String columnLabel, String nString) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.NClob</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second 2, ...
* @param nClob the value for the column to be updated
* @throws SQLException if the columnIndex is not valid;
* if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; this method is called on a closed result set;
* if a database access error occurs or
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateNClob(int columnIndex, NClob nClob) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.NClob</code> value.
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param nClob the value for the column to be updated
* @throws SQLException if the columnLabel is not valid;
* if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; this method is called on a closed result set;
* if a database access error occurs or
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateNClob(String columnLabel, NClob nClob) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>NClob</code> object
* in the Java programming language.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return a <code>NClob</code> object representing the SQL
* <code>NCLOB</code> value in the specified column
* @exception SQLException if the columnIndex is not valid;
* if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; this method is called on a closed result set
* or if a database access error occurs
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
NClob getNClob(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a <code>NClob</code> object
* in the Java programming language.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return a <code>NClob</code> object representing the SQL <code>NCLOB</code>
* value in the specified column
* @exception SQLException if the columnLabel is not valid;
* if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; this method is called on a closed result set
* or if a database access error occurs
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
NClob getNClob(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row of
* this <code>ResultSet</code> as a
* <code>java.sql.SQLXML</code> object in the Java programming language.
* @param columnIndex the first column is 1, the second is 2, ...
* @return a <code>SQLXML</code> object that maps an <code>SQL XML</code> value
* @throws SQLException if the columnIndex is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
SQLXML getSQLXML(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row of
* this <code>ResultSet</code> as a
* <code>java.sql.SQLXML</code> object in the Java programming language.
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return a <code>SQLXML</code> object that maps an <code>SQL XML</code> value
* @throws SQLException if the columnLabel is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
SQLXML getSQLXML(String columnLabel) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.SQLXML</code> value.
* The updater
* methods are used to update column values in the current row or the insert
* row. The updater methods do not update the underlying database; instead
* the <code>updateRow</code> or <code>insertRow</code> methods are called
* to update the database.
* <p>
*
* @param columnIndex the first column is 1, the second 2, ...
* @param xmlObject the value for the column to be updated
* @throws SQLException if the columnIndex is not valid;
* if a database access error occurs; this method
* is called on a closed result set;
* the <code>java.xml.transform.Result</code>,
* <code>Writer</code> or <code>OutputStream</code> has not been closed
* for the <code>SQLXML</code> object;
* if there is an error processing the XML value or
* the result set concurrency is <code>CONCUR_READ_ONLY</code>. The <code>getCause</code> method
* of the exception may provide a more detailed exception, for example, if the
* stream does not contain valid XML.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a <code>java.sql.SQLXML</code> value.
* The updater
* methods are used to update column values in the current row or the insert
* row. The updater methods do not update the underlying database; instead
* the <code>updateRow</code> or <code>insertRow</code> methods are called
* to update the database.
* <p>
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param xmlObject the column value
* @throws SQLException if the columnLabel is not valid;
* if a database access error occurs; this method
* is called on a closed result set;
* the <code>java.xml.transform.Result</code>,
* <code>Writer</code> or <code>OutputStream</code> has not been closed
* for the <code>SQLXML</code> object;
* if there is an error processing the XML value or
* the result set concurrency is <code>CONCUR_READ_ONLY</code>. The <code>getCause</code> method
* of the exception may provide a more detailed exception, for example, if the
* stream does not contain valid XML.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>String</code> in the Java programming language.
* It is intended for use when
* accessing <code>NCHAR</code>,<code>NVARCHAR</code>
* and <code>LONGNVARCHAR</code> columns.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
String getNString(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as
* a <code>String</code> in the Java programming language.
* It is intended for use when
* accessing <code>NCHAR</code>,<code>NVARCHAR</code>
* and <code>LONGNVARCHAR</code> columns.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return the column value; if the value is SQL <code>NULL</code>, the
* value returned is <code>null</code>
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
String getNString(String columnLabel) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a
* <code>java.io.Reader</code> object.
* It is intended for use when
* accessing <code>NCHAR</code>,<code>NVARCHAR</code>
* and <code>LONGNVARCHAR</code> columns.
*
* @return a <code>java.io.Reader</code> object that contains the column
* value; if the value is SQL <code>NULL</code>, the value returned is
* <code>null</code> in the Java programming language.
* @param columnIndex the first column is 1, the second is 2, ...
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
java.io.Reader getNCharacterStream(int columnIndex) throws SQLException;
/** {@collect.stats}
* Retrieves the value of the designated column in the current row
* of this <code>ResultSet</code> object as a
* <code>java.io.Reader</code> object.
* It is intended for use when
* accessing <code>NCHAR</code>,<code>NVARCHAR</code>
* and <code>LONGNVARCHAR</code> columns.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @return a <code>java.io.Reader</code> object that contains the column
* value; if the value is SQL <code>NULL</code>, the value returned is
* <code>null</code> in the Java programming language
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
java.io.Reader getNCharacterStream(String columnLabel) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a character stream value, which will have
* the specified number of bytes. The
* driver does the necessary conversion from Java character format to
* the national character set in the database.
* It is intended for use when
* updating <code>NCHAR</code>,<code>NVARCHAR</code>
* and <code>LONGNVARCHAR</code> columns.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @param length the length of the stream
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code> or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateNCharacterStream(int columnIndex,
java.io.Reader x,
long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a character stream value, which will have
* the specified number of bytes. The
* driver does the necessary conversion from Java character format to
* the national character set in the database.
* It is intended for use when
* updating <code>NCHAR</code>,<code>NVARCHAR</code>
* and <code>LONGNVARCHAR</code> columns.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param reader the <code>java.io.Reader</code> object containing
* the new column value
* @param length the length of the stream
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code> or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateNCharacterStream(String columnLabel,
java.io.Reader reader,
long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with an ascii stream value, which will have
* the specified number of bytes.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @param length the length of the stream
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateAsciiStream(int columnIndex,
java.io.InputStream x,
long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a binary stream value, which will have
* the specified number of bytes.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @param length the length of the stream
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateBinaryStream(int columnIndex,
java.io.InputStream x,
long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a character stream value, which will have
* the specified number of bytes.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @param length the length of the stream
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateCharacterStream(int columnIndex,
java.io.Reader x,
long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with an ascii stream value, which will have
* the specified number of bytes.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @param length the length of the stream
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateAsciiStream(String columnLabel,
java.io.InputStream x,
long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a binary stream value, which will have
* the specified number of bytes.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @param length the length of the stream
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateBinaryStream(String columnLabel,
java.io.InputStream x,
long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a character stream value, which will have
* the specified number of bytes.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param reader the <code>java.io.Reader</code> object containing
* the new column value
* @param length the length of the stream
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateCharacterStream(String columnLabel,
java.io.Reader reader,
long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column using the given input stream, which
* will have the specified number of bytes.
*
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param inputStream An object that contains the data to set the parameter
* value to.
* @param length the number of bytes in the parameter data.
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column using the given input stream, which
* will have the specified number of bytes.
*
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param inputStream An object that contains the data to set the parameter
* value to.
* @param length the number of bytes in the parameter data.
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column using the given <code>Reader</code>
* object, which is the given number of characters long.
* When a very large UNICODE value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.Reader</code> object. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param reader An object that contains the data to set the parameter value to.
* @param length the number of characters in the parameter data.
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateClob(int columnIndex, Reader reader, long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column using the given <code>Reader</code>
* object, which is the given number of characters long.
* When a very large UNICODE value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.Reader</code> object. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param reader An object that contains the data to set the parameter value to.
* @param length the number of characters in the parameter data.
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateClob(String columnLabel, Reader reader, long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column using the given <code>Reader</code>
* object, which is the given number of characters long.
* When a very large UNICODE value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.Reader</code> object. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnIndex the first column is 1, the second 2, ...
* @param reader An object that contains the data to set the parameter value to.
* @param length the number of characters in the parameter data.
* @throws SQLException if the columnIndex is not valid;
* if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; this method is called on a closed result set,
* if a database access error occurs or
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateNClob(int columnIndex, Reader reader, long length) throws SQLException;
/** {@collect.stats}
* Updates the designated column using the given <code>Reader</code>
* object, which is the given number of characters long.
* When a very large UNICODE value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.Reader</code> object. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param reader An object that contains the data to set the parameter value to.
* @param length the number of characters in the parameter data.
* @throws SQLException if the columnLabel is not valid;
* if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; this method is called on a closed result set;
* if a database access error occurs or
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateNClob(String columnLabel, Reader reader, long length) throws SQLException;
//---
/** {@collect.stats}
* Updates the designated column with a character stream value.
* The data will be read from the stream
* as needed until end-of-stream is reached. The
* driver does the necessary conversion from Java character format to
* the national character set in the database.
* It is intended for use when
* updating <code>NCHAR</code>,<code>NVARCHAR</code>
* and <code>LONGNVARCHAR</code> columns.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateNCharacterStream</code> which takes a length parameter.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code> or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateNCharacterStream(int columnIndex,
java.io.Reader x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a character stream value.
* The data will be read from the stream
* as needed until end-of-stream is reached. The
* driver does the necessary conversion from Java character format to
* the national character set in the database.
* It is intended for use when
* updating <code>NCHAR</code>,<code>NVARCHAR</code>
* and <code>LONGNVARCHAR</code> columns.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateNCharacterStream</code> which takes a length parameter.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param reader the <code>java.io.Reader</code> object containing
* the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code> or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateNCharacterStream(String columnLabel,
java.io.Reader reader) throws SQLException;
/** {@collect.stats}
* Updates the designated column with an ascii stream value.
* The data will be read from the stream
* as needed until end-of-stream is reached.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateAsciiStream</code> which takes a length parameter.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateAsciiStream(int columnIndex,
java.io.InputStream x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a binary stream value.
* The data will be read from the stream
* as needed until end-of-stream is reached.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateBinaryStream</code> which takes a length parameter.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateBinaryStream(int columnIndex,
java.io.InputStream x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a character stream value.
* The data will be read from the stream
* as needed until end-of-stream is reached.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateCharacterStream</code> which takes a length parameter.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param x the new column value
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateCharacterStream(int columnIndex,
java.io.Reader x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with an ascii stream value.
* The data will be read from the stream
* as needed until end-of-stream is reached.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateAsciiStream</code> which takes a length parameter.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateAsciiStream(String columnLabel,
java.io.InputStream x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a binary stream value.
* The data will be read from the stream
* as needed until end-of-stream is reached.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateBinaryStream</code> which takes a length parameter.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param x the new column value
* @exception SQLException if the columnLabel is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateBinaryStream(String columnLabel,
java.io.InputStream x) throws SQLException;
/** {@collect.stats}
* Updates the designated column with a character stream value.
* The data will be read from the stream
* as needed until end-of-stream is reached.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateCharacterStream</code> which takes a length parameter.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param reader the <code>java.io.Reader</code> object containing
* the new column value
* @exception SQLException if the columnLabel is not valid; if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateCharacterStream(String columnLabel,
java.io.Reader reader) throws SQLException;
/** {@collect.stats}
* Updates the designated column using the given input stream. The data will be read from the stream
* as needed until end-of-stream is reached.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateBlob</code> which takes a length parameter.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param inputStream An object that contains the data to set the parameter
* value to.
* @exception SQLException if the columnIndex is not valid; if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateBlob(int columnIndex, InputStream inputStream) throws SQLException;
/** {@collect.stats}
* Updates the designated column using the given input stream. The data will be read from the stream
* as needed until end-of-stream is reached.
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateBlob</code> which takes a length parameter.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param inputStream An object that contains the data to set the parameter
* value to.
* @exception SQLException if the columnLabel is not valid; if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateBlob(String columnLabel, InputStream inputStream) throws SQLException;
/** {@collect.stats}
* Updates the designated column using the given <code>Reader</code>
* object.
* The data will be read from the stream
* as needed until end-of-stream is reached. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateClob</code> which takes a length parameter.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @param reader An object that contains the data to set the parameter value to.
* @exception SQLException if the columnIndex is not valid;
* if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateClob(int columnIndex, Reader reader) throws SQLException;
/** {@collect.stats}
* Updates the designated column using the given <code>Reader</code>
* object.
* The data will be read from the stream
* as needed until end-of-stream is reached. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateClob</code> which takes a length parameter.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param reader An object that contains the data to set the parameter value to.
* @exception SQLException if the columnLabel is not valid; if a database access error occurs;
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* or this method is called on a closed result set
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateClob(String columnLabel, Reader reader) throws SQLException;
/** {@collect.stats}
* Updates the designated column using the given <code>Reader</code>
*
* The data will be read from the stream
* as needed until end-of-stream is reached. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateNClob</code> which takes a length parameter.
*
* @param columnIndex the first column is 1, the second 2, ...
* @param reader An object that contains the data to set the parameter value to.
* @throws SQLException if the columnIndex is not valid;
* if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; this method is called on a closed result set,
* if a database access error occurs or
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateNClob(int columnIndex, Reader reader) throws SQLException;
/** {@collect.stats}
* Updates the designated column using the given <code>Reader</code>
* object.
* The data will be read from the stream
* as needed until end-of-stream is reached. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <p>
* The updater methods are used to update column values in the
* current row or the insert row. The updater methods do not
* update the underlying database; instead the <code>updateRow</code> or
* <code>insertRow</code> methods are called to update the database.
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>updateNClob</code> which takes a length parameter.
*
* @param columnLabel the label for the column specified with the SQL AS clause. If the SQL AS clause was not specified, then the label is the name of the column
* @param reader An object that contains the data to set the parameter value to.
* @throws SQLException if the columnLabel is not valid; if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; this method is called on a closed result set;
* if a database access error occurs or
* the result set concurrency is <code>CONCUR_READ_ONLY</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void updateNClob(String columnLabel, Reader reader) throws SQLException;
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* An exception thrown as a <code>DataTruncation</code> exception
* (on writes) or reported as a
* <code>DataTruncation</code> warning (on reads)
* when a data values is unexpectedly truncated for reasons other than its having
* execeeded <code>MaxFieldSize</code>.
*
* <P>The SQLstate for a <code>DataTruncation</code> during read is <code>01004</code>.
* <P>The SQLstate for a <code>DataTruncation</code> during write is <code>22001</code>.
*/
public class DataTruncation extends SQLWarning {
/** {@collect.stats}
* Creates a <code>DataTruncation</code> object
* with the SQLState initialized
* to 01004 when <code>read</code> is set to <code>true</code> and 22001
* when <code>read</code> is set to <code>false</code>,
* the reason set to "Data truncation", the
* vendor code set to 0, and
* the other fields set to the given values.
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
*
* @param index The index of the parameter or column value
* @param parameter true if a parameter value was truncated
* @param read true if a read was truncated
* @param dataSize the original size of the data
* @param transferSize the size after truncation
*/
public DataTruncation(int index, boolean parameter,
boolean read, int dataSize,
int transferSize) {
super("Data truncation", read == true?"01004":"22001");
this.index = index;
this.parameter = parameter;
this.read = read;
this.dataSize = dataSize;
this.transferSize = transferSize;
}
/** {@collect.stats}
* Creates a <code>DataTruncation</code> object
* with the SQLState initialized
* to 01004 when <code>read</code> is set to <code>true</code> and 22001
* when <code>read</code> is set to <code>false</code>,
* the reason set to "Data truncation", the
* vendor code set to 0, and
* the other fields set to the given values.
* <p>
*
* @param index The index of the parameter or column value
* @param parameter true if a parameter value was truncated
* @param read true if a read was truncated
* @param dataSize the original size of the data
* @param transferSize the size after truncation
* @param cause the underlying reason for this <code>DataTruncation</code>
* (which is saved for later retrieval by the <code>getCause()</code> method);
* may be null indicating the cause is non-existent or unknown.
*
* @since 1.6
*/
public DataTruncation(int index, boolean parameter,
boolean read, int dataSize,
int transferSize, Throwable cause) {
super("Data truncation", read == true?"01004":"22001",cause);
this.index = index;
this.parameter = parameter;
this.read = read;
this.dataSize = dataSize;
this.transferSize = transferSize;
}
/** {@collect.stats}
* Retrieves the index of the column or parameter that was truncated.
*
* <P>This may be -1 if the column or parameter index is unknown, in
* which case the <code>parameter</code> and <code>read</code> fields should be ignored.
*
* @return the index of the truncated paramter or column value
*/
public int getIndex() {
return index;
}
/** {@collect.stats}
* Indicates whether the value truncated was a parameter value or
* a column value.
*
* @return <code>true</code> if the value truncated was a parameter;
* <code>false</code> if it was a column value
*/
public boolean getParameter() {
return parameter;
}
/** {@collect.stats}
* Indicates whether or not the value was truncated on a read.
*
* @return <code>true</code> if the value was truncated when read from
* the database; <code>false</code> if the data was truncated on a write
*/
public boolean getRead() {
return read;
}
/** {@collect.stats}
* Gets the number of bytes of data that should have been transferred.
* This number may be approximate if data conversions were being
* performed. The value may be <code>-1</code> if the size is unknown.
*
* @return the number of bytes of data that should have been transferred
*/
public int getDataSize() {
return dataSize;
}
/** {@collect.stats}
* Gets the number of bytes of data actually transferred.
* The value may be <code>-1</code> if the size is unknown.
*
* @return the number of bytes of data actually transferred
*/
public int getTransferSize() {
return transferSize;
}
/** {@collect.stats}
* @serial
*/
private int index;
/** {@collect.stats}
* @serial
*/
private boolean parameter;
/** {@collect.stats}
* @serial
*/
private boolean read;
/** {@collect.stats}
* @serial
*/
private int dataSize;
/** {@collect.stats}
* @serial
*/
private int transferSize;
/** {@collect.stats}
* @serial
*/
private static final long serialVersionUID = 6464298989504059473L;
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
import java.util.Properties;
/** {@collect.stats}
* <P>A connection (session) with a specific
* database. SQL statements are executed and results are returned
* within the context of a connection.
* <P>
* A <code>Connection</code> object's database is able to provide information
* describing its tables, its supported SQL grammar, its stored
* procedures, the capabilities of this connection, and so on. This
* information is obtained with the <code>getMetaData</code> method.
*
* <P><B>Note:</B> When configuring a <code>Connection</code>, JDBC applications
* should use the appropritate <code>Connection</code> method such as
* <code>setAutoCommit</code> or <code>setTransactionIsolation</code>.
* Applications should not invoke SQL commands directly to change the connection's
* configuration when there is a JDBC method available. By default a <code>Connection</code> object is in
* auto-commit mode, which means that it automatically commits changes
* after executing each statement. If auto-commit mode has been
* disabled, the method <code>commit</code> must be called explicitly in
* order to commit changes; otherwise, database changes will not be saved.
* <P>
* A new <code>Connection</code> object created using the JDBC 2.1 core API
* has an initially empty type map associated with it. A user may enter a
* custom mapping for a UDT in this type map.
* When a UDT is retrieved from a data source with the
* method <code>ResultSet.getObject</code>, the <code>getObject</code> method
* will check the connection's type map to see if there is an entry for that
* UDT. If so, the <code>getObject</code> method will map the UDT to the
* class indicated. If there is no entry, the UDT will be mapped using the
* standard mapping.
* <p>
* A user may create a new type map, which is a <code>java.util.Map</code>
* object, make an entry in it, and pass it to the <code>java.sql</code>
* methods that can perform custom mapping. In this case, the method
* will use the given type map instead of the one associated with
* the connection.
* <p>
* For example, the following code fragment specifies that the SQL
* type <code>ATHLETES</code> will be mapped to the class
* <code>Athletes</code> in the Java programming language.
* The code fragment retrieves the type map for the <code>Connection
* </code> object <code>con</code>, inserts the entry into it, and then sets
* the type map with the new entry as the connection's type map.
* <pre>
* java.util.Map map = con.getTypeMap();
* map.put("mySchemaName.ATHLETES", Class.forName("Athletes"));
* con.setTypeMap(map);
* </pre>
*
* @see DriverManager#getConnection
* @see Statement
* @see ResultSet
* @see DatabaseMetaData
*/
public interface Connection extends Wrapper {
/** {@collect.stats}
* Creates a <code>Statement</code> object for sending
* SQL statements to the database.
* SQL statements without parameters are normally
* executed using <code>Statement</code> objects. If the same SQL statement
* is executed many times, it may be more efficient to use a
* <code>PreparedStatement</code> object.
* <P>
* Result sets created using the returned <code>Statement</code>
* object will by default be type <code>TYPE_FORWARD_ONLY</code>
* and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @return a new default <code>Statement</code> object
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
*/
Statement createStatement() throws SQLException;
/** {@collect.stats}
* Creates a <code>PreparedStatement</code> object for sending
* parameterized SQL statements to the database.
* <P>
* A SQL statement with or without IN parameters can be
* pre-compiled and stored in a <code>PreparedStatement</code> object. This
* object can then be used to efficiently execute this statement
* multiple times.
*
* <P><B>Note:</B> This method is optimized for handling
* parametric SQL statements that benefit from precompilation. If
* the driver supports precompilation,
* the method <code>prepareStatement</code> will send
* the statement to the database for precompilation. Some drivers
* may not support precompilation. In this case, the statement may
* not be sent to the database until the <code>PreparedStatement</code>
* object is executed. This has no direct effect on users; however, it does
* affect which methods throw certain <code>SQLException</code> objects.
* <P>
* Result sets created using the returned <code>PreparedStatement</code>
* object will by default be type <code>TYPE_FORWARD_ONLY</code>
* and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @param sql an SQL statement that may contain one or more '?' IN
* parameter placeholders
* @return a new default <code>PreparedStatement</code> object containing the
* pre-compiled SQL statement
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
*/
PreparedStatement prepareStatement(String sql)
throws SQLException;
/** {@collect.stats}
* Creates a <code>CallableStatement</code> object for calling
* database stored procedures.
* The <code>CallableStatement</code> object provides
* methods for setting up its IN and OUT parameters, and
* methods for executing the call to a stored procedure.
*
* <P><B>Note:</B> This method is optimized for handling stored
* procedure call statements. Some drivers may send the call
* statement to the database when the method <code>prepareCall</code>
* is done; others
* may wait until the <code>CallableStatement</code> object
* is executed. This has no
* direct effect on users; however, it does affect which method
* throws certain SQLExceptions.
* <P>
* Result sets created using the returned <code>CallableStatement</code>
* object will by default be type <code>TYPE_FORWARD_ONLY</code>
* and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @param sql an SQL statement that may contain one or more '?'
* parameter placeholders. Typically this statement is specified using JDBC
* call escape syntax.
* @return a new default <code>CallableStatement</code> object containing the
* pre-compiled SQL statement
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
*/
CallableStatement prepareCall(String sql) throws SQLException;
/** {@collect.stats}
* Converts the given SQL statement into the system's native SQL grammar.
* A driver may convert the JDBC SQL grammar into its system's
* native SQL grammar prior to sending it. This method returns the
* native form of the statement that the driver would have sent.
*
* @param sql an SQL statement that may contain one or more '?'
* parameter placeholders
* @return the native form of this statement
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
*/
String nativeSQL(String sql) throws SQLException;
/** {@collect.stats}
* Sets this connection's auto-commit mode to the given state.
* If a connection is in auto-commit mode, then all its SQL
* statements will be executed and committed as individual
* transactions. Otherwise, its SQL statements are grouped into
* transactions that are terminated by a call to either
* the method <code>commit</code> or the method <code>rollback</code>.
* By default, new connections are in auto-commit
* mode.
* <P>
* The commit occurs when the statement completes. The time when the statement
* completes depends on the type of SQL Statement:
* <ul>
* <li>For DML statements, such as Insert, Update or Delete, and DDL statements,
* the statement is complete as soon as it has finished executing.
* <li>For Select statements, the statement is complete when the associated result
* set is closed.
* <li>For <code>CallableStatement</code> objects or for statements that return
* multiple results, the statement is complete
* when all of the associated result sets have been closed, and all update
* counts and output parameters have been retrieved.
*</ul>
* <P>
* <B>NOTE:</B> If this method is called during a transaction and the
* auto-commit mode is changed, the transaction is committed. If
* <code>setAutoCommit</code> is called and the auto-commit mode is
* not changed, the call is a no-op.
*
* @param autoCommit <code>true</code> to enable auto-commit mode;
* <code>false</code> to disable it
* @exception SQLException if a database access error occurs,
* setAutoCommit(true) is called while participating in a distributed transaction,
* or this method is called on a closed connection
* @see #getAutoCommit
*/
void setAutoCommit(boolean autoCommit) throws SQLException;
/** {@collect.stats}
* Retrieves the current auto-commit mode for this <code>Connection</code>
* object.
*
* @return the current state of this <code>Connection</code> object's
* auto-commit mode
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
* @see #setAutoCommit
*/
boolean getAutoCommit() throws SQLException;
/** {@collect.stats}
* Makes all changes made since the previous
* commit/rollback permanent and releases any database locks
* currently held by this <code>Connection</code> object.
* This method should be
* used only when auto-commit mode has been disabled.
*
* @exception SQLException if a database access error occurs,
* this method is called while participating in a distributed transaction,
* if this method is called on a closed conection or this
* <code>Connection</code> object is in auto-commit mode
* @see #setAutoCommit
*/
void commit() throws SQLException;
/** {@collect.stats}
* Undoes all changes made in the current transaction
* and releases any database locks currently held
* by this <code>Connection</code> object. This method should be
* used only when auto-commit mode has been disabled.
*
* @exception SQLException if a database access error occurs,
* this method is called while participating in a distributed transaction,
* this method is called on a closed connection or this
* <code>Connection</code> object is in auto-commit mode
* @see #setAutoCommit
*/
void rollback() throws SQLException;
/** {@collect.stats}
* Releases this <code>Connection</code> object's database and JDBC resources
* immediately instead of waiting for them to be automatically released.
* <P>
* Calling the method <code>close</code> on a <code>Connection</code>
* object that is already closed is a no-op.
* <P>
* It is <b>strongly recommended</b> that an application explicitly
* commits or rolls back an active transaction prior to calling the
* <code>close</code> method. If the <code>close</code> method is called
* and there is an active transaction, the results are implementation-defined.
* <P>
*
* @exception SQLException SQLException if a database access error occurs
*/
void close() throws SQLException;
/** {@collect.stats}
* Retrieves whether this <code>Connection</code> object has been
* closed. A connection is closed if the method <code>close</code>
* has been called on it or if certain fatal errors have occurred.
* This method is guaranteed to return <code>true</code> only when
* it is called after the method <code>Connection.close</code> has
* been called.
* <P>
* This method generally cannot be called to determine whether a
* connection to a database is valid or invalid. A typical client
* can determine that a connection is invalid by catching any
* exceptions that might be thrown when an operation is attempted.
*
* @return <code>true</code> if this <code>Connection</code> object
* is closed; <code>false</code> if it is still open
* @exception SQLException if a database access error occurs
*/
boolean isClosed() throws SQLException;
//======================================================================
// Advanced features:
/** {@collect.stats}
* Retrieves a <code>DatabaseMetaData</code> object that contains
* metadata about the database to which this
* <code>Connection</code> object represents a connection.
* The metadata includes information about the database's
* tables, its supported SQL grammar, its stored
* procedures, the capabilities of this connection, and so on.
*
* @return a <code>DatabaseMetaData</code> object for this
* <code>Connection</code> object
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
*/
DatabaseMetaData getMetaData() throws SQLException;
/** {@collect.stats}
* Puts this connection in read-only mode as a hint to the driver to enable
* database optimizations.
*
* <P><B>Note:</B> This method cannot be called during a transaction.
*
* @param readOnly <code>true</code> enables read-only mode;
* <code>false</code> disables it
* @exception SQLException if a database access error occurs, this
* method is called on a closed connection or this
* method is called during a transaction
*/
void setReadOnly(boolean readOnly) throws SQLException;
/** {@collect.stats}
* Retrieves whether this <code>Connection</code>
* object is in read-only mode.
*
* @return <code>true</code> if this <code>Connection</code> object
* is read-only; <code>false</code> otherwise
* @exception SQLException SQLException if a database access error occurs
* or this method is called on a closed connection
*/
boolean isReadOnly() throws SQLException;
/** {@collect.stats}
* Sets the given catalog name in order to select
* a subspace of this <code>Connection</code> object's database
* in which to work.
* <P>
* If the driver does not support catalogs, it will
* silently ignore this request.
*
* @param catalog the name of a catalog (subspace in this
* <code>Connection</code> object's database) in which to work
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
* @see #getCatalog
*/
void setCatalog(String catalog) throws SQLException;
/** {@collect.stats}
* Retrieves this <code>Connection</code> object's current catalog name.
*
* @return the current catalog name or <code>null</code> if there is none
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
* @see #setCatalog
*/
String getCatalog() throws SQLException;
/** {@collect.stats}
* A constant indicating that transactions are not supported.
*/
int TRANSACTION_NONE = 0;
/** {@collect.stats}
* A constant indicating that
* dirty reads, non-repeatable reads and phantom reads can occur.
* This level allows a row changed by one transaction to be read
* by another transaction before any changes in that row have been
* committed (a "dirty read"). If any of the changes are rolled back,
* the second transaction will have retrieved an invalid row.
*/
int TRANSACTION_READ_UNCOMMITTED = 1;
/** {@collect.stats}
* A constant indicating that
* dirty reads are prevented; non-repeatable reads and phantom
* reads can occur. This level only prohibits a transaction
* from reading a row with uncommitted changes in it.
*/
int TRANSACTION_READ_COMMITTED = 2;
/** {@collect.stats}
* A constant indicating that
* dirty reads and non-repeatable reads are prevented; phantom
* reads can occur. This level prohibits a transaction from
* reading a row with uncommitted changes in it, and it also
* prohibits the situation where one transaction reads a row,
* a second transaction alters the row, and the first transaction
* rereads the row, getting different values the second time
* (a "non-repeatable read").
*/
int TRANSACTION_REPEATABLE_READ = 4;
/** {@collect.stats}
* A constant indicating that
* dirty reads, non-repeatable reads and phantom reads are prevented.
* This level includes the prohibitions in
* <code>TRANSACTION_REPEATABLE_READ</code> and further prohibits the
* situation where one transaction reads all rows that satisfy
* a <code>WHERE</code> condition, a second transaction inserts a row that
* satisfies that <code>WHERE</code> condition, and the first transaction
* rereads for the same condition, retrieving the additional
* "phantom" row in the second read.
*/
int TRANSACTION_SERIALIZABLE = 8;
/** {@collect.stats}
* Attempts to change the transaction isolation level for this
* <code>Connection</code> object to the one given.
* The constants defined in the interface <code>Connection</code>
* are the possible transaction isolation levels.
* <P>
* <B>Note:</B> If this method is called during a transaction, the result
* is implementation-defined.
*
* @param level one of the following <code>Connection</code> constants:
* <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>,
* <code>Connection.TRANSACTION_READ_COMMITTED</code>,
* <code>Connection.TRANSACTION_REPEATABLE_READ</code>, or
* <code>Connection.TRANSACTION_SERIALIZABLE</code>.
* (Note that <code>Connection.TRANSACTION_NONE</code> cannot be used
* because it specifies that transactions are not supported.)
* @exception SQLException if a database access error occurs, this
* method is called on a closed connection
* or the given parameter is not one of the <code>Connection</code>
* constants
* @see DatabaseMetaData#supportsTransactionIsolationLevel
* @see #getTransactionIsolation
*/
void setTransactionIsolation(int level) throws SQLException;
/** {@collect.stats}
* Retrieves this <code>Connection</code> object's current
* transaction isolation level.
*
* @return the current transaction isolation level, which will be one
* of the following constants:
* <code>Connection.TRANSACTION_READ_UNCOMMITTED</code>,
* <code>Connection.TRANSACTION_READ_COMMITTED</code>,
* <code>Connection.TRANSACTION_REPEATABLE_READ</code>,
* <code>Connection.TRANSACTION_SERIALIZABLE</code>, or
* <code>Connection.TRANSACTION_NONE</code>.
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
* @see #setTransactionIsolation
*/
int getTransactionIsolation() throws SQLException;
/** {@collect.stats}
* Retrieves the first warning reported by calls on this
* <code>Connection</code> object. If there is more than one
* warning, subsequent warnings will be chained to the first one
* and can be retrieved by calling the method
* <code>SQLWarning.getNextWarning</code> on the warning
* that was retrieved previously.
* <P>
* This method may not be
* called on a closed connection; doing so will cause an
* <code>SQLException</code> to be thrown.
*
* <P><B>Note:</B> Subsequent warnings will be chained to this
* SQLWarning.
*
* @return the first <code>SQLWarning</code> object or <code>null</code>
* if there are none
* @exception SQLException if a database access error occurs or
* this method is called on a closed connection
* @see SQLWarning
*/
SQLWarning getWarnings() throws SQLException;
/** {@collect.stats}
* Clears all warnings reported for this <code>Connection</code> object.
* After a call to this method, the method <code>getWarnings</code>
* returns <code>null</code> until a new warning is
* reported for this <code>Connection</code> object.
*
* @exception SQLException SQLException if a database access error occurs
* or this method is called on a closed connection
*/
void clearWarnings() throws SQLException;
//--------------------------JDBC 2.0-----------------------------
/** {@collect.stats}
* Creates a <code>Statement</code> object that will generate
* <code>ResultSet</code> objects with the given type and concurrency.
* This method is the same as the <code>createStatement</code> method
* above, but it allows the default result set
* type and concurrency to be overridden.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @param resultSetType a result set type; one of
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency a concurrency type; one of
* <code>ResultSet.CONCUR_READ_ONLY</code> or
* <code>ResultSet.CONCUR_UPDATABLE</code>
* @return a new <code>Statement</code> object that will generate
* <code>ResultSet</code> objects with the given type and
* concurrency
* @exception SQLException if a database access error occurs, this
* method is called on a closed connection
* or the given parameters are not <code>ResultSet</code>
* constants indicating type and concurrency
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method or this method is not supported for the specified result
* set type and result set concurrency.
* @since 1.2
*/
Statement createStatement(int resultSetType, int resultSetConcurrency)
throws SQLException;
/** {@collect.stats}
*
* Creates a <code>PreparedStatement</code> object that will generate
* <code>ResultSet</code> objects with the given type and concurrency.
* This method is the same as the <code>prepareStatement</code> method
* above, but it allows the default result set
* type and concurrency to be overridden.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @param sql a <code>String</code> object that is the SQL statement to
* be sent to the database; may contain one or more '?' IN
* parameters
* @param resultSetType a result set type; one of
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency a concurrency type; one of
* <code>ResultSet.CONCUR_READ_ONLY</code> or
* <code>ResultSet.CONCUR_UPDATABLE</code>
* @return a new PreparedStatement object containing the
* pre-compiled SQL statement that will produce <code>ResultSet</code>
* objects with the given type and concurrency
* @exception SQLException if a database access error occurs, this
* method is called on a closed connection
* or the given parameters are not <code>ResultSet</code>
* constants indicating type and concurrency
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method or this method is not supported for the specified result
* set type and result set concurrency.
* @since 1.2
*/
PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency)
throws SQLException;
/** {@collect.stats}
* Creates a <code>CallableStatement</code> object that will generate
* <code>ResultSet</code> objects with the given type and concurrency.
* This method is the same as the <code>prepareCall</code> method
* above, but it allows the default result set
* type and concurrency to be overridden.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @param sql a <code>String</code> object that is the SQL statement to
* be sent to the database; may contain on or more '?' parameters
* @param resultSetType a result set type; one of
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency a concurrency type; one of
* <code>ResultSet.CONCUR_READ_ONLY</code> or
* <code>ResultSet.CONCUR_UPDATABLE</code>
* @return a new <code>CallableStatement</code> object containing the
* pre-compiled SQL statement that will produce <code>ResultSet</code>
* objects with the given type and concurrency
* @exception SQLException if a database access error occurs, this method
* is called on a closed connection
* or the given parameters are not <code>ResultSet</code>
* constants indicating type and concurrency
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method or this method is not supported for the specified result
* set type and result set concurrency.
* @since 1.2
*/
CallableStatement prepareCall(String sql, int resultSetType,
int resultSetConcurrency) throws SQLException;
/** {@collect.stats}
* Retrieves the <code>Map</code> object associated with this
* <code>Connection</code> object.
* Unless the application has added an entry, the type map returned
* will be empty.
*
* @return the <code>java.util.Map</code> object associated
* with this <code>Connection</code> object
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
* @see #setTypeMap
*/
java.util.Map<String,Class<?>> getTypeMap() throws SQLException;
/** {@collect.stats}
* Installs the given <code>TypeMap</code> object as the type map for
* this <code>Connection</code> object. The type map will be used for the
* custom mapping of SQL structured types and distinct types.
*
* @param map the <code>java.util.Map</code> object to install
* as the replacement for this <code>Connection</code>
* object's default type map
* @exception SQLException if a database access error occurs, this
* method is called on a closed connection or
* the given parameter is not a <code>java.util.Map</code>
* object
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
* @see #getTypeMap
*/
void setTypeMap(java.util.Map<String,Class<?>> map) throws SQLException;
//--------------------------JDBC 3.0-----------------------------
/** {@collect.stats}
* Changes the default holdability of <code>ResultSet</code> objects
* created using this <code>Connection</code> object to the given
* holdability. The default holdability of <code>ResultSet</code> objects
* can be be determined by invoking
* {@link DatabaseMetaData#getResultSetHoldability}.
*
* @param holdability a <code>ResultSet</code> holdability constant; one of
* <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
* <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
* @throws SQLException if a database access occurs, this method is called
* on a closed connection, or the given parameter
* is not a <code>ResultSet</code> constant indicating holdability
* @exception SQLFeatureNotSupportedException if the given holdability is not supported
* @see #getHoldability
* @see DatabaseMetaData#getResultSetHoldability
* @see ResultSet
* @since 1.4
*/
void setHoldability(int holdability) throws SQLException;
/** {@collect.stats}
* Retrieves the current holdability of <code>ResultSet</code> objects
* created using this <code>Connection</code> object.
*
* @return the holdability, one of
* <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
* <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
* @throws SQLException if a database access error occurs
* or this method is called on a closed connection
* @see #setHoldability
* @see DatabaseMetaData#getResultSetHoldability
* @see ResultSet
* @since 1.4
*/
int getHoldability() throws SQLException;
/** {@collect.stats}
* Creates an unnamed savepoint in the current transaction and
* returns the new <code>Savepoint</code> object that represents it.
*
*<p> if setSavepoint is invoked outside of an active transaction, a transaction will be started at this newly created
*savepoint.
*
* @return the new <code>Savepoint</code> object
* @exception SQLException if a database access error occurs,
* this method is called while participating in a distributed transaction,
* this method is called on a closed connection
* or this <code>Connection</code> object is currently in
* auto-commit mode
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see Savepoint
* @since 1.4
*/
Savepoint setSavepoint() throws SQLException;
/** {@collect.stats}
* Creates a savepoint with the given name in the current transaction
* and returns the new <code>Savepoint</code> object that represents it.
*
* <p> if setSavepoint is invoked outside of an active transaction, a transaction will be started at this newly created
*savepoint.
*
* @param name a <code>String</code> containing the name of the savepoint
* @return the new <code>Savepoint</code> object
* @exception SQLException if a database access error occurs,
* this method is called while participating in a distributed transaction,
* this method is called on a closed connection
* or this <code>Connection</code> object is currently in
* auto-commit mode
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see Savepoint
* @since 1.4
*/
Savepoint setSavepoint(String name) throws SQLException;
/** {@collect.stats}
* Undoes all changes made after the given <code>Savepoint</code> object
* was set.
* <P>
* This method should be used only when auto-commit has been disabled.
*
* @param savepoint the <code>Savepoint</code> object to roll back to
* @exception SQLException if a database access error occurs,
* this method is called while participating in a distributed transaction,
* this method is called on a closed connection,
* the <code>Savepoint</code> object is no longer valid,
* or this <code>Connection</code> object is currently in
* auto-commit mode
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @see Savepoint
* @see #rollback
* @since 1.4
*/
void rollback(Savepoint savepoint) throws SQLException;
/** {@collect.stats}
* Removes the specified <code>Savepoint</code> and subsequent <code>Savepoint</code> objects from the current
* transaction. Any reference to the savepoint after it have been removed
* will cause an <code>SQLException</code> to be thrown.
*
* @param savepoint the <code>Savepoint</code> object to be removed
* @exception SQLException if a database access error occurs, this
* method is called on a closed connection or
* the given <code>Savepoint</code> object is not a valid
* savepoint in the current transaction
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
*/
void releaseSavepoint(Savepoint savepoint) throws SQLException;
/** {@collect.stats}
* Creates a <code>Statement</code> object that will generate
* <code>ResultSet</code> objects with the given type, concurrency,
* and holdability.
* This method is the same as the <code>createStatement</code> method
* above, but it allows the default result set
* type, concurrency, and holdability to be overridden.
*
* @param resultSetType one of the following <code>ResultSet</code>
* constants:
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency one of the following <code>ResultSet</code>
* constants:
* <code>ResultSet.CONCUR_READ_ONLY</code> or
* <code>ResultSet.CONCUR_UPDATABLE</code>
* @param resultSetHoldability one of the following <code>ResultSet</code>
* constants:
* <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
* <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
* @return a new <code>Statement</code> object that will generate
* <code>ResultSet</code> objects with the given type,
* concurrency, and holdability
* @exception SQLException if a database access error occurs, this
* method is called on a closed connection
* or the given parameters are not <code>ResultSet</code>
* constants indicating type, concurrency, and holdability
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method or this method is not supported for the specified result
* set type, result set holdability and result set concurrency.
* @see ResultSet
* @since 1.4
*/
Statement createStatement(int resultSetType, int resultSetConcurrency,
int resultSetHoldability) throws SQLException;
/** {@collect.stats}
* Creates a <code>PreparedStatement</code> object that will generate
* <code>ResultSet</code> objects with the given type, concurrency,
* and holdability.
* <P>
* This method is the same as the <code>prepareStatement</code> method
* above, but it allows the default result set
* type, concurrency, and holdability to be overridden.
*
* @param sql a <code>String</code> object that is the SQL statement to
* be sent to the database; may contain one or more '?' IN
* parameters
* @param resultSetType one of the following <code>ResultSet</code>
* constants:
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency one of the following <code>ResultSet</code>
* constants:
* <code>ResultSet.CONCUR_READ_ONLY</code> or
* <code>ResultSet.CONCUR_UPDATABLE</code>
* @param resultSetHoldability one of the following <code>ResultSet</code>
* constants:
* <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
* <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
* @return a new <code>PreparedStatement</code> object, containing the
* pre-compiled SQL statement, that will generate
* <code>ResultSet</code> objects with the given type,
* concurrency, and holdability
* @exception SQLException if a database access error occurs, this
* method is called on a closed connection
* or the given parameters are not <code>ResultSet</code>
* constants indicating type, concurrency, and holdability
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method or this method is not supported for the specified result
* set type, result set holdability and result set concurrency.
* @see ResultSet
* @since 1.4
*/
PreparedStatement prepareStatement(String sql, int resultSetType,
int resultSetConcurrency, int resultSetHoldability)
throws SQLException;
/** {@collect.stats}
* Creates a <code>CallableStatement</code> object that will generate
* <code>ResultSet</code> objects with the given type and concurrency.
* This method is the same as the <code>prepareCall</code> method
* above, but it allows the default result set
* type, result set concurrency type and holdability to be overridden.
*
* @param sql a <code>String</code> object that is the SQL statement to
* be sent to the database; may contain on or more '?' parameters
* @param resultSetType one of the following <code>ResultSet</code>
* constants:
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency one of the following <code>ResultSet</code>
* constants:
* <code>ResultSet.CONCUR_READ_ONLY</code> or
* <code>ResultSet.CONCUR_UPDATABLE</code>
* @param resultSetHoldability one of the following <code>ResultSet</code>
* constants:
* <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
* <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
* @return a new <code>CallableStatement</code> object, containing the
* pre-compiled SQL statement, that will generate
* <code>ResultSet</code> objects with the given type,
* concurrency, and holdability
* @exception SQLException if a database access error occurs, this
* method is called on a closed connection
* or the given parameters are not <code>ResultSet</code>
* constants indicating type, concurrency, and holdability
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method or this method is not supported for the specified result
* set type, result set holdability and result set concurrency.
* @see ResultSet
* @since 1.4
*/
CallableStatement prepareCall(String sql, int resultSetType,
int resultSetConcurrency,
int resultSetHoldability) throws SQLException;
/** {@collect.stats}
* Creates a default <code>PreparedStatement</code> object that has
* the capability to retrieve auto-generated keys. The given constant
* tells the driver whether it should make auto-generated keys
* available for retrieval. This parameter is ignored if the SQL statement
* is not an <code>INSERT</code> statement, or an SQL statement able to return
* auto-generated keys (the list of such statements is vendor-specific).
* <P>
* <B>Note:</B> This method is optimized for handling
* parametric SQL statements that benefit from precompilation. If
* the driver supports precompilation,
* the method <code>prepareStatement</code> will send
* the statement to the database for precompilation. Some drivers
* may not support precompilation. In this case, the statement may
* not be sent to the database until the <code>PreparedStatement</code>
* object is executed. This has no direct effect on users; however, it does
* affect which methods throw certain SQLExceptions.
* <P>
* Result sets created using the returned <code>PreparedStatement</code>
* object will by default be type <code>TYPE_FORWARD_ONLY</code>
* and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @param sql an SQL statement that may contain one or more '?' IN
* parameter placeholders
* @param autoGeneratedKeys a flag indicating whether auto-generated keys
* should be returned; one of
* <code>Statement.RETURN_GENERATED_KEYS</code> or
* <code>Statement.NO_GENERATED_KEYS</code>
* @return a new <code>PreparedStatement</code> object, containing the
* pre-compiled SQL statement, that will have the capability of
* returning auto-generated keys
* @exception SQLException if a database access error occurs, this
* method is called on a closed connection
* or the given parameter is not a <code>Statement</code>
* constant indicating whether auto-generated keys should be
* returned
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method with a constant of Statement.RETURN_GENERATED_KEYS
* @since 1.4
*/
PreparedStatement prepareStatement(String sql, int autoGeneratedKeys)
throws SQLException;
/** {@collect.stats}
* Creates a default <code>PreparedStatement</code> object capable
* of returning the auto-generated keys designated by the given array.
* This array contains the indexes of the columns in the target
* table that contain the auto-generated keys that should be made
* available. The driver will ignore the array if the SQL statement
* is not an <code>INSERT</code> statement, or an SQL statement able to return
* auto-generated keys (the list of such statements is vendor-specific).
*<p>
* An SQL statement with or without IN parameters can be
* pre-compiled and stored in a <code>PreparedStatement</code> object. This
* object can then be used to efficiently execute this statement
* multiple times.
* <P>
* <B>Note:</B> This method is optimized for handling
* parametric SQL statements that benefit from precompilation. If
* the driver supports precompilation,
* the method <code>prepareStatement</code> will send
* the statement to the database for precompilation. Some drivers
* may not support precompilation. In this case, the statement may
* not be sent to the database until the <code>PreparedStatement</code>
* object is executed. This has no direct effect on users; however, it does
* affect which methods throw certain SQLExceptions.
* <P>
* Result sets created using the returned <code>PreparedStatement</code>
* object will by default be type <code>TYPE_FORWARD_ONLY</code>
* and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @param sql an SQL statement that may contain one or more '?' IN
* parameter placeholders
* @param columnIndexes an array of column indexes indicating the columns
* that should be returned from the inserted row or rows
* @return a new <code>PreparedStatement</code> object, containing the
* pre-compiled statement, that is capable of returning the
* auto-generated keys designated by the given array of column
* indexes
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
*
* @since 1.4
*/
PreparedStatement prepareStatement(String sql, int columnIndexes[])
throws SQLException;
/** {@collect.stats}
* Creates a default <code>PreparedStatement</code> object capable
* of returning the auto-generated keys designated by the given array.
* This array contains the names of the columns in the target
* table that contain the auto-generated keys that should be returned.
* The driver will ignore the array if the SQL statement
* is not an <code>INSERT</code> statement, or an SQL statement able to return
* auto-generated keys (the list of such statements is vendor-specific).
* <P>
* An SQL statement with or without IN parameters can be
* pre-compiled and stored in a <code>PreparedStatement</code> object. This
* object can then be used to efficiently execute this statement
* multiple times.
* <P>
* <B>Note:</B> This method is optimized for handling
* parametric SQL statements that benefit from precompilation. If
* the driver supports precompilation,
* the method <code>prepareStatement</code> will send
* the statement to the database for precompilation. Some drivers
* may not support precompilation. In this case, the statement may
* not be sent to the database until the <code>PreparedStatement</code>
* object is executed. This has no direct effect on users; however, it does
* affect which methods throw certain SQLExceptions.
* <P>
* Result sets created using the returned <code>PreparedStatement</code>
* object will by default be type <code>TYPE_FORWARD_ONLY</code>
* and have a concurrency level of <code>CONCUR_READ_ONLY</code>.
* The holdability of the created result sets can be determined by
* calling {@link #getHoldability}.
*
* @param sql an SQL statement that may contain one or more '?' IN
* parameter placeholders
* @param columnNames an array of column names indicating the columns
* that should be returned from the inserted row or rows
* @return a new <code>PreparedStatement</code> object, containing the
* pre-compiled statement, that is capable of returning the
* auto-generated keys designated by the given array of column
* names
* @exception SQLException if a database access error occurs
* or this method is called on a closed connection
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
*
* @since 1.4
*/
PreparedStatement prepareStatement(String sql, String columnNames[])
throws SQLException;
/** {@collect.stats}
* Constructs an object that implements the <code>Clob</code> interface. The object
* returned initially contains no data. The <code>setAsciiStream</code>,
* <code>setCharacterStream</code> and <code>setString</code> methods of
* the <code>Clob</code> interface may be used to add data to the <code>Clob</code>.
* @return An object that implements the <code>Clob</code> interface
* @throws SQLException if an object that implements the
* <code>Clob</code> interface can not be constructed, this method is
* called on a closed connection or a database access error occurs.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this data type
*
* @since 1.6
*/
Clob createClob() throws SQLException;
/** {@collect.stats}
* Constructs an object that implements the <code>Blob</code> interface. The object
* returned initially contains no data. The <code>setBinaryStream</code> and
* <code>setBytes</code> methods of the <code>Blob</code> interface may be used to add data to
* the <code>Blob</code>.
* @return An object that implements the <code>Blob</code> interface
* @throws SQLException if an object that implements the
* <code>Blob</code> interface can not be constructed, this method is
* called on a closed connection or a database access error occurs.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this data type
*
* @since 1.6
*/
Blob createBlob() throws SQLException;
/** {@collect.stats}
* Constructs an object that implements the <code>NClob</code> interface. The object
* returned initially contains no data. The <code>setAsciiStream</code>,
* <code>setCharacterStream</code> and <code>setString</code> methods of the <code>NClob</code> interface may
* be used to add data to the <code>NClob</code>.
* @return An object that implements the <code>NClob</code> interface
* @throws SQLException if an object that implements the
* <code>NClob</code> interface can not be constructed, this method is
* called on a closed connection or a database access error occurs.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this data type
*
* @since 1.6
*/
NClob createNClob() throws SQLException;
/** {@collect.stats}
* Constructs an object that implements the <code>SQLXML</code> interface. The object
* returned initially contains no data. The <code>createXmlStreamWriter</code> object and
* <code>setString</code> method of the <code>SQLXML</code> interface may be used to add data to the <code>SQLXML</code>
* object.
* @return An object that implements the <code>SQLXML</code> interface
* @throws SQLException if an object that implements the <code>SQLXML</code> interface can not
* be constructed, this method is
* called on a closed connection or a database access error occurs.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this data type
* @since 1.6
*/
SQLXML createSQLXML() throws SQLException;
/** {@collect.stats}
* Returns true if the connection has not been closed and is still valid.
* The driver shall submit a query on the connection or use some other
* mechanism that positively verifies the connection is still valid when
* this method is called.
* <p>
* The query submitted by the driver to validate the connection shall be
* executed in the context of the current transaction.
*
* @param timeout - The time in seconds to wait for the database operation
* used to validate the connection to complete. If
* the timeout period expires before the operation
* completes, this method returns false. A value of
* 0 indicates a timeout is not applied to the
* database operation.
* <p>
* @return true if the connection is valid, false otherwise
* @exception SQLException if the value supplied for <code>timeout</code>
* is less then 0
* @since 1.6
* <p>
* @see java.sql.DatabaseMetaData#getClientInfoProperties
*/
boolean isValid(int timeout) throws SQLException;
/** {@collect.stats}
* Sets the value of the client info property specified by name to the
* value specified by value.
* <p>
* Applications may use the <code>DatabaseMetaData.getClientInfoProperties</code>
* method to determine the client info properties supported by the driver
* and the maximum length that may be specified for each property.
* <p>
* The driver stores the value specified in a suitable location in the
* database. For example in a special register, session parameter, or
* system table column. For efficiency the driver may defer setting the
* value in the database until the next time a statement is executed or
* prepared. Other than storing the client information in the appropriate
* place in the database, these methods shall not alter the behavior of
* the connection in anyway. The values supplied to these methods are
* used for accounting, diagnostics and debugging purposes only.
* <p>
* The driver shall generate a warning if the client info name specified
* is not recognized by the driver.
* <p>
* If the value specified to this method is greater than the maximum
* length for the property the driver may either truncate the value and
* generate a warning or generate a <code>SQLClientInfoException</code>. If the driver
* generates a <code>SQLClientInfoException</code>, the value specified was not set on the
* connection.
* <p>
* The following are standard client info properties. Drivers are not
* required to support these properties however if the driver supports a
* client info property that can be described by one of the standard
* properties, the standard property name should be used.
* <p>
* <ul>
* <li>ApplicationName - The name of the application currently utilizing
* the connection</li>
* <li>ClientUser - The name of the user that the application using
* the connection is performing work for. This may
* not be the same as the user name that was used
* in establishing the connection.</li>
* <li>ClientHostname - The hostname of the computer the application
* using the connection is running on.</li>
* </ul>
* <p>
* @param name The name of the client info property to set
* @param value The value to set the client info property to. If the
* value is null, the current value of the specified
* property is cleared.
* <p>
* @throws SQLClientInfoException if the database server returns an error while
* setting the client info value on the database server or this method
* is called on a closed connection
* <p>
* @since 1.6
*/
void setClientInfo(String name, String value)
throws SQLClientInfoException;
/** {@collect.stats}
* Sets the value of the connection's client info properties. The
* <code>Properties</code> object contains the names and values of the client info
* properties to be set. The set of client info properties contained in
* the properties list replaces the current set of client info properties
* on the connection. If a property that is currently set on the
* connection is not present in the properties list, that property is
* cleared. Specifying an empty properties list will clear all of the
* properties on the connection. See <code>setClientInfo (String, String)</code> for
* more information.
* <p>
* If an error occurs in setting any of the client info properties, a
* <code>SQLClientInfoException</code> is thrown. The <code>SQLClientInfoException</code>
* contains information indicating which client info properties were not set.
* The state of the client information is unknown because
* some databases do not allow multiple client info properties to be set
* atomically. For those databases, one or more properties may have been
* set before the error occurred.
* <p>
*
* @param properties the list of client info properties to set
* <p>
* @see java.sql.Connection#setClientInfo(String, String) setClientInfo(String, String)
* @since 1.6
* <p>
* @throws SQLClientInfoException if the database server returns an error while
* setting the clientInfo values on the database server or this method
* is called on a closed connection
* <p>
*/
void setClientInfo(Properties properties)
throws SQLClientInfoException;
/** {@collect.stats}
* Returns the value of the client info property specified by name. This
* method may return null if the specified client info property has not
* been set and does not have a default value. This method will also
* return null if the specified client info property name is not supported
* by the driver.
* <p>
* Applications may use the <code>DatabaseMetaData.getClientInfoProperties</code>
* method to determine the client info properties supported by the driver.
* <p>
* @param name The name of the client info property to retrieve
* <p>
* @return The value of the client info property specified
* <p>
* @throws SQLException if the database server returns an error when
* fetching the client info value from the database
*or this method is called on a closed connection
* <p>
* @since 1.6
* <p>
* @see java.sql.DatabaseMetaData#getClientInfoProperties
*/
String getClientInfo(String name)
throws SQLException;
/** {@collect.stats}
* Returns a list containing the name and current value of each client info
* property supported by the driver. The value of a client info property
* may be null if the property has not been set and does not have a
* default value.
* <p>
* @return A <code>Properties</code> object that contains the name and current value of
* each of the client info properties supported by the driver.
* <p>
* @throws SQLException if the database server returns an error when
* fetching the client info values from the database
* or this method is called on a closed connection
* <p>
* @since 1.6
*/
Properties getClientInfo()
throws SQLException;
/** {@collect.stats}
* Factory method for creating Array objects.
*<p>
* <b>Note: </b>When <code>createArrayOf</code> is used to create an array object
* that maps to a primitive data type, then it is implementation-defined
* whether the <code>Array</code> object is an array of that primitive
* data type or an array of <code>Object</code>.
* <p>
* <b>Note: </b>The JDBC driver is responsible for mapping the elements
* <code>Object</code> array to the default JDBC SQL type defined in
* java.sql.Types for the given class of <code>Object</code>. The default
* mapping is specified in Appendix B of the JDBC specification. If the
* resulting JDBC type is not the appropriate type for the given typeName then
* it is implementation defined whether an <code>SQLException</code> is
* thrown or the driver supports the resulting conversion.
*
* @param typeName the SQL name of the type the elements of the array map to. The typeName is a
* database-specific name which may be the name of a built-in type, a user-defined type or a standard SQL type supported by this database. This
* is the value returned by <code>Array.getBaseTypeName</code>
* @param elements the elements that populate the returned object
* @return an Array object whose elements map to the specified SQL type
* @throws SQLException if a database error occurs, the JDBC type is not
* appropriate for the typeName and the conversion is not supported, the typeName is null or this method is called on a closed connection
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this data type
* @since 1.6
*/
Array createArrayOf(String typeName, Object[] elements) throws
SQLException;
/** {@collect.stats}
* Factory method for creating Struct objects.
*
* @param typeName the SQL type name of the SQL structured type that this <code>Struct</code>
* object maps to. The typeName is the name of a user-defined type that
* has been defined for this database. It is the value returned by
* <code>Struct.getSQLTypeName</code>.
* @param attributes the attributes that populate the returned object
* @return a Struct object that maps to the given SQL type and is populated with the given attributes
* @throws SQLException if a database error occurs, the typeName is null or this method is called on a closed connection
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this data type
* @since 1.6
*/
Struct createStruct(String typeName, Object[] attributes)
throws SQLException;
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* Comprehensive information about the database as a whole.
* <P>
* This interface is implemented by driver vendors to let users know the capabilities
* of a Database Management System (DBMS) in combination with
* the driver based on JDBC<sup><font size=-2>TM</font></sup> technology
* ("JDBC driver") that is used with it. Different relational DBMSs often support
* different features, implement features in different ways, and use different
* data types. In addition, a driver may implement a feature on top of what the
* DBMS offers. Information returned by methods in this interface applies
* to the capabilities of a particular driver and a particular DBMS working
* together. Note that as used in this documentation, the term "database" is
* used generically to refer to both the driver and DBMS.
* <P>
* A user for this interface is commonly a tool that needs to discover how to
* deal with the underlying DBMS. This is especially true for applications
* that are intended to be used with more than one DBMS. For example, a tool might use the method
* <code>getTypeInfo</code> to find out what data types can be used in a
* <code>CREATE TABLE</code> statement. Or a user might call the method
* <code>supportsCorrelatedSubqueries</code> to see if it is possible to use
* a correlated subquery or <code>supportsBatchUpdates</code> to see if it is
* possible to use batch updates.
* <P>
* Some <code>DatabaseMetaData</code> methods return lists of information
* in the form of <code>ResultSet</code> objects.
* Regular <code>ResultSet</code> methods, such as
* <code>getString</code> and <code>getInt</code>, can be used
* to retrieve the data from these <code>ResultSet</code> objects. If
* a given form of metadata is not available, an empty <code>ResultSet</code>
* will be returned. Additional columns beyond the columns defined to be
* returned by the <code>ResultSet</code> object for a given method
* can be defined by the JDBC driver vendor and must be accessed
* by their <B>column label</B>.
* <P>
* Some <code>DatabaseMetaData</code> methods take arguments that are
* String patterns. These arguments all have names such as fooPattern.
* Within a pattern String, "%" means match any substring of 0 or more
* characters, and "_" means match any one character. Only metadata
* entries matching the search pattern are returned. If a search pattern
* argument is set to <code>null</code>, that argument's criterion will
* be dropped from the search.
* <P>
*/
public interface DatabaseMetaData extends Wrapper {
//----------------------------------------------------------------------
// First, a variety of minor information about the target database.
/** {@collect.stats}
* Retrieves whether the current user can call all the procedures
* returned by the method <code>getProcedures</code>.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean allProceduresAreCallable() throws SQLException;
/** {@collect.stats}
* Retrieves whether the current user can use all the tables returned
* by the method <code>getTables</code> in a <code>SELECT</code>
* statement.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean allTablesAreSelectable() throws SQLException;
/** {@collect.stats}
* Retrieves the URL for this DBMS.
*
* @return the URL for this DBMS or <code>null</code> if it cannot be
* generated
* @exception SQLException if a database access error occurs
*/
String getURL() throws SQLException;
/** {@collect.stats}
* Retrieves the user name as known to this database.
*
* @return the database user name
* @exception SQLException if a database access error occurs
*/
String getUserName() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database is in read-only mode.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean isReadOnly() throws SQLException;
/** {@collect.stats}
* Retrieves whether <code>NULL</code> values are sorted high.
* Sorted high means that <code>NULL</code> values
* sort higher than any other value in a domain. In an ascending order,
* if this method returns <code>true</code>, <code>NULL</code> values
* will appear at the end. By contrast, the method
* <code>nullsAreSortedAtEnd</code> indicates whether <code>NULL</code> values
* are sorted at the end regardless of sort order.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean nullsAreSortedHigh() throws SQLException;
/** {@collect.stats}
* Retrieves whether <code>NULL</code> values are sorted low.
* Sorted low means that <code>NULL</code> values
* sort lower than any other value in a domain. In an ascending order,
* if this method returns <code>true</code>, <code>NULL</code> values
* will appear at the beginning. By contrast, the method
* <code>nullsAreSortedAtStart</code> indicates whether <code>NULL</code> values
* are sorted at the beginning regardless of sort order.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean nullsAreSortedLow() throws SQLException;
/** {@collect.stats}
* Retrieves whether <code>NULL</code> values are sorted at the start regardless
* of sort order.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean nullsAreSortedAtStart() throws SQLException;
/** {@collect.stats}
* Retrieves whether <code>NULL</code> values are sorted at the end regardless of
* sort order.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean nullsAreSortedAtEnd() throws SQLException;
/** {@collect.stats}
* Retrieves the name of this database product.
*
* @return database product name
* @exception SQLException if a database access error occurs
*/
String getDatabaseProductName() throws SQLException;
/** {@collect.stats}
* Retrieves the version number of this database product.
*
* @return database version number
* @exception SQLException if a database access error occurs
*/
String getDatabaseProductVersion() throws SQLException;
/** {@collect.stats}
* Retrieves the name of this JDBC driver.
*
* @return JDBC driver name
* @exception SQLException if a database access error occurs
*/
String getDriverName() throws SQLException;
/** {@collect.stats}
* Retrieves the version number of this JDBC driver as a <code>String</code>.
*
* @return JDBC driver version
* @exception SQLException if a database access error occurs
*/
String getDriverVersion() throws SQLException;
/** {@collect.stats}
* Retrieves this JDBC driver's major version number.
*
* @return JDBC driver major version
*/
int getDriverMajorVersion();
/** {@collect.stats}
* Retrieves this JDBC driver's minor version number.
*
* @return JDBC driver minor version number
*/
int getDriverMinorVersion();
/** {@collect.stats}
* Retrieves whether this database stores tables in a local file.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean usesLocalFiles() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database uses a file for each table.
*
* @return <code>true</code> if this database uses a local file for each table;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean usesLocalFilePerTable() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database treats mixed case unquoted SQL identifiers as
* case sensitive and as a result stores them in mixed case.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsMixedCaseIdentifiers() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database treats mixed case unquoted SQL identifiers as
* case insensitive and stores them in upper case.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean storesUpperCaseIdentifiers() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database treats mixed case unquoted SQL identifiers as
* case insensitive and stores them in lower case.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean storesLowerCaseIdentifiers() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database treats mixed case unquoted SQL identifiers as
* case insensitive and stores them in mixed case.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean storesMixedCaseIdentifiers() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database treats mixed case quoted SQL identifiers as
* case sensitive and as a result stores them in mixed case.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsMixedCaseQuotedIdentifiers() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database treats mixed case quoted SQL identifiers as
* case insensitive and stores them in upper case.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean storesUpperCaseQuotedIdentifiers() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database treats mixed case quoted SQL identifiers as
* case insensitive and stores them in lower case.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean storesLowerCaseQuotedIdentifiers() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database treats mixed case quoted SQL identifiers as
* case insensitive and stores them in mixed case.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean storesMixedCaseQuotedIdentifiers() throws SQLException;
/** {@collect.stats}
* Retrieves the string used to quote SQL identifiers.
* This method returns a space " " if identifier quoting is not supported.
*
* @return the quoting string or a space if quoting is not supported
* @exception SQLException if a database access error occurs
*/
String getIdentifierQuoteString() throws SQLException;
/** {@collect.stats}
* Retrieves a comma-separated list of all of this database's SQL keywords
* that are NOT also SQL:2003 keywords.
*
* @return the list of this database's keywords that are not also
* SQL:2003 keywords
* @exception SQLException if a database access error occurs
*/
String getSQLKeywords() throws SQLException;
/** {@collect.stats}
* Retrieves a comma-separated list of math functions available with
* this database. These are the Open /Open CLI math function names used in
* the JDBC function escape clause.
*
* @return the list of math functions supported by this database
* @exception SQLException if a database access error occurs
*/
String getNumericFunctions() throws SQLException;
/** {@collect.stats}
* Retrieves a comma-separated list of string functions available with
* this database. These are the Open Group CLI string function names used
* in the JDBC function escape clause.
*
* @return the list of string functions supported by this database
* @exception SQLException if a database access error occurs
*/
String getStringFunctions() throws SQLException;
/** {@collect.stats}
* Retrieves a comma-separated list of system functions available with
* this database. These are the Open Group CLI system function names used
* in the JDBC function escape clause.
*
* @return a list of system functions supported by this database
* @exception SQLException if a database access error occurs
*/
String getSystemFunctions() throws SQLException;
/** {@collect.stats}
* Retrieves a comma-separated list of the time and date functions available
* with this database.
*
* @return the list of time and date functions supported by this database
* @exception SQLException if a database access error occurs
*/
String getTimeDateFunctions() throws SQLException;
/** {@collect.stats}
* Retrieves the string that can be used to escape wildcard characters.
* This is the string that can be used to escape '_' or '%' in
* the catalog search parameters that are a pattern (and therefore use one
* of the wildcard characters).
*
* <P>The '_' character represents any single character;
* the '%' character represents any sequence of zero or
* more characters.
*
* @return the string used to escape wildcard characters
* @exception SQLException if a database access error occurs
*/
String getSearchStringEscape() throws SQLException;
/** {@collect.stats}
* Retrieves all the "extra" characters that can be used in unquoted
* identifier names (those beyond a-z, A-Z, 0-9 and _).
*
* @return the string containing the extra characters
* @exception SQLException if a database access error occurs
*/
String getExtraNameCharacters() throws SQLException;
//--------------------------------------------------------------------
// Functions describing which features are supported.
/** {@collect.stats}
* Retrieves whether this database supports <code>ALTER TABLE</code>
* with add column.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsAlterTableWithAddColumn() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports <code>ALTER TABLE</code>
* with drop column.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsAlterTableWithDropColumn() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports column aliasing.
*
* <P>If so, the SQL AS clause can be used to provide names for
* computed columns or to provide alias names for columns as
* required.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsColumnAliasing() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports concatenations between
* <code>NULL</code> and non-<code>NULL</code> values being
* <code>NULL</code>.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean nullPlusNonNullIsNull() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports the JDBC scalar function
* <code>CONVERT</code> for the conversion of one JDBC type to another.
* The JDBC types are the generic SQL data types defined
* in <code>java.sql.Types</code>.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsConvert() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports the JDBC scalar function
* <code>CONVERT</code> for conversions between the JDBC types <i>fromType</i>
* and <i>toType</i>. The JDBC types are the generic SQL data types defined
* in <code>java.sql.Types</code>.
*
* @param fromType the type to convert from; one of the type codes from
* the class <code>java.sql.Types</code>
* @param toType the type to convert to; one of the type codes from
* the class <code>java.sql.Types</code>
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @see Types
*/
boolean supportsConvert(int fromType, int toType) throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports table correlation names.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsTableCorrelationNames() throws SQLException;
/** {@collect.stats}
* Retrieves whether, when table correlation names are supported, they
* are restricted to being different from the names of the tables.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsDifferentTableCorrelationNames() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports expressions in
* <code>ORDER BY</code> lists.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsExpressionsInOrderBy() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports using a column that is
* not in the <code>SELECT</code> statement in an
* <code>ORDER BY</code> clause.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsOrderByUnrelated() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports some form of
* <code>GROUP BY</code> clause.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsGroupBy() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports using a column that is
* not in the <code>SELECT</code> statement in a
* <code>GROUP BY</code> clause.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsGroupByUnrelated() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports using columns not included in
* the <code>SELECT</code> statement in a <code>GROUP BY</code> clause
* provided that all of the columns in the <code>SELECT</code> statement
* are included in the <code>GROUP BY</code> clause.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsGroupByBeyondSelect() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports specifying a
* <code>LIKE</code> escape clause.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsLikeEscapeClause() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports getting multiple
* <code>ResultSet</code> objects from a single call to the
* method <code>execute</code>.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsMultipleResultSets() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database allows having multiple
* transactions open at once (on different connections).
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsMultipleTransactions() throws SQLException;
/** {@collect.stats}
* Retrieves whether columns in this database may be defined as non-nullable.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsNonNullableColumns() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports the ODBC Minimum SQL grammar.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsMinimumSQLGrammar() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports the ODBC Core SQL grammar.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsCoreSQLGrammar() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports the ODBC Extended SQL grammar.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsExtendedSQLGrammar() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports the ANSI92 entry level SQL
* grammar.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsANSI92EntryLevelSQL() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports the ANSI92 intermediate SQL grammar supported.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsANSI92IntermediateSQL() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports the ANSI92 full SQL grammar supported.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsANSI92FullSQL() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports the SQL Integrity
* Enhancement Facility.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsIntegrityEnhancementFacility() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports some form of outer join.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsOuterJoins() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports full nested outer joins.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsFullOuterJoins() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database provides limited support for outer
* joins. (This will be <code>true</code> if the method
* <code>supportsFullOuterJoins</code> returns <code>true</code>).
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsLimitedOuterJoins() throws SQLException;
/** {@collect.stats}
* Retrieves the database vendor's preferred term for "schema".
*
* @return the vendor term for "schema"
* @exception SQLException if a database access error occurs
*/
String getSchemaTerm() throws SQLException;
/** {@collect.stats}
* Retrieves the database vendor's preferred term for "procedure".
*
* @return the vendor term for "procedure"
* @exception SQLException if a database access error occurs
*/
String getProcedureTerm() throws SQLException;
/** {@collect.stats}
* Retrieves the database vendor's preferred term for "catalog".
*
* @return the vendor term for "catalog"
* @exception SQLException if a database access error occurs
*/
String getCatalogTerm() throws SQLException;
/** {@collect.stats}
* Retrieves whether a catalog appears at the start of a fully qualified
* table name. If not, the catalog appears at the end.
*
* @return <code>true</code> if the catalog name appears at the beginning
* of a fully qualified table name; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean isCatalogAtStart() throws SQLException;
/** {@collect.stats}
* Retrieves the <code>String</code> that this database uses as the
* separator between a catalog and table name.
*
* @return the separator string
* @exception SQLException if a database access error occurs
*/
String getCatalogSeparator() throws SQLException;
/** {@collect.stats}
* Retrieves whether a schema name can be used in a data manipulation statement.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsSchemasInDataManipulation() throws SQLException;
/** {@collect.stats}
* Retrieves whether a schema name can be used in a procedure call statement.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsSchemasInProcedureCalls() throws SQLException;
/** {@collect.stats}
* Retrieves whether a schema name can be used in a table definition statement.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsSchemasInTableDefinitions() throws SQLException;
/** {@collect.stats}
* Retrieves whether a schema name can be used in an index definition statement.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsSchemasInIndexDefinitions() throws SQLException;
/** {@collect.stats}
* Retrieves whether a schema name can be used in a privilege definition statement.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsSchemasInPrivilegeDefinitions() throws SQLException;
/** {@collect.stats}
* Retrieves whether a catalog name can be used in a data manipulation statement.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsCatalogsInDataManipulation() throws SQLException;
/** {@collect.stats}
* Retrieves whether a catalog name can be used in a procedure call statement.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsCatalogsInProcedureCalls() throws SQLException;
/** {@collect.stats}
* Retrieves whether a catalog name can be used in a table definition statement.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsCatalogsInTableDefinitions() throws SQLException;
/** {@collect.stats}
* Retrieves whether a catalog name can be used in an index definition statement.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsCatalogsInIndexDefinitions() throws SQLException;
/** {@collect.stats}
* Retrieves whether a catalog name can be used in a privilege definition statement.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports positioned <code>DELETE</code>
* statements.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsPositionedDelete() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports positioned <code>UPDATE</code>
* statements.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsPositionedUpdate() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports <code>SELECT FOR UPDATE</code>
* statements.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsSelectForUpdate() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports stored procedure calls
* that use the stored procedure escape syntax.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsStoredProcedures() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports subqueries in comparison
* expressions.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsSubqueriesInComparisons() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports subqueries in
* <code>EXISTS</code> expressions.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsSubqueriesInExists() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports subqueries in
* <code>IN</code> expressions.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsSubqueriesInIns() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports subqueries in quantified
* expressions.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsSubqueriesInQuantifieds() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports correlated subqueries.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsCorrelatedSubqueries() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports SQL <code>UNION</code>.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsUnion() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports SQL <code>UNION ALL</code>.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsUnionAll() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports keeping cursors open
* across commits.
*
* @return <code>true</code> if cursors always remain open;
* <code>false</code> if they might not remain open
* @exception SQLException if a database access error occurs
*/
boolean supportsOpenCursorsAcrossCommit() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports keeping cursors open
* across rollbacks.
*
* @return <code>true</code> if cursors always remain open;
* <code>false</code> if they might not remain open
* @exception SQLException if a database access error occurs
*/
boolean supportsOpenCursorsAcrossRollback() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports keeping statements open
* across commits.
*
* @return <code>true</code> if statements always remain open;
* <code>false</code> if they might not remain open
* @exception SQLException if a database access error occurs
*/
boolean supportsOpenStatementsAcrossCommit() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports keeping statements open
* across rollbacks.
*
* @return <code>true</code> if statements always remain open;
* <code>false</code> if they might not remain open
* @exception SQLException if a database access error occurs
*/
boolean supportsOpenStatementsAcrossRollback() throws SQLException;
//----------------------------------------------------------------------
// The following group of methods exposes various limitations
// based on the target database with the current driver.
// Unless otherwise specified, a result of zero means there is no
// limit, or the limit is not known.
/** {@collect.stats}
* Retrieves the maximum number of hex characters this database allows in an
* inline binary literal.
*
* @return max the maximum length (in hex characters) for a binary literal;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxBinaryLiteralLength() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of characters this database allows
* for a character literal.
*
* @return the maximum number of characters allowed for a character literal;
* a result of zero means that there is no limit or the limit is
* not known
* @exception SQLException if a database access error occurs
*/
int getMaxCharLiteralLength() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of characters this database allows
* for a column name.
*
* @return the maximum number of characters allowed for a column name;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxColumnNameLength() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of columns this database allows in a
* <code>GROUP BY</code> clause.
*
* @return the maximum number of columns allowed;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxColumnsInGroupBy() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of columns this database allows in an index.
*
* @return the maximum number of columns allowed;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxColumnsInIndex() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of columns this database allows in an
* <code>ORDER BY</code> clause.
*
* @return the maximum number of columns allowed;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxColumnsInOrderBy() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of columns this database allows in a
* <code>SELECT</code> list.
*
* @return the maximum number of columns allowed;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxColumnsInSelect() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of columns this database allows in a table.
*
* @return the maximum number of columns allowed;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxColumnsInTable() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of concurrent connections to this
* database that are possible.
*
* @return the maximum number of active connections possible at one time;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxConnections() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of characters that this database allows in a
* cursor name.
*
* @return the maximum number of characters allowed in a cursor name;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxCursorNameLength() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of bytes this database allows for an
* index, including all of the parts of the index.
*
* @return the maximum number of bytes allowed; this limit includes the
* composite of all the constituent parts of the index;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxIndexLength() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of characters that this database allows in a
* schema name.
*
* @return the maximum number of characters allowed in a schema name;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxSchemaNameLength() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of characters that this database allows in a
* procedure name.
*
* @return the maximum number of characters allowed in a procedure name;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxProcedureNameLength() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of characters that this database allows in a
* catalog name.
*
* @return the maximum number of characters allowed in a catalog name;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxCatalogNameLength() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of bytes this database allows in
* a single row.
*
* @return the maximum number of bytes allowed for a row; a result of
* zero means that there is no limit or the limit is not known
* @exception SQLException if a database access error occurs
*/
int getMaxRowSize() throws SQLException;
/** {@collect.stats}
* Retrieves whether the return value for the method
* <code>getMaxRowSize</code> includes the SQL data types
* <code>LONGVARCHAR</code> and <code>LONGVARBINARY</code>.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean doesMaxRowSizeIncludeBlobs() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of characters this database allows in
* an SQL statement.
*
* @return the maximum number of characters allowed for an SQL statement;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxStatementLength() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of active statements to this database
* that can be open at the same time.
*
* @return the maximum number of statements that can be open at one time;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxStatements() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of characters this database allows in
* a table name.
*
* @return the maximum number of characters allowed for a table name;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxTableNameLength() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of tables this database allows in a
* <code>SELECT</code> statement.
*
* @return the maximum number of tables allowed in a <code>SELECT</code>
* statement; a result of zero means that there is no limit or
* the limit is not known
* @exception SQLException if a database access error occurs
*/
int getMaxTablesInSelect() throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of characters this database allows in
* a user name.
*
* @return the maximum number of characters allowed for a user name;
* a result of zero means that there is no limit or the limit
* is not known
* @exception SQLException if a database access error occurs
*/
int getMaxUserNameLength() throws SQLException;
//----------------------------------------------------------------------
/** {@collect.stats}
* Retrieves this database's default transaction isolation level. The
* possible values are defined in <code>java.sql.Connection</code>.
*
* @return the default isolation level
* @exception SQLException if a database access error occurs
* @see Connection
*/
int getDefaultTransactionIsolation() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports transactions. If not, invoking the
* method <code>commit</code> is a noop, and the isolation level is
* <code>TRANSACTION_NONE</code>.
*
* @return <code>true</code> if transactions are supported;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsTransactions() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports the given transaction isolation level.
*
* @param level one of the transaction isolation levels defined in
* <code>java.sql.Connection</code>
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @see Connection
*/
boolean supportsTransactionIsolationLevel(int level)
throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports both data definition and
* data manipulation statements within a transaction.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsDataDefinitionAndDataManipulationTransactions()
throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports only data manipulation
* statements within a transaction.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean supportsDataManipulationTransactionsOnly()
throws SQLException;
/** {@collect.stats}
* Retrieves whether a data definition statement within a transaction forces
* the transaction to commit.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean dataDefinitionCausesTransactionCommit()
throws SQLException;
/** {@collect.stats}
* Retrieves whether this database ignores a data definition statement
* within a transaction.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean dataDefinitionIgnoredInTransactions()
throws SQLException;
/** {@collect.stats}
* Retrieves a description of the stored procedures available in the given
* catalog.
* <P>
* Only procedure descriptions matching the schema and
* procedure name criteria are returned. They are ordered by
* <code>PROCEDURE_CAT</code>, <code>PROCEDURE_SCHEM</code>,
* <code>PROCEDURE_NAME</code> and <code>SPECIFIC_ NAME</code>.
*
* <P>Each procedure description has the the following columns:
* <OL>
* <LI><B>PROCEDURE_CAT</B> String => procedure catalog (may be <code>null</code>)
* <LI><B>PROCEDURE_SCHEM</B> String => procedure schema (may be <code>null</code>)
* <LI><B>PROCEDURE_NAME</B> String => procedure name
* <LI> reserved for future use
* <LI> reserved for future use
* <LI> reserved for future use
* <LI><B>REMARKS</B> String => explanatory comment on the procedure
* <LI><B>PROCEDURE_TYPE</B> short => kind of procedure:
* <UL>
* <LI> procedureResultUnknown - Cannot determine if a return value
* will be returned
* <LI> procedureNoResult - Does not return a return value
* <LI> procedureReturnsResult - Returns a return value
* </UL>
* <LI><B>SPECIFIC_NAME</B> String => The name which uniquely identifies this
* procedure within its schema.
* </OL>
* <p>
* A user may not have permissions to execute any of the procedures that are
* returned by <code>getProcedures</code>
*
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schemaPattern a schema name pattern; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param procedureNamePattern a procedure name pattern; must match the
* procedure name as it is stored in the database
* @return <code>ResultSet</code> - each row is a procedure description
* @exception SQLException if a database access error occurs
* @see #getSearchStringEscape
*/
ResultSet getProcedures(String catalog, String schemaPattern,
String procedureNamePattern) throws SQLException;
/** {@collect.stats}
* Indicates that it is not known whether the procedure returns
* a result.
* <P>
* A possible value for column <code>PROCEDURE_TYPE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getProcedures</code>.
*/
int procedureResultUnknown = 0;
/** {@collect.stats}
* Indicates that the procedure does not return a result.
* <P>
* A possible value for column <code>PROCEDURE_TYPE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getProcedures</code>.
*/
int procedureNoResult = 1;
/** {@collect.stats}
* Indicates that the procedure returns a result.
* <P>
* A possible value for column <code>PROCEDURE_TYPE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getProcedures</code>.
*/
int procedureReturnsResult = 2;
/** {@collect.stats}
* Retrieves a description of the given catalog's stored procedure parameter
* and result columns.
*
* <P>Only descriptions matching the schema, procedure and
* parameter name criteria are returned. They are ordered by
* PROCEDURE_CAT, PROCEDURE_SCHEM, PROCEDURE_NAME and SPECIFIC_NAME. Within this, the return value,
* if any, is first. Next are the parameter descriptions in call
* order. The column descriptions follow in column number order.
*
* <P>Each row in the <code>ResultSet</code> is a parameter description or
* column description with the following fields:
* <OL>
* <LI><B>PROCEDURE_CAT</B> String => procedure catalog (may be <code>null</code>)
* <LI><B>PROCEDURE_SCHEM</B> String => procedure schema (may be <code>null</code>)
* <LI><B>PROCEDURE_NAME</B> String => procedure name
* <LI><B>COLUMN_NAME</B> String => column/parameter name
* <LI><B>COLUMN_TYPE</B> Short => kind of column/parameter:
* <UL>
* <LI> procedureColumnUnknown - nobody knows
* <LI> procedureColumnIn - IN parameter
* <LI> procedureColumnInOut - INOUT parameter
* <LI> procedureColumnOut - OUT parameter
* <LI> procedureColumnReturn - procedure return value
* <LI> procedureColumnResult - result column in <code>ResultSet</code>
* </UL>
* <LI><B>DATA_TYPE</B> int => SQL type from java.sql.Types
* <LI><B>TYPE_NAME</B> String => SQL type name, for a UDT type the
* type name is fully qualified
* <LI><B>PRECISION</B> int => precision
* <LI><B>LENGTH</B> int => length in bytes of data
* <LI><B>SCALE</B> short => scale - null is returned for data types where
* SCALE is not applicable.
* <LI><B>RADIX</B> short => radix
* <LI><B>NULLABLE</B> short => can it contain NULL.
* <UL>
* <LI> procedureNoNulls - does not allow NULL values
* <LI> procedureNullable - allows NULL values
* <LI> procedureNullableUnknown - nullability unknown
* </UL>
* <LI><B>REMARKS</B> String => comment describing parameter/column
* <LI><B>COLUMN_DEF</B> String => default value for the column, which should be interpreted as a string when the value is enclosed in single quotes (may be <code>null</code>)
* <UL>
* <LI> The string NULL (not enclosed in quotes) - if NULL was specified as the default value
* <LI> TRUNCATE (not enclosed in quotes) - if the specified default value cannot be represented without truncation
* <LI> NULL - if a default value was not specified
* </UL>
* <LI><B>SQL_DATA_TYPE</B> int => reserved for future use
* <LI><B>SQL_DATETIME_SUB</B> int => reserved for future use
* <LI><B>CHAR_OCTET_LENGTH</B> int => the maximum length of binary and character based columns. For any other datatype the returned value is a
* NULL
* <LI><B>ORDINAL_POSITION</B> int => the ordinal position, starting from 1, for the input and output parameters for a procedure. A value of 0
*is returned if this row describes the procedure's return value. For result set columns, it is the
*ordinal position of the column in the result set starting from 1. If there are
*multiple result sets, the column ordinal positions are implementation
* defined.
* <LI><B>IS_NULLABLE</B> String => ISO rules are used to determine the nullability for a column.
* <UL>
* <LI> YES --- if the parameter can include NULLs
* <LI> NO --- if the parameter cannot include NULLs
* <LI> empty string --- if the nullability for the
* parameter is unknown
* </UL>
* <LI><B>SPECIFIC_NAME</B> String => the name which uniquely identifies this procedure within its schema.
* </OL>
*
* <P><B>Note:</B> Some databases may not return the column
* descriptions for a procedure.
*
* <p>The PRECISION column represents the specified column size for the given column.
* For numeric data, this is the maximum precision. For character data, this is the length in characters.
* For datetime datatypes, this is the length in characters of the String representation (assuming the
* maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes. For the ROWID datatype,
* this is the length in bytes. Null is returned for data types where the
* column size is not applicable.
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schemaPattern a schema name pattern; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param procedureNamePattern a procedure name pattern; must match the
* procedure name as it is stored in the database
* @param columnNamePattern a column name pattern; must match the column name
* as it is stored in the database
* @return <code>ResultSet</code> - each row describes a stored procedure parameter or
* column
* @exception SQLException if a database access error occurs
* @see #getSearchStringEscape
*/
ResultSet getProcedureColumns(String catalog,
String schemaPattern,
String procedureNamePattern,
String columnNamePattern) throws SQLException;
/** {@collect.stats}
* Indicates that type of the column is unknown.
* <P>
* A possible value for the column
* <code>COLUMN_TYPE</code>
* in the <code>ResultSet</code>
* returned by the method <code>getProcedureColumns</code>.
*/
int procedureColumnUnknown = 0;
/** {@collect.stats}
* Indicates that the column stores IN parameters.
* <P>
* A possible value for the column
* <code>COLUMN_TYPE</code>
* in the <code>ResultSet</code>
* returned by the method <code>getProcedureColumns</code>.
*/
int procedureColumnIn = 1;
/** {@collect.stats}
* Indicates that the column stores INOUT parameters.
* <P>
* A possible value for the column
* <code>COLUMN_TYPE</code>
* in the <code>ResultSet</code>
* returned by the method <code>getProcedureColumns</code>.
*/
int procedureColumnInOut = 2;
/** {@collect.stats}
* Indicates that the column stores OUT parameters.
* <P>
* A possible value for the column
* <code>COLUMN_TYPE</code>
* in the <code>ResultSet</code>
* returned by the method <code>getProcedureColumns</code>.
*/
int procedureColumnOut = 4;
/** {@collect.stats}
* Indicates that the column stores return values.
* <P>
* A possible value for the column
* <code>COLUMN_TYPE</code>
* in the <code>ResultSet</code>
* returned by the method <code>getProcedureColumns</code>.
*/
int procedureColumnReturn = 5;
/** {@collect.stats}
* Indicates that the column stores results.
* <P>
* A possible value for the column
* <code>COLUMN_TYPE</code>
* in the <code>ResultSet</code>
* returned by the method <code>getProcedureColumns</code>.
*/
int procedureColumnResult = 3;
/** {@collect.stats}
* Indicates that <code>NULL</code> values are not allowed.
* <P>
* A possible value for the column
* <code>NULLABLE</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getProcedureColumns</code>.
*/
int procedureNoNulls = 0;
/** {@collect.stats}
* Indicates that <code>NULL</code> values are allowed.
* <P>
* A possible value for the column
* <code>NULLABLE</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getProcedureColumns</code>.
*/
int procedureNullable = 1;
/** {@collect.stats}
* Indicates that whether <code>NULL</code> values are allowed
* is unknown.
* <P>
* A possible value for the column
* <code>NULLABLE</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getProcedureColumns</code>.
*/
int procedureNullableUnknown = 2;
/** {@collect.stats}
* Retrieves a description of the tables available in the given catalog.
* Only table descriptions matching the catalog, schema, table
* name and type criteria are returned. They are ordered by
* <code>TABLE_TYPE</code>, <code>TABLE_CAT</code>,
* <code>TABLE_SCHEM</code> and <code>TABLE_NAME</code>.
* <P>
* Each table description has the following columns:
* <OL>
* <LI><B>TABLE_CAT</B> String => table catalog (may be <code>null</code>)
* <LI><B>TABLE_SCHEM</B> String => table schema (may be <code>null</code>)
* <LI><B>TABLE_NAME</B> String => table name
* <LI><B>TABLE_TYPE</B> String => table type. Typical types are "TABLE",
* "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
* "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
* <LI><B>REMARKS</B> String => explanatory comment on the table
* <LI><B>TYPE_CAT</B> String => the types catalog (may be <code>null</code>)
* <LI><B>TYPE_SCHEM</B> String => the types schema (may be <code>null</code>)
* <LI><B>TYPE_NAME</B> String => type name (may be <code>null</code>)
* <LI><B>SELF_REFERENCING_COL_NAME</B> String => name of the designated
* "identifier" column of a typed table (may be <code>null</code>)
* <LI><B>REF_GENERATION</B> String => specifies how values in
* SELF_REFERENCING_COL_NAME are created. Values are
* "SYSTEM", "USER", "DERIVED". (may be <code>null</code>)
* </OL>
*
* <P><B>Note:</B> Some databases may not return information for
* all tables.
*
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schemaPattern a schema name pattern; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param tableNamePattern a table name pattern; must match the
* table name as it is stored in the database
* @param types a list of table types, which must be from the list of table types
* returned from {@link #getTableTypes},to include; <code>null</code> returns
* all types
* @return <code>ResultSet</code> - each row is a table description
* @exception SQLException if a database access error occurs
* @see #getSearchStringEscape
*/
ResultSet getTables(String catalog, String schemaPattern,
String tableNamePattern, String types[]) throws SQLException;
/** {@collect.stats}
* Retrieves the schema names available in this database. The results
* are ordered by <code>TABLE_CATALOG</code> and
* <code>TABLE_SCHEM</code>.
*
* <P>The schema columns are:
* <OL>
* <LI><B>TABLE_SCHEM</B> String => schema name
* <LI><B>TABLE_CATALOG</B> String => catalog name (may be <code>null</code>)
* </OL>
*
* @return a <code>ResultSet</code> object in which each row is a
* schema description
* @exception SQLException if a database access error occurs
*
*/
ResultSet getSchemas() throws SQLException;
/** {@collect.stats}
* Retrieves the catalog names available in this database. The results
* are ordered by catalog name.
*
* <P>The catalog column is:
* <OL>
* <LI><B>TABLE_CAT</B> String => catalog name
* </OL>
*
* @return a <code>ResultSet</code> object in which each row has a
* single <code>String</code> column that is a catalog name
* @exception SQLException if a database access error occurs
*/
ResultSet getCatalogs() throws SQLException;
/** {@collect.stats}
* Retrieves the table types available in this database. The results
* are ordered by table type.
*
* <P>The table type is:
* <OL>
* <LI><B>TABLE_TYPE</B> String => table type. Typical types are "TABLE",
* "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY",
* "LOCAL TEMPORARY", "ALIAS", "SYNONYM".
* </OL>
*
* @return a <code>ResultSet</code> object in which each row has a
* single <code>String</code> column that is a table type
* @exception SQLException if a database access error occurs
*/
ResultSet getTableTypes() throws SQLException;
/** {@collect.stats}
* Retrieves a description of table columns available in
* the specified catalog.
*
* <P>Only column descriptions matching the catalog, schema, table
* and column name criteria are returned. They are ordered by
* <code>TABLE_CAT</code>,<code>TABLE_SCHEM</code>,
* <code>TABLE_NAME</code>, and <code>ORDINAL_POSITION</code>.
*
* <P>Each column description has the following columns:
* <OL>
* <LI><B>TABLE_CAT</B> String => table catalog (may be <code>null</code>)
* <LI><B>TABLE_SCHEM</B> String => table schema (may be <code>null</code>)
* <LI><B>TABLE_NAME</B> String => table name
* <LI><B>COLUMN_NAME</B> String => column name
* <LI><B>DATA_TYPE</B> int => SQL type from java.sql.Types
* <LI><B>TYPE_NAME</B> String => Data source dependent type name,
* for a UDT the type name is fully qualified
* <LI><B>COLUMN_SIZE</B> int => column size.
* <LI><B>BUFFER_LENGTH</B> is not used.
* <LI><B>DECIMAL_DIGITS</B> int => the number of fractional digits. Null is returned for data types where
* DECIMAL_DIGITS is not applicable.
* <LI><B>NUM_PREC_RADIX</B> int => Radix (typically either 10 or 2)
* <LI><B>NULLABLE</B> int => is NULL allowed.
* <UL>
* <LI> columnNoNulls - might not allow <code>NULL</code> values
* <LI> columnNullable - definitely allows <code>NULL</code> values
* <LI> columnNullableUnknown - nullability unknown
* </UL>
* <LI><B>REMARKS</B> String => comment describing column (may be <code>null</code>)
* <LI><B>COLUMN_DEF</B> String => default value for the column, which should be interpreted as a string when the value is enclosed in single quotes (may be <code>null</code>)
* <LI><B>SQL_DATA_TYPE</B> int => unused
* <LI><B>SQL_DATETIME_SUB</B> int => unused
* <LI><B>CHAR_OCTET_LENGTH</B> int => for char types the
* maximum number of bytes in the column
* <LI><B>ORDINAL_POSITION</B> int => index of column in table
* (starting at 1)
* <LI><B>IS_NULLABLE</B> String => ISO rules are used to determine the nullability for a column.
* <UL>
* <LI> YES --- if the parameter can include NULLs
* <LI> NO --- if the parameter cannot include NULLs
* <LI> empty string --- if the nullability for the
* parameter is unknown
* </UL>
* <LI><B>SCOPE_CATLOG</B> String => catalog of table that is the scope
* of a reference attribute (<code>null</code> if DATA_TYPE isn't REF)
* <LI><B>SCOPE_SCHEMA</B> String => schema of table that is the scope
* of a reference attribute (<code>null</code> if the DATA_TYPE isn't REF)
* <LI><B>SCOPE_TABLE</B> String => table name that this the scope
* of a reference attribure (<code>null</code> if the DATA_TYPE isn't REF)
* <LI><B>SOURCE_DATA_TYPE</B> short => source type of a distinct type or user-generated
* Ref type, SQL type from java.sql.Types (<code>null</code> if DATA_TYPE
* isn't DISTINCT or user-generated REF)
* <LI><B>IS_AUTOINCREMENT</B> String => Indicates whether this column is auto incremented
* <UL>
* <LI> YES --- if the column is auto incremented
* <LI> NO --- if the column is not auto incremented
* <LI> empty string --- if it cannot be determined whether the column is auto incremented
* parameter is unknown
* </UL>
* </OL>
*
* <p>The COLUMN_SIZE column the specified column size for the given column.
* For numeric data, this is the maximum precision. For character data, this is the length in characters.
* For datetime datatypes, this is the length in characters of the String representation (assuming the
* maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes. For the ROWID datatype,
* this is the length in bytes. Null is returned for data types where the
* column size is not applicable.
*
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schemaPattern a schema name pattern; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param tableNamePattern a table name pattern; must match the
* table name as it is stored in the database
* @param columnNamePattern a column name pattern; must match the column
* name as it is stored in the database
* @return <code>ResultSet</code> - each row is a column description
* @exception SQLException if a database access error occurs
* @see #getSearchStringEscape
*/
ResultSet getColumns(String catalog, String schemaPattern,
String tableNamePattern, String columnNamePattern)
throws SQLException;
/** {@collect.stats}
* Indicates that the column might not allow <code>NULL</code> values.
* <P>
* A possible value for the column
* <code>NULLABLE</code>
* in the <code>ResultSet</code> returned by the method
* <code>getColumns</code>.
*/
int columnNoNulls = 0;
/** {@collect.stats}
* Indicates that the column definitely allows <code>NULL</code> values.
* <P>
* A possible value for the column
* <code>NULLABLE</code>
* in the <code>ResultSet</code> returned by the method
* <code>getColumns</code>.
*/
int columnNullable = 1;
/** {@collect.stats}
* Indicates that the nullability of columns is unknown.
* <P>
* A possible value for the column
* <code>NULLABLE</code>
* in the <code>ResultSet</code> returned by the method
* <code>getColumns</code>.
*/
int columnNullableUnknown = 2;
/** {@collect.stats}
* Retrieves a description of the access rights for a table's columns.
*
* <P>Only privileges matching the column name criteria are
* returned. They are ordered by COLUMN_NAME and PRIVILEGE.
*
* <P>Each privilige description has the following columns:
* <OL>
* <LI><B>TABLE_CAT</B> String => table catalog (may be <code>null</code>)
* <LI><B>TABLE_SCHEM</B> String => table schema (may be <code>null</code>)
* <LI><B>TABLE_NAME</B> String => table name
* <LI><B>COLUMN_NAME</B> String => column name
* <LI><B>GRANTOR</B> String => grantor of access (may be <code>null</code>)
* <LI><B>GRANTEE</B> String => grantee of access
* <LI><B>PRIVILEGE</B> String => name of access (SELECT,
* INSERT, UPDATE, REFRENCES, ...)
* <LI><B>IS_GRANTABLE</B> String => "YES" if grantee is permitted
* to grant to others; "NO" if not; <code>null</code> if unknown
* </OL>
*
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schema a schema name; must match the schema name as it is
* stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param table a table name; must match the table name as it is
* stored in the database
* @param columnNamePattern a column name pattern; must match the column
* name as it is stored in the database
* @return <code>ResultSet</code> - each row is a column privilege description
* @exception SQLException if a database access error occurs
* @see #getSearchStringEscape
*/
ResultSet getColumnPrivileges(String catalog, String schema,
String table, String columnNamePattern) throws SQLException;
/** {@collect.stats}
* Retrieves a description of the access rights for each table available
* in a catalog. Note that a table privilege applies to one or
* more columns in the table. It would be wrong to assume that
* this privilege applies to all columns (this may be true for
* some systems but is not true for all.)
*
* <P>Only privileges matching the schema and table name
* criteria are returned. They are ordered by
* <code>TABLE_CAT</code>,
* <code>TABLE_SCHEM</code>, <code>TABLE_NAME</code>,
* and <code>PRIVILEGE</code>.
*
* <P>Each privilige description has the following columns:
* <OL>
* <LI><B>TABLE_CAT</B> String => table catalog (may be <code>null</code>)
* <LI><B>TABLE_SCHEM</B> String => table schema (may be <code>null</code>)
* <LI><B>TABLE_NAME</B> String => table name
* <LI><B>GRANTOR</B> String => grantor of access (may be <code>null</code>)
* <LI><B>GRANTEE</B> String => grantee of access
* <LI><B>PRIVILEGE</B> String => name of access (SELECT,
* INSERT, UPDATE, REFRENCES, ...)
* <LI><B>IS_GRANTABLE</B> String => "YES" if grantee is permitted
* to grant to others; "NO" if not; <code>null</code> if unknown
* </OL>
*
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schemaPattern a schema name pattern; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param tableNamePattern a table name pattern; must match the
* table name as it is stored in the database
* @return <code>ResultSet</code> - each row is a table privilege description
* @exception SQLException if a database access error occurs
* @see #getSearchStringEscape
*/
ResultSet getTablePrivileges(String catalog, String schemaPattern,
String tableNamePattern) throws SQLException;
/** {@collect.stats}
* Retrieves a description of a table's optimal set of columns that
* uniquely identifies a row. They are ordered by SCOPE.
*
* <P>Each column description has the following columns:
* <OL>
* <LI><B>SCOPE</B> short => actual scope of result
* <UL>
* <LI> bestRowTemporary - very temporary, while using row
* <LI> bestRowTransaction - valid for remainder of current transaction
* <LI> bestRowSession - valid for remainder of current session
* </UL>
* <LI><B>COLUMN_NAME</B> String => column name
* <LI><B>DATA_TYPE</B> int => SQL data type from java.sql.Types
* <LI><B>TYPE_NAME</B> String => Data source dependent type name,
* for a UDT the type name is fully qualified
* <LI><B>COLUMN_SIZE</B> int => precision
* <LI><B>BUFFER_LENGTH</B> int => not used
* <LI><B>DECIMAL_DIGITS</B> short => scale - Null is returned for data types where
* DECIMAL_DIGITS is not applicable.
* <LI><B>PSEUDO_COLUMN</B> short => is this a pseudo column
* like an Oracle ROWID
* <UL>
* <LI> bestRowUnknown - may or may not be pseudo column
* <LI> bestRowNotPseudo - is NOT a pseudo column
* <LI> bestRowPseudo - is a pseudo column
* </UL>
* </OL>
*
* <p>The COLUMN_SIZE column represents the specified column size for the given column.
* For numeric data, this is the maximum precision. For character data, this is the length in characters.
* For datetime datatypes, this is the length in characters of the String representation (assuming the
* maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes. For the ROWID datatype,
* this is the length in bytes. Null is returned for data types where the
* column size is not applicable.
*
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schema a schema name; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param table a table name; must match the table name as it is stored
* in the database
* @param scope the scope of interest; use same values as SCOPE
* @param nullable include columns that are nullable.
* @return <code>ResultSet</code> - each row is a column description
* @exception SQLException if a database access error occurs
*/
ResultSet getBestRowIdentifier(String catalog, String schema,
String table, int scope, boolean nullable) throws SQLException;
/** {@collect.stats}
* Indicates that the scope of the best row identifier is
* very temporary, lasting only while the
* row is being used.
* <P>
* A possible value for the column
* <code>SCOPE</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getBestRowIdentifier</code>.
*/
int bestRowTemporary = 0;
/** {@collect.stats}
* Indicates that the scope of the best row identifier is
* the remainder of the current transaction.
* <P>
* A possible value for the column
* <code>SCOPE</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getBestRowIdentifier</code>.
*/
int bestRowTransaction = 1;
/** {@collect.stats}
* Indicates that the scope of the best row identifier is
* the remainder of the current session.
* <P>
* A possible value for the column
* <code>SCOPE</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getBestRowIdentifier</code>.
*/
int bestRowSession = 2;
/** {@collect.stats}
* Indicates that the best row identifier may or may not be a pseudo column.
* <P>
* A possible value for the column
* <code>PSEUDO_COLUMN</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getBestRowIdentifier</code>.
*/
int bestRowUnknown = 0;
/** {@collect.stats}
* Indicates that the best row identifier is NOT a pseudo column.
* <P>
* A possible value for the column
* <code>PSEUDO_COLUMN</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getBestRowIdentifier</code>.
*/
int bestRowNotPseudo = 1;
/** {@collect.stats}
* Indicates that the best row identifier is a pseudo column.
* <P>
* A possible value for the column
* <code>PSEUDO_COLUMN</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getBestRowIdentifier</code>.
*/
int bestRowPseudo = 2;
/** {@collect.stats}
* Retrieves a description of a table's columns that are automatically
* updated when any value in a row is updated. They are
* unordered.
*
* <P>Each column description has the following columns:
* <OL>
* <LI><B>SCOPE</B> short => is not used
* <LI><B>COLUMN_NAME</B> String => column name
* <LI><B>DATA_TYPE</B> int => SQL data type from <code>java.sql.Types</code>
* <LI><B>TYPE_NAME</B> String => Data source-dependent type name
* <LI><B>COLUMN_SIZE</B> int => precision
* <LI><B>BUFFER_LENGTH</B> int => length of column value in bytes
* <LI><B>DECIMAL_DIGITS</B> short => scale - Null is returned for data types where
* DECIMAL_DIGITS is not applicable.
* <LI><B>PSEUDO_COLUMN</B> short => whether this is pseudo column
* like an Oracle ROWID
* <UL>
* <LI> versionColumnUnknown - may or may not be pseudo column
* <LI> versionColumnNotPseudo - is NOT a pseudo column
* <LI> versionColumnPseudo - is a pseudo column
* </UL>
* </OL>
*
* <p>The COLUMN_SIZE column represents the specified column size for the given column.
* For numeric data, this is the maximum precision. For character data, this is the length in characters.
* For datetime datatypes, this is the length in characters of the String representation (assuming the
* maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes. For the ROWID datatype,
* this is the length in bytes. Null is returned for data types where the
* column size is not applicable.
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schema a schema name; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param table a table name; must match the table name as it is stored
* in the database
* @return a <code>ResultSet</code> object in which each row is a
* column description
* @exception SQLException if a database access error occurs
*/
ResultSet getVersionColumns(String catalog, String schema,
String table) throws SQLException;
/** {@collect.stats}
* Indicates that this version column may or may not be a pseudo column.
* <P>
* A possible value for the column
* <code>PSEUDO_COLUMN</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getVersionColumns</code>.
*/
int versionColumnUnknown = 0;
/** {@collect.stats}
* Indicates that this version column is NOT a pseudo column.
* <P>
* A possible value for the column
* <code>PSEUDO_COLUMN</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getVersionColumns</code>.
*/
int versionColumnNotPseudo = 1;
/** {@collect.stats}
* Indicates that this version column is a pseudo column.
* <P>
* A possible value for the column
* <code>PSEUDO_COLUMN</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getVersionColumns</code>.
*/
int versionColumnPseudo = 2;
/** {@collect.stats}
* Retrieves a description of the given table's primary key columns. They
* are ordered by COLUMN_NAME.
*
* <P>Each primary key column description has the following columns:
* <OL>
* <LI><B>TABLE_CAT</B> String => table catalog (may be <code>null</code>)
* <LI><B>TABLE_SCHEM</B> String => table schema (may be <code>null</code>)
* <LI><B>TABLE_NAME</B> String => table name
* <LI><B>COLUMN_NAME</B> String => column name
* <LI><B>KEY_SEQ</B> short => sequence number within primary key( a value
* of 1 represents the first column of the primary key, a value of 2 would
* represent the second column within the primary key).
* <LI><B>PK_NAME</B> String => primary key name (may be <code>null</code>)
* </OL>
*
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schema a schema name; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param table a table name; must match the table name as it is stored
* in the database
* @return <code>ResultSet</code> - each row is a primary key column description
* @exception SQLException if a database access error occurs
*/
ResultSet getPrimaryKeys(String catalog, String schema,
String table) throws SQLException;
/** {@collect.stats}
* Retrieves a description of the primary key columns that are
* referenced by the given table's foreign key columns (the primary keys
* imported by a table). They are ordered by PKTABLE_CAT,
* PKTABLE_SCHEM, PKTABLE_NAME, and KEY_SEQ.
*
* <P>Each primary key column description has the following columns:
* <OL>
* <LI><B>PKTABLE_CAT</B> String => primary key table catalog
* being imported (may be <code>null</code>)
* <LI><B>PKTABLE_SCHEM</B> String => primary key table schema
* being imported (may be <code>null</code>)
* <LI><B>PKTABLE_NAME</B> String => primary key table name
* being imported
* <LI><B>PKCOLUMN_NAME</B> String => primary key column name
* being imported
* <LI><B>FKTABLE_CAT</B> String => foreign key table catalog (may be <code>null</code>)
* <LI><B>FKTABLE_SCHEM</B> String => foreign key table schema (may be <code>null</code>)
* <LI><B>FKTABLE_NAME</B> String => foreign key table name
* <LI><B>FKCOLUMN_NAME</B> String => foreign key column name
* <LI><B>KEY_SEQ</B> short => sequence number within a foreign key( a value
* of 1 represents the first column of the foreign key, a value of 2 would
* represent the second column within the foreign key).
* <LI><B>UPDATE_RULE</B> short => What happens to a
* foreign key when the primary key is updated:
* <UL>
* <LI> importedNoAction - do not allow update of primary
* key if it has been imported
* <LI> importedKeyCascade - change imported key to agree
* with primary key update
* <LI> importedKeySetNull - change imported key to <code>NULL</code>
* if its primary key has been updated
* <LI> importedKeySetDefault - change imported key to default values
* if its primary key has been updated
* <LI> importedKeyRestrict - same as importedKeyNoAction
* (for ODBC 2.x compatibility)
* </UL>
* <LI><B>DELETE_RULE</B> short => What happens to
* the foreign key when primary is deleted.
* <UL>
* <LI> importedKeyNoAction - do not allow delete of primary
* key if it has been imported
* <LI> importedKeyCascade - delete rows that import a deleted key
* <LI> importedKeySetNull - change imported key to NULL if
* its primary key has been deleted
* <LI> importedKeyRestrict - same as importedKeyNoAction
* (for ODBC 2.x compatibility)
* <LI> importedKeySetDefault - change imported key to default if
* its primary key has been deleted
* </UL>
* <LI><B>FK_NAME</B> String => foreign key name (may be <code>null</code>)
* <LI><B>PK_NAME</B> String => primary key name (may be <code>null</code>)
* <LI><B>DEFERRABILITY</B> short => can the evaluation of foreign key
* constraints be deferred until commit
* <UL>
* <LI> importedKeyInitiallyDeferred - see SQL92 for definition
* <LI> importedKeyInitiallyImmediate - see SQL92 for definition
* <LI> importedKeyNotDeferrable - see SQL92 for definition
* </UL>
* </OL>
*
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schema a schema name; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param table a table name; must match the table name as it is stored
* in the database
* @return <code>ResultSet</code> - each row is a primary key column description
* @exception SQLException if a database access error occurs
* @see #getExportedKeys
*/
ResultSet getImportedKeys(String catalog, String schema,
String table) throws SQLException;
/** {@collect.stats}
* For the column <code>UPDATE_RULE</code>,
* indicates that
* when the primary key is updated, the foreign key (imported key)
* is changed to agree with it.
* For the column <code>DELETE_RULE</code>,
* it indicates that
* when the primary key is deleted, rows that imported that key
* are deleted.
* <P>
* A possible value for the columns <code>UPDATE_RULE</code>
* and <code>DELETE_RULE</code> in the
* <code>ResultSet</code> objects returned by the methods
* <code>getImportedKeys</code>, <code>getExportedKeys</code>,
* and <code>getCrossReference</code>.
*/
int importedKeyCascade = 0;
/** {@collect.stats}
* For the column <code>UPDATE_RULE</code>, indicates that
* a primary key may not be updated if it has been imported by
* another table as a foreign key.
* For the column <code>DELETE_RULE</code>, indicates that
* a primary key may not be deleted if it has been imported by
* another table as a foreign key.
* <P>
* A possible value for the columns <code>UPDATE_RULE</code>
* and <code>DELETE_RULE</code> in the
* <code>ResultSet</code> objects returned by the methods
* <code>getImportedKeys</code>, <code>getExportedKeys</code>,
* and <code>getCrossReference</code>.
*/
int importedKeyRestrict = 1;
/** {@collect.stats}
* For the columns <code>UPDATE_RULE</code>
* and <code>DELETE_RULE</code>, indicates that
* when the primary key is updated or deleted, the foreign key (imported key)
* is changed to <code>NULL</code>.
* <P>
* A possible value for the columns <code>UPDATE_RULE</code>
* and <code>DELETE_RULE</code> in the
* <code>ResultSet</code> objects returned by the methods
* <code>getImportedKeys</code>, <code>getExportedKeys</code>,
* and <code>getCrossReference</code>.
*/
int importedKeySetNull = 2;
/** {@collect.stats}
* For the columns <code>UPDATE_RULE</code>
* and <code>DELETE_RULE</code>, indicates that
* if the primary key has been imported, it cannot be updated or deleted.
* <P>
* A possible value for the columns <code>UPDATE_RULE</code>
* and <code>DELETE_RULE</code> in the
* <code>ResultSet</code> objects returned by the methods
* <code>getImportedKeys</code>, <code>getExportedKeys</code>,
* and <code>getCrossReference</code>.
*/
int importedKeyNoAction = 3;
/** {@collect.stats}
* For the columns <code>UPDATE_RULE</code>
* and <code>DELETE_RULE</code>, indicates that
* if the primary key is updated or deleted, the foreign key (imported key)
* is set to the default value.
* <P>
* A possible value for the columns <code>UPDATE_RULE</code>
* and <code>DELETE_RULE</code> in the
* <code>ResultSet</code> objects returned by the methods
* <code>getImportedKeys</code>, <code>getExportedKeys</code>,
* and <code>getCrossReference</code>.
*/
int importedKeySetDefault = 4;
/** {@collect.stats}
* Indicates deferrability. See SQL-92 for a definition.
* <P>
* A possible value for the column <code>DEFERRABILITY</code>
* in the <code>ResultSet</code> objects returned by the methods
* <code>getImportedKeys</code>, <code>getExportedKeys</code>,
* and <code>getCrossReference</code>.
*/
int importedKeyInitiallyDeferred = 5;
/** {@collect.stats}
* Indicates deferrability. See SQL-92 for a definition.
* <P>
* A possible value for the column <code>DEFERRABILITY</code>
* in the <code>ResultSet</code> objects returned by the methods
* <code>getImportedKeys</code>, <code>getExportedKeys</code>,
* and <code>getCrossReference</code>.
*/
int importedKeyInitiallyImmediate = 6;
/** {@collect.stats}
* Indicates deferrability. See SQL-92 for a definition.
* <P>
* A possible value for the column <code>DEFERRABILITY</code>
* in the <code>ResultSet</code> objects returned by the methods
* <code>getImportedKeys</code>, <code>getExportedKeys</code>,
* and <code>getCrossReference</code>.
*/
int importedKeyNotDeferrable = 7;
/** {@collect.stats}
* Retrieves a description of the foreign key columns that reference the
* given table's primary key columns (the foreign keys exported by a
* table). They are ordered by FKTABLE_CAT, FKTABLE_SCHEM,
* FKTABLE_NAME, and KEY_SEQ.
*
* <P>Each foreign key column description has the following columns:
* <OL>
* <LI><B>PKTABLE_CAT</B> String => primary key table catalog (may be <code>null</code>)
* <LI><B>PKTABLE_SCHEM</B> String => primary key table schema (may be <code>null</code>)
* <LI><B>PKTABLE_NAME</B> String => primary key table name
* <LI><B>PKCOLUMN_NAME</B> String => primary key column name
* <LI><B>FKTABLE_CAT</B> String => foreign key table catalog (may be <code>null</code>)
* being exported (may be <code>null</code>)
* <LI><B>FKTABLE_SCHEM</B> String => foreign key table schema (may be <code>null</code>)
* being exported (may be <code>null</code>)
* <LI><B>FKTABLE_NAME</B> String => foreign key table name
* being exported
* <LI><B>FKCOLUMN_NAME</B> String => foreign key column name
* being exported
* <LI><B>KEY_SEQ</B> short => sequence number within foreign key( a value
* of 1 represents the first column of the foreign key, a value of 2 would
* represent the second column within the foreign key).
* <LI><B>UPDATE_RULE</B> short => What happens to
* foreign key when primary is updated:
* <UL>
* <LI> importedNoAction - do not allow update of primary
* key if it has been imported
* <LI> importedKeyCascade - change imported key to agree
* with primary key update
* <LI> importedKeySetNull - change imported key to <code>NULL</code> if
* its primary key has been updated
* <LI> importedKeySetDefault - change imported key to default values
* if its primary key has been updated
* <LI> importedKeyRestrict - same as importedKeyNoAction
* (for ODBC 2.x compatibility)
* </UL>
* <LI><B>DELETE_RULE</B> short => What happens to
* the foreign key when primary is deleted.
* <UL>
* <LI> importedKeyNoAction - do not allow delete of primary
* key if it has been imported
* <LI> importedKeyCascade - delete rows that import a deleted key
* <LI> importedKeySetNull - change imported key to <code>NULL</code> if
* its primary key has been deleted
* <LI> importedKeyRestrict - same as importedKeyNoAction
* (for ODBC 2.x compatibility)
* <LI> importedKeySetDefault - change imported key to default if
* its primary key has been deleted
* </UL>
* <LI><B>FK_NAME</B> String => foreign key name (may be <code>null</code>)
* <LI><B>PK_NAME</B> String => primary key name (may be <code>null</code>)
* <LI><B>DEFERRABILITY</B> short => can the evaluation of foreign key
* constraints be deferred until commit
* <UL>
* <LI> importedKeyInitiallyDeferred - see SQL92 for definition
* <LI> importedKeyInitiallyImmediate - see SQL92 for definition
* <LI> importedKeyNotDeferrable - see SQL92 for definition
* </UL>
* </OL>
*
* @param catalog a catalog name; must match the catalog name as it
* is stored in this database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schema a schema name; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param table a table name; must match the table name as it is stored
* in this database
* @return a <code>ResultSet</code> object in which each row is a
* foreign key column description
* @exception SQLException if a database access error occurs
* @see #getImportedKeys
*/
ResultSet getExportedKeys(String catalog, String schema,
String table) throws SQLException;
/** {@collect.stats}
* Retrieves a description of the foreign key columns in the given foreign key
* table that reference the primary key or the columns representing a unique constraint of the parent table (could be the same or a different table).
* The number of columns returned from the parent table must match the number of
* columns that make up the foreign key. They
* are ordered by FKTABLE_CAT, FKTABLE_SCHEM, FKTABLE_NAME, and
* KEY_SEQ.
*
* <P>Each foreign key column description has the following columns:
* <OL>
* <LI><B>PKTABLE_CAT</B> String => parent key table catalog (may be <code>null</code>)
* <LI><B>PKTABLE_SCHEM</B> String => parent key table schema (may be <code>null</code>)
* <LI><B>PKTABLE_NAME</B> String => parent key table name
* <LI><B>PKCOLUMN_NAME</B> String => parent key column name
* <LI><B>FKTABLE_CAT</B> String => foreign key table catalog (may be <code>null</code>)
* being exported (may be <code>null</code>)
* <LI><B>FKTABLE_SCHEM</B> String => foreign key table schema (may be <code>null</code>)
* being exported (may be <code>null</code>)
* <LI><B>FKTABLE_NAME</B> String => foreign key table name
* being exported
* <LI><B>FKCOLUMN_NAME</B> String => foreign key column name
* being exported
* <LI><B>KEY_SEQ</B> short => sequence number within foreign key( a value
* of 1 represents the first column of the foreign key, a value of 2 would
* represent the second column within the foreign key).
* <LI><B>UPDATE_RULE</B> short => What happens to
* foreign key when parent key is updated:
* <UL>
* <LI> importedNoAction - do not allow update of parent
* key if it has been imported
* <LI> importedKeyCascade - change imported key to agree
* with parent key update
* <LI> importedKeySetNull - change imported key to <code>NULL</code> if
* its parent key has been updated
* <LI> importedKeySetDefault - change imported key to default values
* if its parent key has been updated
* <LI> importedKeyRestrict - same as importedKeyNoAction
* (for ODBC 2.x compatibility)
* </UL>
* <LI><B>DELETE_RULE</B> short => What happens to
* the foreign key when parent key is deleted.
* <UL>
* <LI> importedKeyNoAction - do not allow delete of parent
* key if it has been imported
* <LI> importedKeyCascade - delete rows that import a deleted key
* <LI> importedKeySetNull - change imported key to <code>NULL</code> if
* its primary key has been deleted
* <LI> importedKeyRestrict - same as importedKeyNoAction
* (for ODBC 2.x compatibility)
* <LI> importedKeySetDefault - change imported key to default if
* its parent key has been deleted
* </UL>
* <LI><B>FK_NAME</B> String => foreign key name (may be <code>null</code>)
* <LI><B>PK_NAME</B> String => parent key name (may be <code>null</code>)
* <LI><B>DEFERRABILITY</B> short => can the evaluation of foreign key
* constraints be deferred until commit
* <UL>
* <LI> importedKeyInitiallyDeferred - see SQL92 for definition
* <LI> importedKeyInitiallyImmediate - see SQL92 for definition
* <LI> importedKeyNotDeferrable - see SQL92 for definition
* </UL>
* </OL>
*
* @param parentCatalog a catalog name; must match the catalog name
* as it is stored in the database; "" retrieves those without a
* catalog; <code>null</code> means drop catalog name from the selection criteria
* @param parentSchema a schema name; must match the schema name as
* it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means drop schema name from the selection criteria
* @param parentTable the name of the table that exports the key; must match
* the table name as it is stored in the database
* @param foreignCatalog a catalog name; must match the catalog name as
* it is stored in the database; "" retrieves those without a
* catalog; <code>null</code> means drop catalog name from the selection criteria
* @param foreignSchema a schema name; must match the schema name as it
* is stored in the database; "" retrieves those without a schema;
* <code>null</code> means drop schema name from the selection criteria
* @param foreignTable the name of the table that imports the key; must match
* the table name as it is stored in the database
* @return <code>ResultSet</code> - each row is a foreign key column description
* @exception SQLException if a database access error occurs
* @see #getImportedKeys
*/
ResultSet getCrossReference(
String parentCatalog, String parentSchema, String parentTable,
String foreignCatalog, String foreignSchema, String foreignTable
) throws SQLException;
/** {@collect.stats}
* Retrieves a description of all the data types supported by
* this database. They are ordered by DATA_TYPE and then by how
* closely the data type maps to the corresponding JDBC SQL type.
*
* <P>If the database supports SQL distinct types, then getTypeInfo() will return
* a single row with a TYPE_NAME of DISTINCT and a DATA_TYPE of Types.DISTINCT.
* If the database supports SQL structured types, then getTypeInfo() will return
* a single row with a TYPE_NAME of STRUCT and a DATA_TYPE of Types.STRUCT.
*
* <P>If SQL distinct or structured types are supported, then information on the
* individual types may be obtained from the getUDTs() method.
*
*
* <P>Each type description has the following columns:
* <OL>
* <LI><B>TYPE_NAME</B> String => Type name
* <LI><B>DATA_TYPE</B> int => SQL data type from java.sql.Types
* <LI><B>PRECISION</B> int => maximum precision
* <LI><B>LITERAL_PREFIX</B> String => prefix used to quote a literal
* (may be <code>null</code>)
* <LI><B>LITERAL_SUFFIX</B> String => suffix used to quote a literal
(may be <code>null</code>)
* <LI><B>CREATE_PARAMS</B> String => parameters used in creating
* the type (may be <code>null</code>)
* <LI><B>NULLABLE</B> short => can you use NULL for this type.
* <UL>
* <LI> typeNoNulls - does not allow NULL values
* <LI> typeNullable - allows NULL values
* <LI> typeNullableUnknown - nullability unknown
* </UL>
* <LI><B>CASE_SENSITIVE</B> boolean=> is it case sensitive.
* <LI><B>SEARCHABLE</B> short => can you use "WHERE" based on this type:
* <UL>
* <LI> typePredNone - No support
* <LI> typePredChar - Only supported with WHERE .. LIKE
* <LI> typePredBasic - Supported except for WHERE .. LIKE
* <LI> typeSearchable - Supported for all WHERE ..
* </UL>
* <LI><B>UNSIGNED_ATTRIBUTE</B> boolean => is it unsigned.
* <LI><B>FIXED_PREC_SCALE</B> boolean => can it be a money value.
* <LI><B>AUTO_INCREMENT</B> boolean => can it be used for an
* auto-increment value.
* <LI><B>LOCAL_TYPE_NAME</B> String => localized version of type name
* (may be <code>null</code>)
* <LI><B>MINIMUM_SCALE</B> short => minimum scale supported
* <LI><B>MAXIMUM_SCALE</B> short => maximum scale supported
* <LI><B>SQL_DATA_TYPE</B> int => unused
* <LI><B>SQL_DATETIME_SUB</B> int => unused
* <LI><B>NUM_PREC_RADIX</B> int => usually 2 or 10
* </OL>
*
* <p>The PRECISION column represents the maximum column size that the server supports for the given datatype.
* For numeric data, this is the maximum precision. For character data, this is the length in characters.
* For datetime datatypes, this is the length in characters of the String representation (assuming the
* maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes. For the ROWID datatype,
* this is the length in bytes. Null is returned for data types where the
* column size is not applicable.
*
* @return a <code>ResultSet</code> object in which each row is an SQL
* type description
* @exception SQLException if a database access error occurs
*/
ResultSet getTypeInfo() throws SQLException;
/** {@collect.stats}
* Indicates that a <code>NULL</code> value is NOT allowed for this
* data type.
* <P>
* A possible value for column <code>NULLABLE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getTypeInfo</code>.
*/
int typeNoNulls = 0;
/** {@collect.stats}
* Indicates that a <code>NULL</code> value is allowed for this
* data type.
* <P>
* A possible value for column <code>NULLABLE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getTypeInfo</code>.
*/
int typeNullable = 1;
/** {@collect.stats}
* Indicates that it is not known whether a <code>NULL</code> value
* is allowed for this data type.
* <P>
* A possible value for column <code>NULLABLE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getTypeInfo</code>.
*/
int typeNullableUnknown = 2;
/** {@collect.stats}
* Indicates that <code>WHERE</code> search clauses are not supported
* for this type.
* <P>
* A possible value for column <code>SEARCHABLE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getTypeInfo</code>.
*/
int typePredNone = 0;
/** {@collect.stats}
* Indicates that the data type
* can be only be used in <code>WHERE</code> search clauses
* that use <code>LIKE</code> predicates.
* <P>
* A possible value for column <code>SEARCHABLE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getTypeInfo</code>.
*/
int typePredChar = 1;
/** {@collect.stats}
* Indicates that the data type can be only be used in <code>WHERE</code>
* search clauses
* that do not use <code>LIKE</code> predicates.
* <P>
* A possible value for column <code>SEARCHABLE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getTypeInfo</code>.
*/
int typePredBasic = 2;
/** {@collect.stats}
* Indicates that all <code>WHERE</code> search clauses can be
* based on this type.
* <P>
* A possible value for column <code>SEARCHABLE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getTypeInfo</code>.
*/
int typeSearchable = 3;
/** {@collect.stats}
* Retrieves a description of the given table's indices and statistics. They are
* ordered by NON_UNIQUE, TYPE, INDEX_NAME, and ORDINAL_POSITION.
*
* <P>Each index column description has the following columns:
* <OL>
* <LI><B>TABLE_CAT</B> String => table catalog (may be <code>null</code>)
* <LI><B>TABLE_SCHEM</B> String => table schema (may be <code>null</code>)
* <LI><B>TABLE_NAME</B> String => table name
* <LI><B>NON_UNIQUE</B> boolean => Can index values be non-unique.
* false when TYPE is tableIndexStatistic
* <LI><B>INDEX_QUALIFIER</B> String => index catalog (may be <code>null</code>);
* <code>null</code> when TYPE is tableIndexStatistic
* <LI><B>INDEX_NAME</B> String => index name; <code>null</code> when TYPE is
* tableIndexStatistic
* <LI><B>TYPE</B> short => index type:
* <UL>
* <LI> tableIndexStatistic - this identifies table statistics that are
* returned in conjuction with a table's index descriptions
* <LI> tableIndexClustered - this is a clustered index
* <LI> tableIndexHashed - this is a hashed index
* <LI> tableIndexOther - this is some other style of index
* </UL>
* <LI><B>ORDINAL_POSITION</B> short => column sequence number
* within index; zero when TYPE is tableIndexStatistic
* <LI><B>COLUMN_NAME</B> String => column name; <code>null</code> when TYPE is
* tableIndexStatistic
* <LI><B>ASC_OR_DESC</B> String => column sort sequence, "A" => ascending,
* "D" => descending, may be <code>null</code> if sort sequence is not supported;
* <code>null</code> when TYPE is tableIndexStatistic
* <LI><B>CARDINALITY</B> int => When TYPE is tableIndexStatistic, then
* this is the number of rows in the table; otherwise, it is the
* number of unique values in the index.
* <LI><B>PAGES</B> int => When TYPE is tableIndexStatisic then
* this is the number of pages used for the table, otherwise it
* is the number of pages used for the current index.
* <LI><B>FILTER_CONDITION</B> String => Filter condition, if any.
* (may be <code>null</code>)
* </OL>
*
* @param catalog a catalog name; must match the catalog name as it
* is stored in this database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schema a schema name; must match the schema name
* as it is stored in this database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param table a table name; must match the table name as it is stored
* in this database
* @param unique when true, return only indices for unique values;
* when false, return indices regardless of whether unique or not
* @param approximate when true, result is allowed to reflect approximate
* or out of data values; when false, results are requested to be
* accurate
* @return <code>ResultSet</code> - each row is an index column description
* @exception SQLException if a database access error occurs
*/
ResultSet getIndexInfo(String catalog, String schema, String table,
boolean unique, boolean approximate)
throws SQLException;
/** {@collect.stats}
* Indicates that this column contains table statistics that
* are returned in conjunction with a table's index descriptions.
* <P>
* A possible value for column <code>TYPE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getIndexInfo</code>.
*/
short tableIndexStatistic = 0;
/** {@collect.stats}
* Indicates that this table index is a clustered index.
* <P>
* A possible value for column <code>TYPE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getIndexInfo</code>.
*/
short tableIndexClustered = 1;
/** {@collect.stats}
* Indicates that this table index is a hashed index.
* <P>
* A possible value for column <code>TYPE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getIndexInfo</code>.
*/
short tableIndexHashed = 2;
/** {@collect.stats}
* Indicates that this table index is not a clustered
* index, a hashed index, or table statistics;
* it is something other than these.
* <P>
* A possible value for column <code>TYPE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getIndexInfo</code>.
*/
short tableIndexOther = 3;
//--------------------------JDBC 2.0-----------------------------
/** {@collect.stats}
* Retrieves whether this database supports the given result set type.
*
* @param type defined in <code>java.sql.ResultSet</code>
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @see Connection
* @since 1.2
*/
boolean supportsResultSetType(int type) throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports the given concurrency type
* in combination with the given result set type.
*
* @param type defined in <code>java.sql.ResultSet</code>
* @param concurrency type defined in <code>java.sql.ResultSet</code>
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @see Connection
* @since 1.2
*/
boolean supportsResultSetConcurrency(int type, int concurrency)
throws SQLException;
/** {@collect.stats}
*
* Retrieves whether for the given type of <code>ResultSet</code> object,
* the result set's own updates are visible.
*
* @param type the <code>ResultSet</code> type; one of
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @return <code>true</code> if updates are visible for the given result set type;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.2
*/
boolean ownUpdatesAreVisible(int type) throws SQLException;
/** {@collect.stats}
* Retrieves whether a result set's own deletes are visible.
*
* @param type the <code>ResultSet</code> type; one of
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @return <code>true</code> if deletes are visible for the given result set type;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.2
*/
boolean ownDeletesAreVisible(int type) throws SQLException;
/** {@collect.stats}
* Retrieves whether a result set's own inserts are visible.
*
* @param type the <code>ResultSet</code> type; one of
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @return <code>true</code> if inserts are visible for the given result set type;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.2
*/
boolean ownInsertsAreVisible(int type) throws SQLException;
/** {@collect.stats}
* Retrieves whether updates made by others are visible.
*
* @param type the <code>ResultSet</code> type; one of
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @return <code>true</code> if updates made by others
* are visible for the given result set type;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.2
*/
boolean othersUpdatesAreVisible(int type) throws SQLException;
/** {@collect.stats}
* Retrieves whether deletes made by others are visible.
*
* @param type the <code>ResultSet</code> type; one of
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @return <code>true</code> if deletes made by others
* are visible for the given result set type;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.2
*/
boolean othersDeletesAreVisible(int type) throws SQLException;
/** {@collect.stats}
* Retrieves whether inserts made by others are visible.
*
* @param type the <code>ResultSet</code> type; one of
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @return <code>true</code> if inserts made by others
* are visible for the given result set type;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.2
*/
boolean othersInsertsAreVisible(int type) throws SQLException;
/** {@collect.stats}
* Retrieves whether or not a visible row update can be detected by
* calling the method <code>ResultSet.rowUpdated</code>.
*
* @param type the <code>ResultSet</code> type; one of
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @return <code>true</code> if changes are detected by the result set type;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.2
*/
boolean updatesAreDetected(int type) throws SQLException;
/** {@collect.stats}
* Retrieves whether or not a visible row delete can be detected by
* calling the method <code>ResultSet.rowDeleted</code>. If the method
* <code>deletesAreDetected</code> returns <code>false</code>, it means that
* deleted rows are removed from the result set.
*
* @param type the <code>ResultSet</code> type; one of
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @return <code>true</code> if deletes are detected by the given result set type;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.2
*/
boolean deletesAreDetected(int type) throws SQLException;
/** {@collect.stats}
* Retrieves whether or not a visible row insert can be detected
* by calling the method <code>ResultSet.rowInserted</code>.
*
* @param type the <code>ResultSet</code> type; one of
* <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @return <code>true</code> if changes are detected by the specified result
* set type; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.2
*/
boolean insertsAreDetected(int type) throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports batch updates.
*
* @return <code>true</code> if this database supports batch upcates;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.2
*/
boolean supportsBatchUpdates() throws SQLException;
/** {@collect.stats}
* Retrieves a description of the user-defined types (UDTs) defined
* in a particular schema. Schema-specific UDTs may have type
* <code>JAVA_OBJECT</code>, <code>STRUCT</code>,
* or <code>DISTINCT</code>.
*
* <P>Only types matching the catalog, schema, type name and type
* criteria are returned. They are ordered by <code>DATA_TYPE</code>,
* <code>TYPE_CAT</code>, <code>TYPE_SCHEM</code> and
* <code>TYPE_NAME</code>. The type name parameter may be a fully-qualified
* name. In this case, the catalog and schemaPattern parameters are
* ignored.
*
* <P>Each type description has the following columns:
* <OL>
* <LI><B>TYPE_CAT</B> String => the type's catalog (may be <code>null</code>)
* <LI><B>TYPE_SCHEM</B> String => type's schema (may be <code>null</code>)
* <LI><B>TYPE_NAME</B> String => type name
* <LI><B>CLASS_NAME</B> String => Java class name
* <LI><B>DATA_TYPE</B> int => type value defined in java.sql.Types.
* One of JAVA_OBJECT, STRUCT, or DISTINCT
* <LI><B>REMARKS</B> String => explanatory comment on the type
* <LI><B>BASE_TYPE</B> short => type code of the source type of a
* DISTINCT type or the type that implements the user-generated
* reference type of the SELF_REFERENCING_COLUMN of a structured
* type as defined in java.sql.Types (<code>null</code> if DATA_TYPE is not
* DISTINCT or not STRUCT with REFERENCE_GENERATION = USER_DEFINED)
* </OL>
*
* <P><B>Note:</B> If the driver does not support UDTs, an empty
* result set is returned.
*
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schemaPattern a schema pattern name; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param typeNamePattern a type name pattern; must match the type name
* as it is stored in the database; may be a fully qualified name
* @param types a list of user-defined types (JAVA_OBJECT,
* STRUCT, or DISTINCT) to include; <code>null</code> returns all types
* @return <code>ResultSet</code> object in which each row describes a UDT
* @exception SQLException if a database access error occurs
* @see #getSearchStringEscape
* @since 1.2
*/
ResultSet getUDTs(String catalog, String schemaPattern,
String typeNamePattern, int[] types)
throws SQLException;
/** {@collect.stats}
* Retrieves the connection that produced this metadata object.
* <P>
* @return the connection that produced this metadata object
* @exception SQLException if a database access error occurs
* @since 1.2
*/
Connection getConnection() throws SQLException;
// ------------------- JDBC 3.0 -------------------------
/** {@collect.stats}
* Retrieves whether this database supports savepoints.
*
* @return <code>true</code> if savepoints are supported;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.4
*/
boolean supportsSavepoints() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports named parameters to callable
* statements.
*
* @return <code>true</code> if named parameters are supported;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.4
*/
boolean supportsNamedParameters() throws SQLException;
/** {@collect.stats}
* Retrieves whether it is possible to have multiple <code>ResultSet</code> objects
* returned from a <code>CallableStatement</code> object
* simultaneously.
*
* @return <code>true</code> if a <code>CallableStatement</code> object
* can return multiple <code>ResultSet</code> objects
* simultaneously; <code>false</code> otherwise
* @exception SQLException if a datanase access error occurs
* @since 1.4
*/
boolean supportsMultipleOpenResults() throws SQLException;
/** {@collect.stats}
* Retrieves whether auto-generated keys can be retrieved after
* a statement has been executed
*
* @return <code>true</code> if auto-generated keys can be retrieved
* after a statement has executed; <code>false</code> otherwise
*<p>If <code>true</code> is returned, the JDBC driver must support the
* returning of auto-generated keys for at least SQL INSERT statements
*<p>
* @exception SQLException if a database access error occurs
* @since 1.4
*/
boolean supportsGetGeneratedKeys() throws SQLException;
/** {@collect.stats}
* Retrieves a description of the user-defined type (UDT) hierarchies defined in a
* particular schema in this database. Only the immediate super type/
* sub type relationship is modeled.
* <P>
* Only supertype information for UDTs matching the catalog,
* schema, and type name is returned. The type name parameter
* may be a fully-qualified name. When the UDT name supplied is a
* fully-qualified name, the catalog and schemaPattern parameters are
* ignored.
* <P>
* If a UDT does not have a direct super type, it is not listed here.
* A row of the <code>ResultSet</code> object returned by this method
* describes the designated UDT and a direct supertype. A row has the following
* columns:
* <OL>
* <LI><B>TYPE_CAT</B> String => the UDT's catalog (may be <code>null</code>)
* <LI><B>TYPE_SCHEM</B> String => UDT's schema (may be <code>null</code>)
* <LI><B>TYPE_NAME</B> String => type name of the UDT
* <LI><B>SUPERTYPE_CAT</B> String => the direct super type's catalog
* (may be <code>null</code>)
* <LI><B>SUPERTYPE_SCHEM</B> String => the direct super type's schema
* (may be <code>null</code>)
* <LI><B>SUPERTYPE_NAME</B> String => the direct super type's name
* </OL>
*
* <P><B>Note:</B> If the driver does not support type hierarchies, an
* empty result set is returned.
*
* @param catalog a catalog name; "" retrieves those without a catalog;
* <code>null</code> means drop catalog name from the selection criteria
* @param schemaPattern a schema name pattern; "" retrieves those
* without a schema
* @param typeNamePattern a UDT name pattern; may be a fully-qualified
* name
* @return a <code>ResultSet</code> object in which a row gives information
* about the designated UDT
* @throws SQLException if a database access error occurs
* @see #getSearchStringEscape
* @since 1.4
*/
ResultSet getSuperTypes(String catalog, String schemaPattern,
String typeNamePattern) throws SQLException;
/** {@collect.stats}
* Retrieves a description of the table hierarchies defined in a particular
* schema in this database.
*
* <P>Only supertable information for tables matching the catalog, schema
* and table name are returned. The table name parameter may be a fully-
* qualified name, in which case, the catalog and schemaPattern parameters
* are ignored. If a table does not have a super table, it is not listed here.
* Supertables have to be defined in the same catalog and schema as the
* sub tables. Therefore, the type description does not need to include
* this information for the supertable.
*
* <P>Each type description has the following columns:
* <OL>
* <LI><B>TABLE_CAT</B> String => the type's catalog (may be <code>null</code>)
* <LI><B>TABLE_SCHEM</B> String => type's schema (may be <code>null</code>)
* <LI><B>TABLE_NAME</B> String => type name
* <LI><B>SUPERTABLE_NAME</B> String => the direct super type's name
* </OL>
*
* <P><B>Note:</B> If the driver does not support type hierarchies, an
* empty result set is returned.
*
* @param catalog a catalog name; "" retrieves those without a catalog;
* <code>null</code> means drop catalog name from the selection criteria
* @param schemaPattern a schema name pattern; "" retrieves those
* without a schema
* @param tableNamePattern a table name pattern; may be a fully-qualified
* name
* @return a <code>ResultSet</code> object in which each row is a type description
* @throws SQLException if a database access error occurs
* @see #getSearchStringEscape
* @since 1.4
*/
ResultSet getSuperTables(String catalog, String schemaPattern,
String tableNamePattern) throws SQLException;
/** {@collect.stats}
* Indicates that <code>NULL</code> values might not be allowed.
* <P>
* A possible value for the column
* <code>NULLABLE</code> in the <code>ResultSet</code> object
* returned by the method <code>getAttributes</code>.
*/
short attributeNoNulls = 0;
/** {@collect.stats}
* Indicates that <code>NULL</code> values are definitely allowed.
* <P>
* A possible value for the column <code>NULLABLE</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getAttributes</code>.
*/
short attributeNullable = 1;
/** {@collect.stats}
* Indicates that whether <code>NULL</code> values are allowed is not
* known.
* <P>
* A possible value for the column <code>NULLABLE</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getAttributes</code>.
*/
short attributeNullableUnknown = 2;
/** {@collect.stats}
* Retrieves a description of the given attribute of the given type
* for a user-defined type (UDT) that is available in the given schema
* and catalog.
* <P>
* Descriptions are returned only for attributes of UDTs matching the
* catalog, schema, type, and attribute name criteria. They are ordered by
* <code>TYPE_CAT</code>, <code>TYPE_SCHEM</code>,
* <code>TYPE_NAME</code> and <code>ORDINAL_POSITION</code>. This description
* does not contain inherited attributes.
* <P>
* The <code>ResultSet</code> object that is returned has the following
* columns:
* <OL>
* <LI><B>TYPE_CAT</B> String => type catalog (may be <code>null</code>)
* <LI><B>TYPE_SCHEM</B> String => type schema (may be <code>null</code>)
* <LI><B>TYPE_NAME</B> String => type name
* <LI><B>ATTR_NAME</B> String => attribute name
* <LI><B>DATA_TYPE</B> int => attribute type SQL type from java.sql.Types
* <LI><B>ATTR_TYPE_NAME</B> String => Data source dependent type name.
* For a UDT, the type name is fully qualified. For a REF, the type name is
* fully qualified and represents the target type of the reference type.
* <LI><B>ATTR_SIZE</B> int => column size. For char or date
* types this is the maximum number of characters; for numeric or
* decimal types this is precision.
* <LI><B>DECIMAL_DIGITS</B> int => the number of fractional digits. Null is returned for data types where
* DECIMAL_DIGITS is not applicable.
* <LI><B>NUM_PREC_RADIX</B> int => Radix (typically either 10 or 2)
* <LI><B>NULLABLE</B> int => whether NULL is allowed
* <UL>
* <LI> attributeNoNulls - might not allow NULL values
* <LI> attributeNullable - definitely allows NULL values
* <LI> attributeNullableUnknown - nullability unknown
* </UL>
* <LI><B>REMARKS</B> String => comment describing column (may be <code>null</code>)
* <LI><B>ATTR_DEF</B> String => default value (may be <code>null</code>)
* <LI><B>SQL_DATA_TYPE</B> int => unused
* <LI><B>SQL_DATETIME_SUB</B> int => unused
* <LI><B>CHAR_OCTET_LENGTH</B> int => for char types the
* maximum number of bytes in the column
* <LI><B>ORDINAL_POSITION</B> int => index of the attribute in the UDT
* (starting at 1)
* <LI><B>IS_NULLABLE</B> String => ISO rules are used to determine
* the nullability for a attribute.
* <UL>
* <LI> YES --- if the attribute can include NULLs
* <LI> NO --- if the attribute cannot include NULLs
* <LI> empty string --- if the nullability for the
* attribute is unknown
* </UL>
* <LI><B>SCOPE_CATALOG</B> String => catalog of table that is the
* scope of a reference attribute (<code>null</code> if DATA_TYPE isn't REF)
* <LI><B>SCOPE_SCHEMA</B> String => schema of table that is the
* scope of a reference attribute (<code>null</code> if DATA_TYPE isn't REF)
* <LI><B>SCOPE_TABLE</B> String => table name that is the scope of a
* reference attribute (<code>null</code> if the DATA_TYPE isn't REF)
* <LI><B>SOURCE_DATA_TYPE</B> short => source type of a distinct type or user-generated
* Ref type,SQL type from java.sql.Types (<code>null</code> if DATA_TYPE
* isn't DISTINCT or user-generated REF)
* </OL>
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schemaPattern a schema name pattern; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param typeNamePattern a type name pattern; must match the
* type name as it is stored in the database
* @param attributeNamePattern an attribute name pattern; must match the attribute
* name as it is declared in the database
* @return a <code>ResultSet</code> object in which each row is an
* attribute description
* @exception SQLException if a database access error occurs
* @see #getSearchStringEscape
* @since 1.4
*/
ResultSet getAttributes(String catalog, String schemaPattern,
String typeNamePattern, String attributeNamePattern)
throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports the given result set holdability.
*
* @param holdability one of the following constants:
* <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
* <code>ResultSet.CLOSE_CURSORS_AT_COMMIT<code>
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @see Connection
* @since 1.4
*/
boolean supportsResultSetHoldability(int holdability) throws SQLException;
/** {@collect.stats}
* Retrieves this database's default holdability for <code>ResultSet</code>
* objects.
*
* @return the default holdability; either
* <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
* <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
* @exception SQLException if a database access error occurs
* @since 1.4
*/
int getResultSetHoldability() throws SQLException;
/** {@collect.stats}
* Retrieves the major version number of the underlying database.
*
* @return the underlying database's major version
* @exception SQLException if a database access error occurs
* @since 1.4
*/
int getDatabaseMajorVersion() throws SQLException;
/** {@collect.stats}
* Retrieves the minor version number of the underlying database.
*
* @return underlying database's minor version
* @exception SQLException if a database access error occurs
* @since 1.4
*/
int getDatabaseMinorVersion() throws SQLException;
/** {@collect.stats}
* Retrieves the major JDBC version number for this
* driver.
*
* @return JDBC version major number
* @exception SQLException if a database access error occurs
* @since 1.4
*/
int getJDBCMajorVersion() throws SQLException;
/** {@collect.stats}
* Retrieves the minor JDBC version number for this
* driver.
*
* @return JDBC version minor number
* @exception SQLException if a database access error occurs
* @since 1.4
*/
int getJDBCMinorVersion() throws SQLException;
/** {@collect.stats}
* A possible return value for the method
* <code>DatabaseMetaData.getSQLStateType</code> which is used to indicate
* whether the value returned by the method
* <code>SQLException.getSQLState</code> is an
* X/Open (now know as Open Group) SQL CLI SQLSTATE value.
* <P>
* @since 1.4
*/
int sqlStateXOpen = 1;
/** {@collect.stats}
* A possible return value for the method
* <code>DatabaseMetaData.getSQLStateType</code> which is used to indicate
* whether the value returned by the method
* <code>SQLException.getSQLState</code> is an SQLSTATE value.
* <P>
* @since 1.6
*/
int sqlStateSQL = 2;
/** {@collect.stats}
* A possible return value for the method
* <code>DatabaseMetaData.getSQLStateType</code> which is used to indicate
* whether the value returned by the method
* <code>SQLException.getSQLState</code> is an SQL99 SQLSTATE value.
* <P>
* <b>Note:</b>This constant remains only for compatibility reasons. Developers
* should use the constant <code>sqlStateSQL</code> instead.
*
* @since 1.4
*/
int sqlStateSQL99 = sqlStateSQL;
/** {@collect.stats}
* Indicates whether the SQLSTATE returned by <code>SQLException.getSQLState</code>
* is X/Open (now known as Open Group) SQL CLI or SQL:2003.
* @return the type of SQLSTATE; one of:
* sqlStateXOpen or
* sqlStateSQL
* @throws SQLException if a database access error occurs
* @since 1.4
*/
int getSQLStateType() throws SQLException;
/** {@collect.stats}
* Indicates whether updates made to a LOB are made on a copy or directly
* to the LOB.
* @return <code>true</code> if updates are made to a copy of the LOB;
* <code>false</code> if updates are made directly to the LOB
* @throws SQLException if a database access error occurs
* @since 1.4
*/
boolean locatorsUpdateCopy() throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports statement pooling.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @throws SQLExcpetion if a database access error occurs
* @since 1.4
*/
boolean supportsStatementPooling() throws SQLException;
//------------------------- JDBC 4.0 -----------------------------------
/** {@collect.stats}
* Indicates whether or not this data source supports the SQL <code>ROWID</code> type,
* and if so the lifetime for which a <code>RowId</code> object remains valid.
* <p>
* The returned int values have the following relationship:
* <pre>
* ROWID_UNSUPPORTED < ROWID_VALID_OTHER < ROWID_VALID_TRANSACTION
* < ROWID_VALID_SESSION < ROWID_VALID_FOREVER
* </pre>
* so conditional logic such as
* <pre>
* if (metadata.getRowIdLifetime() > DatabaseMetaData.ROWID_VALID_TRANSACTION)
* </pre>
* can be used. Valid Forever means valid across all Sessions, and valid for
* a Session means valid across all its contained Transactions.
*
* @return the status indicating the lifetime of a <code>RowId</code>
* @throws SQLException if a database access error occurs
* @since 1.6
*/
RowIdLifetime getRowIdLifetime() throws SQLException;
/** {@collect.stats}
* Retrieves the schema names available in this database. The results
* are ordered by <code>TABLE_CATALOG</code> and
* <code>TABLE_SCHEM</code>.
*
* <P>The schema columns are:
* <OL>
* <LI><B>TABLE_SCHEM</B> String => schema name
* <LI><B>TABLE_CATALOG</B> String => catalog name (may be <code>null</code>)
* </OL>
*
*
* @param catalog a catalog name; must match the catalog name as it is stored
* in the database;"" retrieves those without a catalog; null means catalog
* name should not be used to narrow down the search.
* @param schemaPattern a schema name; must match the schema name as it is
* stored in the database; null means
* schema name should not be used to narrow down the search.
* @return a <code>ResultSet</code> object in which each row is a
* schema description
* @exception SQLException if a database access error occurs
* @see #getSearchStringEscape
* @since 1.6
*/
ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException;
/** {@collect.stats}
* Retrieves whether this database supports invoking user-defined or vendor functions
* using the stored procedure escape syntax.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.6
*/
boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException;
/** {@collect.stats}
* Retrieves whether a <code>SQLException</code> while autoCommit is <code>true</code> inidcates
* that all open ResultSets are closed, even ones that are holdable. When a <code>SQLException</code> occurs while
* autocommit is <code>true</code>, it is vendor specific whether the JDBC driver responds with a commit operation, a
* rollback operation, or by doing neither a commit nor a rollback. A potential result of this difference
* is in whether or not holdable ResultSets are closed.
*
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.6
*/
boolean autoCommitFailureClosesAllResultSets() throws SQLException;
/** {@collect.stats}
* Retrieves a list of the client info properties
* that the driver supports. The result set contains the following columns
* <p>
* <ol>
* <li><b>NAME</b> String=> The name of the client info property<br>
* <li><b>MAX_LEN</b> int=> The maximum length of the value for the property<br>
* <li><b>DEFAULT_VALUE</b> String=> The default value of the property<br>
* <li><b>DESCRIPTION</b> String=> A description of the property. This will typically
* contain information as to where this property is
* stored in the database.
* </ol>
* <p>
* The <code>ResultSet</code> is sorted by the NAME column
* <p>
* @return A <code>ResultSet</code> object; each row is a supported client info
* property
* <p>
* @exception SQLException if a database access error occurs
* <p>
* @since 1.6
*/
ResultSet getClientInfoProperties()
throws SQLException;
/** {@collect.stats}
* Retrieves a description of the system and user functions available
* in the given catalog.
* <P>
* Only system and user function descriptions matching the schema and
* function name criteria are returned. They are ordered by
* <code>FUNCTION_CAT</code>, <code>FUNCTION_SCHEM</code>,
* <code>FUNCTION_NAME</code> and
* <code>SPECIFIC_ NAME</code>.
*
* <P>Each function description has the the following columns:
* <OL>
* <LI><B>FUNCTION_CAT</B> String => function catalog (may be <code>null</code>)
* <LI><B>FUNCTION_SCHEM</B> String => function schema (may be <code>null</code>)
* <LI><B>FUNCTION_NAME</B> String => function name. This is the name
* used to invoke the function
* <LI><B>REMARKS</B> String => explanatory comment on the function
* <LI><B>FUNCTION_TYPE</B> short => kind of function:
* <UL>
* <LI>functionResultUnknown - Cannot determine if a return value
* or table will be returned
* <LI> functionNoTable- Does not return a table
* <LI> functionReturnsTable - Returns a table
* </UL>
* <LI><B>SPECIFIC_NAME</B> String => the name which uniquely identifies
* this function within its schema. This is a user specified, or DBMS
* generated, name that may be different then the <code>FUNCTION_NAME</code>
* for example with overload functions
* </OL>
* <p>
* A user may not have permission to execute any of the functions that are
* returned by <code>getFunctions</code>
*
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schemaPattern a schema name pattern; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param functionNamePattern a function name pattern; must match the
* function name as it is stored in the database
* @return <code>ResultSet</code> - each row is a function description
* @exception SQLException if a database access error occurs
* @see #getSearchStringEscape
* @since 1.6
*/
ResultSet getFunctions(String catalog, String schemaPattern,
String functionNamePattern) throws SQLException;
/** {@collect.stats}
* Retrieves a description of the given catalog's system or user
* function parameters and return type.
*
* <P>Only descriptions matching the schema, function and
* parameter name criteria are returned. They are ordered by
* <code>FUNCTION_CAT</code>, <code>FUNCTION_SCHEM</code>,
* <code>FUNCTION_NAME</code> and
* <code>SPECIFIC_ NAME</code>. Within this, the return value,
* if any, is first. Next are the parameter descriptions in call
* order. The column descriptions follow in column number order.
*
* <P>Each row in the <code>ResultSet</code>
* is a parameter description, column description or
* return type description with the following fields:
* <OL>
* <LI><B>FUNCTION_CAT</B> String => function catalog (may be <code>null</code>)
* <LI><B>FUNCTION_SCHEM</B> String => function schema (may be <code>null</code>)
* <LI><B>FUNCTION_NAME</B> String => function name. This is the name
* used to invoke the function
* <LI><B>COLUMN_NAME</B> String => column/parameter name
* <LI><B>COLUMN_TYPE</B> Short => kind of column/parameter:
* <UL>
* <LI> functionColumnUnknown - nobody knows
* <LI> functionColumnIn - IN parameter
* <LI> functionColumnInOut - INOUT parameter
* <LI> functionColumnOut - OUT parameter
* <LI> functionColumnReturn - function return value
* <LI> functionColumnResult - Indicates that the parameter or column
* is a column in the <code>ResultSet</code>
* </UL>
* <LI><B>DATA_TYPE</B> int => SQL type from java.sql.Types
* <LI><B>TYPE_NAME</B> String => SQL type name, for a UDT type the
* type name is fully qualified
* <LI><B>PRECISION</B> int => precision
* <LI><B>LENGTH</B> int => length in bytes of data
* <LI><B>SCALE</B> short => scale - null is returned for data types where
* SCALE is not applicable.
* <LI><B>RADIX</B> short => radix
* <LI><B>NULLABLE</B> short => can it contain NULL.
* <UL>
* <LI> functionNoNulls - does not allow NULL values
* <LI> functionNullable - allows NULL values
* <LI> functionNullableUnknown - nullability unknown
* </UL>
* <LI><B>REMARKS</B> String => comment describing column/parameter
* <LI><B>CHAR_OCTET_LENGTH</B> int => the maximum length of binary
* and character based parameters or columns. For any other datatype the returned value
* is a NULL
* <LI><B>ORDINAL_POSITION</B> int => the ordinal position, starting
* from 1, for the input and output parameters. A value of 0
* is returned if this row describes the function's return value.
* For result set columns, it is the
* ordinal position of the column in the result set starting from 1.
* <LI><B>IS_NULLABLE</B> String => ISO rules are used to determine
* the nullability for a parameter or column.
* <UL>
* <LI> YES --- if the parameter or column can include NULLs
* <LI> NO --- if the parameter or column cannot include NULLs
* <LI> empty string --- if the nullability for the
* parameter or column is unknown
* </UL>
* <LI><B>SPECIFIC_NAME</B> String => the name which uniquely identifies
* this function within its schema. This is a user specified, or DBMS
* generated, name that may be different then the <code>FUNCTION_NAME</code>
* for example with overload functions
* </OL>
*
* <p>The PRECISION column represents the specified column size for the given
* parameter or column.
* For numeric data, this is the maximum precision. For character data, this is the length in characters.
* For datetime datatypes, this is the length in characters of the String representation (assuming the
* maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes. For the ROWID datatype,
* this is the length in bytes. Null is returned for data types where the
* column size is not applicable.
* @param catalog a catalog name; must match the catalog name as it
* is stored in the database; "" retrieves those without a catalog;
* <code>null</code> means that the catalog name should not be used to narrow
* the search
* @param schemaPattern a schema name pattern; must match the schema name
* as it is stored in the database; "" retrieves those without a schema;
* <code>null</code> means that the schema name should not be used to narrow
* the search
* @param functionNamePattern a procedure name pattern; must match the
* function name as it is stored in the database
* @param columnNamePattern a parameter name pattern; must match the
* parameter or column name as it is stored in the database
* @return <code>ResultSet</code> - each row describes a
* user function parameter, column or return type
*
* @exception SQLException if a database access error occurs
* @see #getSearchStringEscape
* @since 1.6
*/
ResultSet getFunctionColumns(String catalog,
String schemaPattern,
String functionNamePattern,
String columnNamePattern) throws SQLException;
/** {@collect.stats}
* Indicates that type of the parameter or column is unknown.
* <P>
* A possible value for the column
* <code>COLUMN_TYPE</code>
* in the <code>ResultSet</code>
* returned by the method <code>getFunctionColumns</code>.
*/
int functionColumnUnknown = 0;
/** {@collect.stats}
* Indicates that the parameter or column is an IN parameter.
* <P>
* A possible value for the column
* <code>COLUMN_TYPE</code>
* in the <code>ResultSet</code>
* returned by the method <code>getFunctionColumns</code>.
* @since 1.6
*/
int functionColumnIn = 1;
/** {@collect.stats}
* Indicates that the parameter or column is an INOUT parameter.
* <P>
* A possible value for the column
* <code>COLUMN_TYPE</code>
* in the <code>ResultSet</code>
* returned by the method <code>getFunctionColumns</code>.
* @since 1.6
*/
int functionColumnInOut = 2;
/** {@collect.stats}
* Indicates that the parameter or column is an OUT parameter.
* <P>
* A possible value for the column
* <code>COLUMN_TYPE</code>
* in the <code>ResultSet</code>
* returned by the method <code>getFunctionColumns</code>.
* @since 1.6
*/
int functionColumnOut = 3;
/** {@collect.stats}
* Indicates that the parameter or column is a return value.
* <P>
* A possible value for the column
* <code>COLUMN_TYPE</code>
* in the <code>ResultSet</code>
* returned by the method <code>getFunctionColumns</code>.
* @since 1.6
*/
int functionReturn = 4;
/** {@collect.stats}
* Indicates that the parameter or column is a column in a result set.
* <P>
* A possible value for the column
* <code>COLUMN_TYPE</code>
* in the <code>ResultSet</code>
* returned by the method <code>getFunctionColumns</code>.
* @since 1.6
*/
int functionColumnResult = 5;
/** {@collect.stats}
* Indicates that <code>NULL</code> values are not allowed.
* <P>
* A possible value for the column
* <code>NULLABLE</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getFunctionColumns</code>.
* @since 1.6
*/
int functionNoNulls = 0;
/** {@collect.stats}
* Indicates that <code>NULL</code> values are allowed.
* <P>
* A possible value for the column
* <code>NULLABLE</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getFunctionColumns</code>.
* @since 1.6
*/
int functionNullable = 1;
/** {@collect.stats}
* Indicates that whether <code>NULL</code> values are allowed
* is unknown.
* <P>
* A possible value for the column
* <code>NULLABLE</code>
* in the <code>ResultSet</code> object
* returned by the method <code>getFunctionColumns</code>.
* @since 1.6
*/
int functionNullableUnknown = 2;
/** {@collect.stats}
* Indicates that it is not known whether the function returns
* a result or a table.
* <P>
* A possible value for column <code>FUNCTION_TYPE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getFunctions</code>.
* @since 1.6
*/
int functionResultUnknown = 0;
/** {@collect.stats}
* Indicates that the function does not return a table.
* <P>
* A possible value for column <code>FUNCTION_TYPE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getFunctions</code>.
* @since 1.6
*/
int functionNoTable = 1;
/** {@collect.stats}
* Indicates that the function returns a table.
* <P>
* A possible value for column <code>FUNCTION_TYPE</code> in the
* <code>ResultSet</code> object returned by the method
* <code>getFunctions</code>.
* @since 1.6
*/
int functionReturnsTable = 2;
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
import java.math.BigDecimal;
import java.util.Calendar;
import java.io.Reader;
import java.io.InputStream;
/** {@collect.stats}
* An object that represents a precompiled SQL statement.
* <P>A SQL statement is precompiled and stored in a
* <code>PreparedStatement</code> object. This object can then be used to
* efficiently execute this statement multiple times.
*
* <P><B>Note:</B> The setter methods (<code>setShort</code>, <code>setString</code>,
* and so on) for setting IN parameter values
* must specify types that are compatible with the defined SQL type of
* the input parameter. For instance, if the IN parameter has SQL type
* <code>INTEGER</code>, then the method <code>setInt</code> should be used.
*
* <p>If arbitrary parameter type conversions are required, the method
* <code>setObject</code> should be used with a target SQL type.
* <P>
* In the following example of setting a parameter, <code>con</code> represents
* an active connection:
* <PRE>
* PreparedStatement pstmt = con.prepareStatement("UPDATE EMPLOYEES
* SET SALARY = ? WHERE ID = ?");
* pstmt.setBigDecimal(1, 153833.00)
* pstmt.setInt(2, 110592)
* </PRE>
*
* @see Connection#prepareStatement
* @see ResultSet
*/
public interface PreparedStatement extends Statement {
/** {@collect.stats}
* Executes the SQL query in this <code>PreparedStatement</code> object
* and returns the <code>ResultSet</code> object generated by the query.
*
* @return a <code>ResultSet</code> object that contains the data produced by the
* query; never <code>null</code>
* @exception SQLException if a database access error occurs;
* this method is called on a closed <code>PreparedStatement</code> or the SQL
* statement does not return a <code>ResultSet</code> object
*/
ResultSet executeQuery() throws SQLException;
/** {@collect.stats}
* Executes the SQL statement in this <code>PreparedStatement</code> object,
* which must be an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
* <code>DELETE</code>; or an SQL statement that returns nothing,
* such as a DDL statement.
*
* @return either (1) the row count for SQL Data Manipulation Language (DML) statements
* or (2) 0 for SQL statements that return nothing
* @exception SQLException if a database access error occurs;
* this method is called on a closed <code>PreparedStatement</code>
* or the SQL
* statement returns a <code>ResultSet</code> object
*/
int executeUpdate() throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to SQL <code>NULL</code>.
*
* <P><B>Note:</B> You must specify the parameter's SQL type.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param sqlType the SQL type code defined in <code>java.sql.Types</code>
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @exception SQLFeatureNotSupportedException if <code>sqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type
*/
void setNull(int parameterIndex, int sqlType) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>boolean</code> value.
* The driver converts this
* to an SQL <code>BIT</code> or <code>BOOLEAN</code> value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement;
* if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setBoolean(int parameterIndex, boolean x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>byte</code> value.
* The driver converts this
* to an SQL <code>TINYINT</code> value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setByte(int parameterIndex, byte x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>short</code> value.
* The driver converts this
* to an SQL <code>SMALLINT</code> value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setShort(int parameterIndex, short x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>int</code> value.
* The driver converts this
* to an SQL <code>INTEGER</code> value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setInt(int parameterIndex, int x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>long</code> value.
* The driver converts this
* to an SQL <code>BIGINT</code> value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setLong(int parameterIndex, long x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>float</code> value.
* The driver converts this
* to an SQL <code>REAL</code> value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setFloat(int parameterIndex, float x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>double</code> value.
* The driver converts this
* to an SQL <code>DOUBLE</code> value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setDouble(int parameterIndex, double x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.math.BigDecimal</code> value.
* The driver converts this to an SQL <code>NUMERIC</code> value when
* it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java <code>String</code> value.
* The driver converts this
* to an SQL <code>VARCHAR</code> or <code>LONGVARCHAR</code> value
* (depending on the argument's
* size relative to the driver's limits on <code>VARCHAR</code> values)
* when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setString(int parameterIndex, String x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given Java array of bytes. The driver converts
* this to an SQL <code>VARBINARY</code> or <code>LONGVARBINARY</code>
* (depending on the argument's size relative to the driver's limits on
* <code>VARBINARY</code> values) when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setBytes(int parameterIndex, byte x[]) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Date</code> value
* using the default time zone of the virtual machine that is running
* the application.
* The driver converts this
* to an SQL <code>DATE</code> value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setDate(int parameterIndex, java.sql.Date x)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Time</code> value.
* The driver converts this
* to an SQL <code>TIME</code> value when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setTime(int parameterIndex, java.sql.Time x)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Timestamp</code> value.
* The driver
* converts this to an SQL <code>TIMESTAMP</code> value when it sends it to the
* database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code> */
void setTimestamp(int parameterIndex, java.sql.Timestamp x)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given input stream, which will have
* the specified number of bytes.
* When a very large ASCII value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code>. Data will be read from the stream
* as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from ASCII to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the Java input stream that contains the ASCII parameter value
* @param length the number of bytes in the stream
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setAsciiStream(int parameterIndex, java.io.InputStream x, int length)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given input stream, which
* will have the specified number of bytes.
*
* When a very large Unicode value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code> object. The data will be read from the
* stream as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from Unicode to the database char format.
*
*The byte format of the Unicode stream must be a Java UTF-8, as defined in the
*Java Virtual Machine Specification.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x a <code>java.io.InputStream</code> object that contains the
* Unicode parameter value
* @param length the number of bytes in the stream
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @deprecated
*/
void setUnicodeStream(int parameterIndex, java.io.InputStream x,
int length) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given input stream, which will have
* the specified number of bytes.
* When a very large binary value is input to a <code>LONGVARBINARY</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code> object. The data will be read from the
* stream as needed until end-of-file is reached.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the java input stream which contains the binary parameter value
* @param length the number of bytes in the stream
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void setBinaryStream(int parameterIndex, java.io.InputStream x,
int length) throws SQLException;
/** {@collect.stats}
* Clears the current parameter values immediately.
* <P>In general, parameter values remain in force for repeated use of a
* statement. Setting a parameter value automatically clears its
* previous value. However, in some cases it is useful to immediately
* release the resources used by the current parameter values; this can
* be done by calling the method <code>clearParameters</code>.
*
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
*/
void clearParameters() throws SQLException;
//----------------------------------------------------------------------
// Advanced features:
/** {@collect.stats}
* Sets the value of the designated parameter with the given object.
* This method is like the method <code>setObject</code>
* above, except that it assumes a scale of zero.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the object containing the input parameter value
* @param targetSqlType the SQL type (as defined in java.sql.Types) to be
* sent to the database
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @exception SQLFeatureNotSupportedException if <code>targetSqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type
* @see Types
*/
void setObject(int parameterIndex, Object x, int targetSqlType)
throws SQLException;
/** {@collect.stats}
* <p>Sets the value of the designated parameter using the given object.
* The second parameter must be of type <code>Object</code>; therefore, the
* <code>java.lang</code> equivalent objects should be used for built-in types.
*
* <p>The JDBC specification specifies a standard mapping from
* Java <code>Object</code> types to SQL types. The given argument
* will be converted to the corresponding SQL type before being
* sent to the database.
*
* <p>Note that this method may be used to pass datatabase-
* specific abstract data types, by using a driver-specific Java
* type.
*
* If the object is of a class implementing the interface <code>SQLData</code>,
* the JDBC driver should call the method <code>SQLData.writeSQL</code>
* to write it to the SQL data stream.
* If, on the other hand, the object is of a class implementing
* <code>Ref</code>, <code>Blob</code>, <code>Clob</code>, <code>NClob</code>,
* <code>Struct</code>, <code>java.net.URL</code>, <code>RowId</code>, <code>SQLXML</code>
* or <code>Array</code>, the driver should pass it to the database as a
* value of the corresponding SQL type.
* <P>
*<b>Note:</b> Not all databases allow for a non-typed Null to be sent to
* the backend. For maximum portability, the <code>setNull</code> or the
* <code>setObject(int parameterIndex, Object x, int sqlType)</code>
* method should be used
* instead of <code>setObject(int parameterIndex, Object x)</code>.
*<p>
* <b>Note:</b> This method throws an exception if there is an ambiguity, for example, if the
* object is of a class implementing more than one of the interfaces named above.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the object containing the input parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs;
* this method is called on a closed <code>PreparedStatement</code>
* or the type of the given object is ambiguous
*/
void setObject(int parameterIndex, Object x) throws SQLException;
/** {@collect.stats}
* Executes the SQL statement in this <code>PreparedStatement</code> object,
* which may be any kind of SQL statement.
* Some prepared statements return multiple results; the <code>execute</code>
* method handles these complex statements as well as the simpler
* form of statements handled by the methods <code>executeQuery</code>
* and <code>executeUpdate</code>.
* <P>
* The <code>execute</code> method returns a <code>boolean</code> to
* indicate the form of the first result. You must call either the method
* <code>getResultSet</code> or <code>getUpdateCount</code>
* to retrieve the result; you must call <code>getMoreResults</code> to
* move to any subsequent result(s).
*
* @return <code>true</code> if the first result is a <code>ResultSet</code>
* object; <code>false</code> if the first result is an update
* count or there is no result
* @exception SQLException if a database access error occurs;
* this method is called on a closed <code>PreparedStatement</code>
* or an argument is supplied to this method
* @see Statement#execute
* @see Statement#getResultSet
* @see Statement#getUpdateCount
* @see Statement#getMoreResults
*/
boolean execute() throws SQLException;
//--------------------------JDBC 2.0-----------------------------
/** {@collect.stats}
* Adds a set of parameters to this <code>PreparedStatement</code>
* object's batch of commands.
*
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @see Statement#addBatch
* @since 1.2
*/
void addBatch() throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>Reader</code>
* object, which is the given number of characters long.
* When a very large UNICODE value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.Reader</code> object. The data will be read from the stream
* as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param reader the <code>java.io.Reader</code> object that contains the
* Unicode data
* @param length the number of characters in the stream
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @since 1.2
*/
void setCharacterStream(int parameterIndex,
java.io.Reader reader,
int length) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given
* <code>REF(<structured-type>)</code> value.
* The driver converts this to an SQL <code>REF</code> value when it
* sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x an SQL <code>REF</code> value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.2
*/
void setRef (int parameterIndex, Ref x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Blob</code> object.
* The driver converts this to an SQL <code>BLOB</code> value when it
* sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x a <code>Blob</code> object that maps an SQL <code>BLOB</code> value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.2
*/
void setBlob (int parameterIndex, Blob x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Clob</code> object.
* The driver converts this to an SQL <code>CLOB</code> value when it
* sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x a <code>Clob</code> object that maps an SQL <code>CLOB</code> value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.2
*/
void setClob (int parameterIndex, Clob x) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Array</code> object.
* The driver converts this to an SQL <code>ARRAY</code> value when it
* sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x an <code>Array</code> object that maps an SQL <code>ARRAY</code> value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.2
*/
void setArray (int parameterIndex, Array x) throws SQLException;
/** {@collect.stats}
* Retrieves a <code>ResultSetMetaData</code> object that contains
* information about the columns of the <code>ResultSet</code> object
* that will be returned when this <code>PreparedStatement</code> object
* is executed.
* <P>
* Because a <code>PreparedStatement</code> object is precompiled, it is
* possible to know about the <code>ResultSet</code> object that it will
* return without having to execute it. Consequently, it is possible
* to invoke the method <code>getMetaData</code> on a
* <code>PreparedStatement</code> object rather than waiting to execute
* it and then invoking the <code>ResultSet.getMetaData</code> method
* on the <code>ResultSet</code> object that is returned.
* <P>
* <B>NOTE:</B> Using this method may be expensive for some drivers due
* to the lack of underlying DBMS support.
*
* @return the description of a <code>ResultSet</code> object's columns or
* <code>null</code> if the driver cannot return a
* <code>ResultSetMetaData</code> object
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
ResultSetMetaData getMetaData() throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Date</code> value,
* using the given <code>Calendar</code> object. The driver uses
* the <code>Calendar</code> object to construct an SQL <code>DATE</code> value,
* which the driver then sends to the database. With
* a <code>Calendar</code> object, the driver can calculate the date
* taking into account a custom timezone. If no
* <code>Calendar</code> object is specified, the driver uses the default
* timezone, which is that of the virtual machine running the application.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @param cal the <code>Calendar</code> object the driver will use
* to construct the date
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @since 1.2
*/
void setDate(int parameterIndex, java.sql.Date x, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Time</code> value,
* using the given <code>Calendar</code> object. The driver uses
* the <code>Calendar</code> object to construct an SQL <code>TIME</code> value,
* which the driver then sends to the database. With
* a <code>Calendar</code> object, the driver can calculate the time
* taking into account a custom timezone. If no
* <code>Calendar</code> object is specified, the driver uses the default
* timezone, which is that of the virtual machine running the application.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @param cal the <code>Calendar</code> object the driver will use
* to construct the time
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @since 1.2
*/
void setTime(int parameterIndex, java.sql.Time x, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.Timestamp</code> value,
* using the given <code>Calendar</code> object. The driver uses
* the <code>Calendar</code> object to construct an SQL <code>TIMESTAMP</code> value,
* which the driver then sends to the database. With a
* <code>Calendar</code> object, the driver can calculate the timestamp
* taking into account a custom timezone. If no
* <code>Calendar</code> object is specified, the driver uses the default
* timezone, which is that of the virtual machine running the application.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @param cal the <code>Calendar</code> object the driver will use
* to construct the timestamp
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @since 1.2
*/
void setTimestamp(int parameterIndex, java.sql.Timestamp x, Calendar cal)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to SQL <code>NULL</code>.
* This version of the method <code>setNull</code> should
* be used for user-defined types and REF type parameters. Examples
* of user-defined types include: STRUCT, DISTINCT, JAVA_OBJECT, and
* named array types.
*
* <P><B>Note:</B> To be portable, applications must give the
* SQL type code and the fully-qualified SQL type name when specifying
* a NULL user-defined or REF parameter. In the case of a user-defined type
* the name is the type name of the parameter itself. For a REF
* parameter, the name is the type name of the referenced type. If
* a JDBC driver does not need the type code or type name information,
* it may ignore it.
*
* Although it is intended for user-defined and Ref parameters,
* this method may be used to set a null parameter of any JDBC type.
* If the parameter does not have a user-defined or REF type, the given
* typeName is ignored.
*
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param sqlType a value from <code>java.sql.Types</code>
* @param typeName the fully-qualified name of an SQL user-defined type;
* ignored if the parameter is not a user-defined type or REF
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @exception SQLFeatureNotSupportedException if <code>sqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type or if the JDBC driver does not support this method
* @since 1.2
*/
void setNull (int parameterIndex, int sqlType, String typeName)
throws SQLException;
//------------------------- JDBC 3.0 -----------------------------------
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.net.URL</code> value.
* The driver converts this to an SQL <code>DATALINK</code> value
* when it sends it to the database.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the <code>java.net.URL</code> object to be set
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.4
*/
void setURL(int parameterIndex, java.net.URL x) throws SQLException;
/** {@collect.stats}
* Retrieves the number, types and properties of this
* <code>PreparedStatement</code> object's parameters.
*
* @return a <code>ParameterMetaData</code> object that contains information
* about the number, types and properties for each
* parameter marker of this <code>PreparedStatement</code> object
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @see ParameterMetaData
* @since 1.4
*/
ParameterMetaData getParameterMetaData() throws SQLException;
//------------------------- JDBC 4.0 -----------------------------------
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.RowId</code> object. The
* driver converts this to a SQL <code>ROWID</code> value when it sends it
* to the database
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the parameter value
* @throws SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
*
* @since 1.6
*/
void setRowId(int parameterIndex, RowId x) throws SQLException;
/** {@collect.stats}
* Sets the designated paramter to the given <code>String</code> object.
* The driver converts this to a SQL <code>NCHAR</code> or
* <code>NVARCHAR</code> or <code>LONGNVARCHAR</code> value
* (depending on the argument's
* size relative to the driver's limits on <code>NVARCHAR</code> values)
* when it sends it to the database.
*
* @param parameterIndex of the first parameter is 1, the second is 2, ...
* @param value the parameter value
* @throws SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; if a database access error occurs; or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setNString(int parameterIndex, String value) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>Reader</code> object. The
* <code>Reader</code> reads the data till end-of-file is reached. The
* driver does the necessary conversion from Java character format to
* the national character set in the database.
* @param parameterIndex of the first parameter is 1, the second is 2, ...
* @param value the parameter value
* @param length the number of characters in the parameter data.
* @throws SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; if a database access error occurs; or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>java.sql.NClob</code> object. The driver converts this to a
* SQL <code>NCLOB</code> value when it sends it to the database.
* @param parameterIndex of the first parameter is 1, the second is 2, ...
* @param value the parameter value
* @throws SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; if a database access error occurs; or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setNClob(int parameterIndex, NClob value) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>Reader</code> object. The reader must contain the number
* of characters specified by length otherwise a <code>SQLException</code> will be
* generated when the <code>PreparedStatement</code> is executed.
*This method differs from the <code>setCharacterStream (int, Reader, int)</code> method
* because it informs the driver that the parameter value should be sent to
* the server as a <code>CLOB</code>. When the <code>setCharacterStream</code> method is used, the
* driver may have to do extra work to determine whether the parameter
* data should be sent to the server as a <code>LONGVARCHAR</code> or a <code>CLOB</code>
* @param parameterIndex index of the first parameter is 1, the second is 2, ...
* @param reader An object that contains the data to set the parameter value to.
* @param length the number of characters in the parameter data.
* @throws SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs; this method is called on
* a closed <code>PreparedStatement</code> or if the length specified is less than zero.
*
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setClob(int parameterIndex, Reader reader, long length)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>InputStream</code> object. The inputstream must contain the number
* of characters specified by length otherwise a <code>SQLException</code> will be
* generated when the <code>PreparedStatement</code> is executed.
* This method differs from the <code>setBinaryStream (int, InputStream, int)</code>
* method because it informs the driver that the parameter value should be
* sent to the server as a <code>BLOB</code>. When the <code>setBinaryStream</code> method is used,
* the driver may have to do extra work to determine whether the parameter
* data should be sent to the server as a <code>LONGVARBINARY</code> or a <code>BLOB</code>
* @param parameterIndex index of the first parameter is 1,
* the second is 2, ...
* @param inputStream An object that contains the data to set the parameter
* value to.
* @param length the number of bytes in the parameter data.
* @throws SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs;
* this method is called on a closed <code>PreparedStatement</code>;
* if the length specified
* is less than zero or if the number of bytes in the inputstream does not match
* the specfied length.
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
*
* @since 1.6
*/
void setBlob(int parameterIndex, InputStream inputStream, long length)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>Reader</code> object. The reader must contain the number
* of characters specified by length otherwise a <code>SQLException</code> will be
* generated when the <code>PreparedStatement</code> is executed.
* This method differs from the <code>setCharacterStream (int, Reader, int)</code> method
* because it informs the driver that the parameter value should be sent to
* the server as a <code>NCLOB</code>. When the <code>setCharacterStream</code> method is used, the
* driver may have to do extra work to determine whether the parameter
* data should be sent to the server as a <code>LONGNVARCHAR</code> or a <code>NCLOB</code>
* @param parameterIndex index of the first parameter is 1, the second is 2, ...
* @param reader An object that contains the data to set the parameter value to.
* @param length the number of characters in the parameter data.
* @throws SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if the length specified is less than zero;
* if the driver does not support national character sets;
* if the driver can detect that a data conversion
* error could occur; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
*
* @since 1.6
*/
void setNClob(int parameterIndex, Reader reader, long length)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>java.sql.SQLXML</code> object.
* The driver converts this to an
* SQL <code>XML</code> value when it sends it to the database.
* <p>
*
* @param parameterIndex index of the first parameter is 1, the second is 2, ...
* @param xmlObject a <code>SQLXML</code> object that maps an SQL <code>XML</code> value
* @throws SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs;
* this method is called on a closed <code>PreparedStatement</code>
* or the <code>java.xml.transform.Result</code>,
* <code>Writer</code> or <code>OutputStream</code> has not been closed for
* the <code>SQLXML</code> object
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
*
* @since 1.6
*/
void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException;
/** {@collect.stats}
* <p>Sets the value of the designated parameter with the given object. The second
* argument must be an object type; for integral values, the
* <code>java.lang</code> equivalent objects should be used.
*
* If the second argument is an <code>InputStream</code> then the stream must contain
* the number of bytes specified by scaleOrLength. If the second argument is a
* <code>Reader</code> then the reader must contain the number of characters specified
* by scaleOrLength. If these conditions are not true the driver will generate a
* <code>SQLException</code> when the prepared statement is executed.
*
* <p>The given Java object will be converted to the given targetSqlType
* before being sent to the database.
*
* If the object has a custom mapping (is of a class implementing the
* interface <code>SQLData</code>),
* the JDBC driver should call the method <code>SQLData.writeSQL</code> to
* write it to the SQL data stream.
* If, on the other hand, the object is of a class implementing
* <code>Ref</code>, <code>Blob</code>, <code>Clob</code>, <code>NClob</code>,
* <code>Struct</code>, <code>java.net.URL</code>,
* or <code>Array</code>, the driver should pass it to the database as a
* value of the corresponding SQL type.
*
* <p>Note that this method may be used to pass database-specific
* abstract data types.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the object containing the input parameter value
* @param targetSqlType the SQL type (as defined in java.sql.Types) to be
* sent to the database. The scale argument may further qualify this type.
* @param scaleOrLength for <code>java.sql.Types.DECIMAL</code>
* or <code>java.sql.Types.NUMERIC types</code>,
* this is the number of digits after the decimal point. For
* Java Object types <code>InputStream</code> and <code>Reader</code>,
* this is the length
* of the data in the stream or reader. For all other types,
* this value will be ignored.
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs;
* this method is called on a closed <code>PreparedStatement</code> or
* if the Java Object specified by x is an InputStream
* or Reader object and the value of the scale parameter is less
* than zero
* @exception SQLFeatureNotSupportedException if <code>targetSqlType</code> is
* a <code>ARRAY</code>, <code>BLOB</code>, <code>CLOB</code>,
* <code>DATALINK</code>, <code>JAVA_OBJECT</code>, <code>NCHAR</code>,
* <code>NCLOB</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>,
* <code>REF</code>, <code>ROWID</code>, <code>SQLXML</code>
* or <code>STRUCT</code> data type and the JDBC driver does not support
* this data type
* @see Types
*
* @since 1.6
*/
void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given input stream, which will have
* the specified number of bytes.
* When a very large ASCII value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code>. Data will be read from the stream
* as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from ASCII to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the Java input stream that contains the ASCII parameter value
* @param length the number of bytes in the stream
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @since 1.6
*/
void setAsciiStream(int parameterIndex, java.io.InputStream x, long length)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given input stream, which will have
* the specified number of bytes.
* When a very large binary value is input to a <code>LONGVARBINARY</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code> object. The data will be read from the
* stream as needed until end-of-file is reached.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the java input stream which contains the binary parameter value
* @param length the number of bytes in the stream
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @since 1.6
*/
void setBinaryStream(int parameterIndex, java.io.InputStream x,
long length) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>Reader</code>
* object, which is the given number of characters long.
* When a very large UNICODE value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.Reader</code> object. The data will be read from the stream
* as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param reader the <code>java.io.Reader</code> object that contains the
* Unicode data
* @param length the number of characters in the stream
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @since 1.6
*/
void setCharacterStream(int parameterIndex,
java.io.Reader reader,
long length) throws SQLException;
//-----
/** {@collect.stats}
* Sets the designated parameter to the given input stream.
* When a very large ASCII value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code>. Data will be read from the stream
* as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from ASCII to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setAsciiStream</code> which takes a length parameter.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the Java input stream that contains the ASCII parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setAsciiStream(int parameterIndex, java.io.InputStream x)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given input stream.
* When a very large binary value is input to a <code>LONGVARBINARY</code>
* parameter, it may be more practical to send it via a
* <code>java.io.InputStream</code> object. The data will be read from the
* stream as needed until end-of-file is reached.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setBinaryStream</code> which takes a length parameter.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param x the java input stream which contains the binary parameter value
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setBinaryStream(int parameterIndex, java.io.InputStream x)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to the given <code>Reader</code>
* object.
* When a very large UNICODE value is input to a <code>LONGVARCHAR</code>
* parameter, it may be more practical to send it via a
* <code>java.io.Reader</code> object. The data will be read from the stream
* as needed until end-of-file is reached. The JDBC driver will
* do any necessary conversion from UNICODE to the database char format.
*
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setCharacterStream</code> which takes a length parameter.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param reader the <code>java.io.Reader</code> object that contains the
* Unicode data
* @exception SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setCharacterStream(int parameterIndex,
java.io.Reader reader) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>Reader</code> object. The
* <code>Reader</code> reads the data till end-of-file is reached. The
* driver does the necessary conversion from Java character format to
* the national character set in the database.
* <P><B>Note:</B> This stream object can either be a standard
* Java stream object or your own subclass that implements the
* standard interface.
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setNCharacterStream</code> which takes a length parameter.
*
* @param parameterIndex of the first parameter is 1, the second is 2, ...
* @param value the parameter value
* @throws SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if the driver does not support national
* character sets; if the driver can detect that a data conversion
* error could occur; if a database access error occurs; or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setNCharacterStream(int parameterIndex, Reader value) throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>Reader</code> object.
* This method differs from the <code>setCharacterStream (int, Reader)</code> method
* because it informs the driver that the parameter value should be sent to
* the server as a <code>CLOB</code>. When the <code>setCharacterStream</code> method is used, the
* driver may have to do extra work to determine whether the parameter
* data should be sent to the server as a <code>LONGVARCHAR</code> or a <code>CLOB</code>
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setClob</code> which takes a length parameter.
*
* @param parameterIndex index of the first parameter is 1, the second is 2, ...
* @param reader An object that contains the data to set the parameter value to.
* @throws SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs; this method is called on
* a closed <code>PreparedStatement</code>or if parameterIndex does not correspond to a parameter
* marker in the SQL statement
*
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.6
*/
void setClob(int parameterIndex, Reader reader)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>InputStream</code> object.
* This method differs from the <code>setBinaryStream (int, InputStream)</code>
* method because it informs the driver that the parameter value should be
* sent to the server as a <code>BLOB</code>. When the <code>setBinaryStream</code> method is used,
* the driver may have to do extra work to determine whether the parameter
* data should be sent to the server as a <code>LONGVARBINARY</code> or a <code>BLOB</code>
*
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setBlob</code> which takes a length parameter.
*
* @param parameterIndex index of the first parameter is 1,
* the second is 2, ...
* @param inputStream An object that contains the data to set the parameter
* value to.
* @throws SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement; if a database access error occurs;
* this method is called on a closed <code>PreparedStatement</code> or
* if parameterIndex does not correspond
* to a parameter marker in the SQL statement,
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
*
* @since 1.6
*/
void setBlob(int parameterIndex, InputStream inputStream)
throws SQLException;
/** {@collect.stats}
* Sets the designated parameter to a <code>Reader</code> object.
* This method differs from the <code>setCharacterStream (int, Reader)</code> method
* because it informs the driver that the parameter value should be sent to
* the server as a <code>NCLOB</code>. When the <code>setCharacterStream</code> method is used, the
* driver may have to do extra work to determine whether the parameter
* data should be sent to the server as a <code>LONGNVARCHAR</code> or a <code>NCLOB</code>
* <P><B>Note:</B> Consult your JDBC driver documentation to determine if
* it might be more efficient to use a version of
* <code>setNClob</code> which takes a length parameter.
*
* @param parameterIndex index of the first parameter is 1, the second is 2, ...
* @param reader An object that contains the data to set the parameter value to.
* @throws SQLException if parameterIndex does not correspond to a parameter
* marker in the SQL statement;
* if the driver does not support national character sets;
* if the driver can detect that a data conversion
* error could occur; if a database access error occurs or
* this method is called on a closed <code>PreparedStatement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
*
* @since 1.6
*/
void setNClob(int parameterIndex, Reader reader)
throws SQLException;
}
|
Java
|
/*
* Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* <p>The standard mapping in the Java programming language for an SQL
* structured type. A <code>Struct</code> object contains a
* value for each attribute of the SQL structured type that
* it represents.
* By default, an instance of<code>Struct</code> is valid as long as the
* application has a reference to it.
* <p>
* All methods on the <code>Struct</code> interface must be fully implemented if the
* JDBC driver supports the data type.
* @since 1.2
*/
public interface Struct {
/** {@collect.stats}
* Retrieves the SQL type name of the SQL structured type
* that this <code>Struct</code> object represents.
*
* @return the fully-qualified type name of the SQL structured
* type for which this <code>Struct</code> object
* is the generic representation
* @exception SQLException if a database access error occurs
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
String getSQLTypeName() throws SQLException;
/** {@collect.stats}
* Produces the ordered values of the attributes of the SQL
* structured type that this <code>Struct</code> object represents.
* As individual attributes are processed, this method uses the type map
* associated with the
* connection for customizations of the type mappings.
* If there is no
* entry in the connection's type map that matches the structured
* type that an attribute represents,
* the driver uses the standard mapping.
* <p>
* Conceptually, this method calls the method
* <code>getObject</code> on each attribute
* of the structured type and returns a Java array containing
* the result.
*
* @return an array containing the ordered attribute values
* @exception SQLException if a database access error occurs
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Object[] getAttributes() throws SQLException;
/** {@collect.stats}
* Produces the ordered values of the attributes of the SQL
* structured type that this <code>Struct</code> object represents.
* As individual attrbutes are proccessed, this method uses the given type map
* for customizations of the type mappings.
* If there is no
* entry in the given type map that matches the structured
* type that an attribute represents,
* the driver uses the standard mapping. This method never
* uses the type map associated with the connection.
* <p>
* Conceptually, this method calls the method
* <code>getObject</code> on each attribute
* of the structured type and returns a Java array containing
* the result.
*
* @param map a mapping of SQL type names to Java classes
* @return an array containing the ordered attribute values
* @exception SQLException if a database access error occurs
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Object[] getAttributes(java.util.Map<String,Class<?>> map)
throws SQLException;
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* <P>The object used for executing a static SQL statement
* and returning the results it produces.
* <P>
* By default, only one <code>ResultSet</code> object per <code>Statement</code>
* object can be open at the same time. Therefore, if the reading of one
* <code>ResultSet</code> object is interleaved
* with the reading of another, each must have been generated by
* different <code>Statement</code> objects. All execution methods in the
* <code>Statement</code> interface implicitly close a statment's current
* <code>ResultSet</code> object if an open one exists.
*
* @see Connection#createStatement
* @see ResultSet
*/
public interface Statement extends Wrapper {
/** {@collect.stats}
* Executes the given SQL statement, which returns a single
* <code>ResultSet</code> object.
*
* @param sql an SQL statement to be sent to the database, typically a
* static SQL <code>SELECT</code> statement
* @return a <code>ResultSet</code> object that contains the data produced
* by the given query; never <code>null</code>
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code> or the given
* SQL statement produces anything other than a single
* <code>ResultSet</code> object
*/
ResultSet executeQuery(String sql) throws SQLException;
/** {@collect.stats}
* Executes the given SQL statement, which may be an <code>INSERT</code>,
* <code>UPDATE</code>, or <code>DELETE</code> statement or an
* SQL statement that returns nothing, such as an SQL DDL statement.
*
* @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
* <code>DELETE</code>; or an SQL statement that returns nothing,
* such as a DDL statement.
*
* @return either (1) the row count for SQL Data Manipulation Language (DML) statements
* or (2) 0 for SQL statements that return nothing
*
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code> or the given
* SQL statement produces a <code>ResultSet</code> object
*/
int executeUpdate(String sql) throws SQLException;
/** {@collect.stats}
* Releases this <code>Statement</code> object's database
* and JDBC resources immediately instead of waiting for
* this to happen when it is automatically closed.
* It is generally good practice to release resources as soon as
* you are finished with them to avoid tying up database
* resources.
* <P>
* Calling the method <code>close</code> on a <code>Statement</code>
* object that is already closed has no effect.
* <P>
* <B>Note:</B>When a <code>Statement</code> object is
* closed, its current <code>ResultSet</code> object, if one exists, is
* also closed.
*
* @exception SQLException if a database access error occurs
*/
void close() throws SQLException;
//----------------------------------------------------------------------
/** {@collect.stats}
* Retrieves the maximum number of bytes that can be
* returned for character and binary column values in a <code>ResultSet</code>
* object produced by this <code>Statement</code> object.
* This limit applies only to <code>BINARY</code>, <code>VARBINARY</code>,
* <code>LONGVARBINARY</code>, <code>CHAR</code>, <code>VARCHAR</code>,
* <code>NCHAR</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code>
* and <code>LONGVARCHAR</code> columns. If the limit is exceeded, the
* excess data is silently discarded.
*
* @return the current column size limit for columns storing character and
* binary values; zero means there is no limit
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @see #setMaxFieldSize
*/
int getMaxFieldSize() throws SQLException;
/** {@collect.stats}
* Sets the limit for the maximum number of bytes that can be returned for
* character and binary column values in a <code>ResultSet</code>
* object produced by this <code>Statement</code> object.
*
* This limit applies
* only to <code>BINARY</code>, <code>VARBINARY</code>,
* <code>LONGVARBINARY</code>, <code>CHAR</code>, <code>VARCHAR</code>,
* <code>NCHAR</code>, <code>NVARCHAR</code>, <code>LONGNVARCHAR</code> and
* <code>LONGVARCHAR</code> fields. If the limit is exceeded, the excess data
* is silently discarded. For maximum portability, use values
* greater than 256.
*
* @param max the new column size limit in bytes; zero means there is no limit
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code>
* or the condition max >= 0 is not satisfied
* @see #getMaxFieldSize
*/
void setMaxFieldSize(int max) throws SQLException;
/** {@collect.stats}
* Retrieves the maximum number of rows that a
* <code>ResultSet</code> object produced by this
* <code>Statement</code> object can contain. If this limit is exceeded,
* the excess rows are silently dropped.
*
* @return the current maximum number of rows for a <code>ResultSet</code>
* object produced by this <code>Statement</code> object;
* zero means there is no limit
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @see #setMaxRows
*/
int getMaxRows() throws SQLException;
/** {@collect.stats}
* Sets the limit for the maximum number of rows that any
* <code>ResultSet</code> object generated by this <code>Statement</code>
* object can contain to the given number.
* If the limit is exceeded, the excess
* rows are silently dropped.
*
* @param max the new max rows limit; zero means there is no limit
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code>
* or the condition max >= 0 is not satisfied
* @see #getMaxRows
*/
void setMaxRows(int max) throws SQLException;
/** {@collect.stats}
* Sets escape processing on or off.
* If escape scanning is on (the default), the driver will do
* escape substitution before sending the SQL statement to the database.
*
* Note: Since prepared statements have usually been parsed prior
* to making this call, disabling escape processing for
* <code>PreparedStatements</code> objects will have no effect.
*
* @param enable <code>true</code> to enable escape processing;
* <code>false</code> to disable it
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
*/
void setEscapeProcessing(boolean enable) throws SQLException;
/** {@collect.stats}
* Retrieves the number of seconds the driver will
* wait for a <code>Statement</code> object to execute.
* If the limit is exceeded, a
* <code>SQLException</code> is thrown.
*
* @return the current query timeout limit in seconds; zero means there is
* no limit
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @see #setQueryTimeout
*/
int getQueryTimeout() throws SQLException;
/** {@collect.stats}
* Sets the number of seconds the driver will wait for a
* <code>Statement</code> object to execute to the given number of seconds.
* If the limit is exceeded, an <code>SQLException</code> is thrown. A JDBC
* driver must apply this limit to the <code>execute</code>,
* <code>executeQuery</code> and <code>executeUpdate</code> methods. JDBC driver
* implementations may also apply this limit to <code>ResultSet</code> methods
* (consult your driver vendor documentation for details).
*
* @param seconds the new query timeout limit in seconds; zero means
* there is no limit
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code>
* or the condition seconds >= 0 is not satisfied
* @see #getQueryTimeout
*/
void setQueryTimeout(int seconds) throws SQLException;
/** {@collect.stats}
* Cancels this <code>Statement</code> object if both the DBMS and
* driver support aborting an SQL statement.
* This method can be used by one thread to cancel a statement that
* is being executed by another thread.
*
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
*/
void cancel() throws SQLException;
/** {@collect.stats}
* Retrieves the first warning reported by calls on this <code>Statement</code> object.
* Subsequent <code>Statement</code> object warnings will be chained to this
* <code>SQLWarning</code> object.
*
* <p>The warning chain is automatically cleared each time
* a statement is (re)executed. This method may not be called on a closed
* <code>Statement</code> object; doing so will cause an <code>SQLException</code>
* to be thrown.
*
* <P><B>Note:</B> If you are processing a <code>ResultSet</code> object, any
* warnings associated with reads on that <code>ResultSet</code> object
* will be chained on it rather than on the <code>Statement</code>
* object that produced it.
*
* @return the first <code>SQLWarning</code> object or <code>null</code>
* if there are no warnings
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
*/
SQLWarning getWarnings() throws SQLException;
/** {@collect.stats}
* Clears all the warnings reported on this <code>Statement</code>
* object. After a call to this method,
* the method <code>getWarnings</code> will return
* <code>null</code> until a new warning is reported for this
* <code>Statement</code> object.
*
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
*/
void clearWarnings() throws SQLException;
/** {@collect.stats}
* Sets the SQL cursor name to the given <code>String</code>, which
* will be used by subsequent <code>Statement</code> object
* <code>execute</code> methods. This name can then be
* used in SQL positioned update or delete statements to identify the
* current row in the <code>ResultSet</code> object generated by this
* statement. If the database does not support positioned update/delete,
* this method is a noop. To insure that a cursor has the proper isolation
* level to support updates, the cursor's <code>SELECT</code> statement
* should have the form <code>SELECT FOR UPDATE</code>. If
* <code>FOR UPDATE</code> is not present, positioned updates may fail.
*
* <P><B>Note:</B> By definition, the execution of positioned updates and
* deletes must be done by a different <code>Statement</code> object than
* the one that generated the <code>ResultSet</code> object being used for
* positioning. Also, cursor names must be unique within a connection.
*
* @param name the new cursor name, which must be unique within
* a connection
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
*/
void setCursorName(String name) throws SQLException;
//----------------------- Multiple Results --------------------------
/** {@collect.stats}
* Executes the given SQL statement, which may return multiple results.
* In some (uncommon) situations, a single SQL statement may return
* multiple result sets and/or update counts. Normally you can ignore
* this unless you are (1) executing a stored procedure that you know may
* return multiple results or (2) you are dynamically executing an
* unknown SQL string.
* <P>
* The <code>execute</code> method executes an SQL statement and indicates the
* form of the first result. You must then use the methods
* <code>getResultSet</code> or <code>getUpdateCount</code>
* to retrieve the result, and <code>getMoreResults</code> to
* move to any subsequent result(s).
*
* @param sql any SQL statement
* @return <code>true</code> if the first result is a <code>ResultSet</code>
* object; <code>false</code> if it is an update count or there are
* no results
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @see #getResultSet
* @see #getUpdateCount
* @see #getMoreResults
*/
boolean execute(String sql) throws SQLException;
/** {@collect.stats}
* Retrieves the current result as a <code>ResultSet</code> object.
* This method should be called only once per result.
*
* @return the current result as a <code>ResultSet</code> object or
* <code>null</code> if the result is an update count or there are no more results
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @see #execute
*/
ResultSet getResultSet() throws SQLException;
/** {@collect.stats}
* Retrieves the current result as an update count;
* if the result is a <code>ResultSet</code> object or there are no more results, -1
* is returned. This method should be called only once per result.
*
* @return the current result as an update count; -1 if the current result is a
* <code>ResultSet</code> object or there are no more results
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @see #execute
*/
int getUpdateCount() throws SQLException;
/** {@collect.stats}
* Moves to this <code>Statement</code> object's next result, returns
* <code>true</code> if it is a <code>ResultSet</code> object, and
* implicitly closes any current <code>ResultSet</code>
* object(s) obtained with the method <code>getResultSet</code>.
*
* <P>There are no more results when the following is true:
* <PRE>
* // stmt is a Statement object
* ((stmt.getMoreResults() == false) && (stmt.getUpdateCount() == -1))
* </PRE>
*
* @return <code>true</code> if the next result is a <code>ResultSet</code>
* object; <code>false</code> if it is an update count or there are
* no more results
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @see #execute
*/
boolean getMoreResults() throws SQLException;
//--------------------------JDBC 2.0-----------------------------
/** {@collect.stats}
* Gives the driver a hint as to the direction in which
* rows will be processed in <code>ResultSet</code>
* objects created using this <code>Statement</code> object. The
* default value is <code>ResultSet.FETCH_FORWARD</code>.
* <P>
* Note that this method sets the default fetch direction for
* result sets generated by this <code>Statement</code> object.
* Each result set has its own methods for getting and setting
* its own fetch direction.
*
* @param direction the initial direction for processing rows
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code>
* or the given direction
* is not one of <code>ResultSet.FETCH_FORWARD</code>,
* <code>ResultSet.FETCH_REVERSE</code>, or <code>ResultSet.FETCH_UNKNOWN</code>
* @since 1.2
* @see #getFetchDirection
*/
void setFetchDirection(int direction) throws SQLException;
/** {@collect.stats}
* Retrieves the direction for fetching rows from
* database tables that is the default for result sets
* generated from this <code>Statement</code> object.
* If this <code>Statement</code> object has not set
* a fetch direction by calling the method <code>setFetchDirection</code>,
* the return value is implementation-specific.
*
* @return the default fetch direction for result sets generated
* from this <code>Statement</code> object
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @since 1.2
* @see #setFetchDirection
*/
int getFetchDirection() throws SQLException;
/** {@collect.stats}
* Gives the JDBC driver a hint as to the number of rows that should
* be fetched from the database when more rows are needed for
* <code>ResultSet</code> objects genrated by this <code>Statement</code>.
* If the value specified is zero, then the hint is ignored.
* The default value is zero.
*
* @param rows the number of rows to fetch
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code> or the
* condition <code>rows >= 0</code> is not satisfied.
* @since 1.2
* @see #getFetchSize
*/
void setFetchSize(int rows) throws SQLException;
/** {@collect.stats}
* Retrieves the number of result set rows that is the default
* fetch size for <code>ResultSet</code> objects
* generated from this <code>Statement</code> object.
* If this <code>Statement</code> object has not set
* a fetch size by calling the method <code>setFetchSize</code>,
* the return value is implementation-specific.
*
* @return the default fetch size for result sets generated
* from this <code>Statement</code> object
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @since 1.2
* @see #setFetchSize
*/
int getFetchSize() throws SQLException;
/** {@collect.stats}
* Retrieves the result set concurrency for <code>ResultSet</code> objects
* generated by this <code>Statement</code> object.
*
* @return either <code>ResultSet.CONCUR_READ_ONLY</code> or
* <code>ResultSet.CONCUR_UPDATABLE</code>
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @since 1.2
*/
int getResultSetConcurrency() throws SQLException;
/** {@collect.stats}
* Retrieves the result set type for <code>ResultSet</code> objects
* generated by this <code>Statement</code> object.
*
* @return one of <code>ResultSet.TYPE_FORWARD_ONLY</code>,
* <code>ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @since 1.2
*/
int getResultSetType() throws SQLException;
/** {@collect.stats}
* Adds the given SQL command to the current list of commmands for this
* <code>Statement</code> object. The commands in this list can be
* executed as a batch by calling the method <code>executeBatch</code>.
* <P>
*
* @param sql typically this is a SQL <code>INSERT</code> or
* <code>UPDATE</code> statement
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code> or the
* driver does not support batch updates
* @see #executeBatch
* @see DatabaseMetaData#supportsBatchUpdates
* @since 1.2
*/
void addBatch( String sql ) throws SQLException;
/** {@collect.stats}
* Empties this <code>Statement</code> object's current list of
* SQL commands.
* <P>
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code> or the
* driver does not support batch updates
* @see #addBatch
* @see DatabaseMetaData#supportsBatchUpdates
* @since 1.2
*/
void clearBatch() throws SQLException;
/** {@collect.stats}
* Submits a batch of commands to the database for execution and
* if all commands execute successfully, returns an array of update counts.
* The <code>int</code> elements of the array that is returned are ordered
* to correspond to the commands in the batch, which are ordered
* according to the order in which they were added to the batch.
* The elements in the array returned by the method <code>executeBatch</code>
* may be one of the following:
* <OL>
* <LI>A number greater than or equal to zero -- indicates that the
* command was processed successfully and is an update count giving the
* number of rows in the database that were affected by the command's
* execution
* <LI>A value of <code>SUCCESS_NO_INFO</code> -- indicates that the command was
* processed successfully but that the number of rows affected is
* unknown
* <P>
* If one of the commands in a batch update fails to execute properly,
* this method throws a <code>BatchUpdateException</code>, and a JDBC
* driver may or may not continue to process the remaining commands in
* the batch. However, the driver's behavior must be consistent with a
* particular DBMS, either always continuing to process commands or never
* continuing to process commands. If the driver continues processing
* after a failure, the array returned by the method
* <code>BatchUpdateException.getUpdateCounts</code>
* will contain as many elements as there are commands in the batch, and
* at least one of the elements will be the following:
* <P>
* <LI>A value of <code>EXECUTE_FAILED</code> -- indicates that the command failed
* to execute successfully and occurs only if a driver continues to
* process commands after a command fails
* </OL>
* <P>
* The possible implementations and return values have been modified in
* the Java 2 SDK, Standard Edition, version 1.3 to
* accommodate the option of continuing to proccess commands in a batch
* update after a <code>BatchUpdateException</code> obejct has been thrown.
*
* @return an array of update counts containing one element for each
* command in the batch. The elements of the array are ordered according
* to the order in which commands were added to the batch.
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code> or the
* driver does not support batch statements. Throws {@link BatchUpdateException}
* (a subclass of <code>SQLException</code>) if one of the commands sent to the
* database fails to execute properly or attempts to return a result set.
*
*
* @see #addBatch
* @see DatabaseMetaData#supportsBatchUpdates
* @since 1.3
*/
int[] executeBatch() throws SQLException;
/** {@collect.stats}
* Retrieves the <code>Connection</code> object
* that produced this <code>Statement</code> object.
* @return the connection that produced this statement
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @since 1.2
*/
Connection getConnection() throws SQLException;
//--------------------------JDBC 3.0-----------------------------
/** {@collect.stats}
* The constant indicating that the current <code>ResultSet</code> object
* should be closed when calling <code>getMoreResults</code>.
*
* @since 1.4
*/
int CLOSE_CURRENT_RESULT = 1;
/** {@collect.stats}
* The constant indicating that the current <code>ResultSet</code> object
* should not be closed when calling <code>getMoreResults</code>.
*
* @since 1.4
*/
int KEEP_CURRENT_RESULT = 2;
/** {@collect.stats}
* The constant indicating that all <code>ResultSet</code> objects that
* have previously been kept open should be closed when calling
* <code>getMoreResults</code>.
*
* @since 1.4
*/
int CLOSE_ALL_RESULTS = 3;
/** {@collect.stats}
* The constant indicating that a batch statement executed successfully
* but that no count of the number of rows it affected is available.
*
* @since 1.4
*/
int SUCCESS_NO_INFO = -2;
/** {@collect.stats}
* The constant indicating that an error occured while executing a
* batch statement.
*
* @since 1.4
*/
int EXECUTE_FAILED = -3;
/** {@collect.stats}
* The constant indicating that generated keys should be made
* available for retrieval.
*
* @since 1.4
*/
int RETURN_GENERATED_KEYS = 1;
/** {@collect.stats}
* The constant indicating that generated keys should not be made
* available for retrieval.
*
* @since 1.4
*/
int NO_GENERATED_KEYS = 2;
/** {@collect.stats}
* Moves to this <code>Statement</code> object's next result, deals with
* any current <code>ResultSet</code> object(s) according to the instructions
* specified by the given flag, and returns
* <code>true</code> if the next result is a <code>ResultSet</code> object.
*
* <P>There are no more results when the following is true:
* <PRE>
* // stmt is a Statement object
* ((stmt.getMoreResults(current) == false) && (stmt.getUpdateCount() == -1))
* </PRE>
*
* @param current one of the following <code>Statement</code>
* constants indicating what should happen to current
* <code>ResultSet</code> objects obtained using the method
* <code>getResultSet</code>:
* <code>Statement.CLOSE_CURRENT_RESULT</code>,
* <code>Statement.KEEP_CURRENT_RESULT</code>, or
* <code>Statement.CLOSE_ALL_RESULTS</code>
* @return <code>true</code> if the next result is a <code>ResultSet</code>
* object; <code>false</code> if it is an update count or there are no
* more results
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code> or the argument
* supplied is not one of the following:
* <code>Statement.CLOSE_CURRENT_RESULT</code>,
* <code>Statement.KEEP_CURRENT_RESULT</code> or
* <code>Statement.CLOSE_ALL_RESULTS</code>
*@exception SQLFeatureNotSupportedException if
* <code>DatabaseMetaData.supportsMultipleOpenResults</code> returns
* <code>false</code> and either
* <code>Statement.KEEP_CURRENT_RESULT</code> or
* <code>Statement.CLOSE_ALL_RESULTS</code> are supplied as
* the argument.
* @since 1.4
* @see #execute
*/
boolean getMoreResults(int current) throws SQLException;
/** {@collect.stats}
* Retrieves any auto-generated keys created as a result of executing this
* <code>Statement</code> object. If this <code>Statement</code> object did
* not generate any keys, an empty <code>ResultSet</code>
* object is returned.
*
*<p><B>Note:</B>If the columns which represent the auto-generated keys were not specified,
* the JDBC driver implementation will determine the columns which best represent the auto-generated keys.
*
* @return a <code>ResultSet</code> object containing the auto-generated key(s)
* generated by the execution of this <code>Statement</code> object
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.4
*/
ResultSet getGeneratedKeys() throws SQLException;
/** {@collect.stats}
* Executes the given SQL statement and signals the driver with the
* given flag about whether the
* auto-generated keys produced by this <code>Statement</code> object
* should be made available for retrieval. The driver will ignore the
* flag if the SQL statement
* is not an <code>INSERT</code> statement, or an SQL statement able to return
* auto-generated keys (the list of such statements is vendor-specific).
*
* @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
* <code>DELETE</code>; or an SQL statement that returns nothing,
* such as a DDL statement.
*
* @param autoGeneratedKeys a flag indicating whether auto-generated keys
* should be made available for retrieval;
* one of the following constants:
* <code>Statement.RETURN_GENERATED_KEYS</code>
* <code>Statement.NO_GENERATED_KEYS</code>
* @return either (1) the row count for SQL Data Manipulation Language (DML) statements
* or (2) 0 for SQL statements that return nothing
*
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code>, the given
* SQL statement returns a <code>ResultSet</code> object, or
* the given constant is not one of those allowed
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method with a constant of Statement.RETURN_GENERATED_KEYS
* @since 1.4
*/
int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException;
/** {@collect.stats}
* Executes the given SQL statement and signals the driver that the
* auto-generated keys indicated in the given array should be made available
* for retrieval. This array contains the indexes of the columns in the
* target table that contain the auto-generated keys that should be made
* available. The driver will ignore the array if the SQL statement
* is not an <code>INSERT</code> statement, or an SQL statement able to return
* auto-generated keys (the list of such statements is vendor-specific).
*
* @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
* <code>DELETE</code>; or an SQL statement that returns nothing,
* such as a DDL statement.
*
* @param columnIndexes an array of column indexes indicating the columns
* that should be returned from the inserted row
* @return either (1) the row count for SQL Data Manipulation Language (DML) statements
* or (2) 0 for SQL statements that return nothing
*
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code>, the SQL
* statement returns a <code>ResultSet</code> object, or the
* second argument supplied to this method is not an <code>int</code> array
* whose elements are valid column indexes
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.4
*/
int executeUpdate(String sql, int columnIndexes[]) throws SQLException;
/** {@collect.stats}
* Executes the given SQL statement and signals the driver that the
* auto-generated keys indicated in the given array should be made available
* for retrieval. This array contains the names of the columns in the
* target table that contain the auto-generated keys that should be made
* available. The driver will ignore the array if the SQL statement
* is not an <code>INSERT</code> statement, or an SQL statement able to return
* auto-generated keys (the list of such statements is vendor-specific).
*
* @param sql an SQL Data Manipulation Language (DML) statement, such as <code>INSERT</code>, <code>UPDATE</code> or
* <code>DELETE</code>; or an SQL statement that returns nothing,
* such as a DDL statement.
* @param columnNames an array of the names of the columns that should be
* returned from the inserted row
* @return either the row count for <code>INSERT</code>, <code>UPDATE</code>,
* or <code>DELETE</code> statements, or 0 for SQL statements
* that return nothing
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code>, the SQL
* statement returns a <code>ResultSet</code> object, or the
* second argument supplied to this method is not a <code>String</code> array
* whose elements are valid column names
*
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @since 1.4
*/
int executeUpdate(String sql, String columnNames[]) throws SQLException;
/** {@collect.stats}
* Executes the given SQL statement, which may return multiple results,
* and signals the driver that any
* auto-generated keys should be made available
* for retrieval. The driver will ignore this signal if the SQL statement
* is not an <code>INSERT</code> statement, or an SQL statement able to return
* auto-generated keys (the list of such statements is vendor-specific).
* <P>
* In some (uncommon) situations, a single SQL statement may return
* multiple result sets and/or update counts. Normally you can ignore
* this unless you are (1) executing a stored procedure that you know may
* return multiple results or (2) you are dynamically executing an
* unknown SQL string.
* <P>
* The <code>execute</code> method executes an SQL statement and indicates the
* form of the first result. You must then use the methods
* <code>getResultSet</code> or <code>getUpdateCount</code>
* to retrieve the result, and <code>getMoreResults</code> to
* move to any subsequent result(s).
*
* @param sql any SQL statement
* @param autoGeneratedKeys a constant indicating whether auto-generated
* keys should be made available for retrieval using the method
* <code>getGeneratedKeys</code>; one of the following constants:
* <code>Statement.RETURN_GENERATED_KEYS</code> or
* <code>Statement.NO_GENERATED_KEYS</code>
* @return <code>true</code> if the first result is a <code>ResultSet</code>
* object; <code>false</code> if it is an update count or there are
* no results
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code> or the second
* parameter supplied to this method is not
* <code>Statement.RETURN_GENERATED_KEYS</code> or
* <code>Statement.NO_GENERATED_KEYS</code>.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method with a constant of Statement.RETURN_GENERATED_KEYS
* @see #getResultSet
* @see #getUpdateCount
* @see #getMoreResults
* @see #getGeneratedKeys
*
* @since 1.4
*/
boolean execute(String sql, int autoGeneratedKeys) throws SQLException;
/** {@collect.stats}
* Executes the given SQL statement, which may return multiple results,
* and signals the driver that the
* auto-generated keys indicated in the given array should be made available
* for retrieval. This array contains the indexes of the columns in the
* target table that contain the auto-generated keys that should be made
* available. The driver will ignore the array if the SQL statement
* is not an <code>INSERT</code> statement, or an SQL statement able to return
* auto-generated keys (the list of such statements is vendor-specific).
* <P>
* Under some (uncommon) situations, a single SQL statement may return
* multiple result sets and/or update counts. Normally you can ignore
* this unless you are (1) executing a stored procedure that you know may
* return multiple results or (2) you are dynamically executing an
* unknown SQL string.
* <P>
* The <code>execute</code> method executes an SQL statement and indicates the
* form of the first result. You must then use the methods
* <code>getResultSet</code> or <code>getUpdateCount</code>
* to retrieve the result, and <code>getMoreResults</code> to
* move to any subsequent result(s).
*
* @param sql any SQL statement
* @param columnIndexes an array of the indexes of the columns in the
* inserted row that should be made available for retrieval by a
* call to the method <code>getGeneratedKeys</code>
* @return <code>true</code> if the first result is a <code>ResultSet</code>
* object; <code>false</code> if it is an update count or there
* are no results
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code> or the
* elements in the <code>int</code> array passed to this method
* are not valid column indexes
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @see #getResultSet
* @see #getUpdateCount
* @see #getMoreResults
*
* @since 1.4
*/
boolean execute(String sql, int columnIndexes[]) throws SQLException;
/** {@collect.stats}
* Executes the given SQL statement, which may return multiple results,
* and signals the driver that the
* auto-generated keys indicated in the given array should be made available
* for retrieval. This array contains the names of the columns in the
* target table that contain the auto-generated keys that should be made
* available. The driver will ignore the array if the SQL statement
* is not an <code>INSERT</code> statement, or an SQL statement able to return
* auto-generated keys (the list of such statements is vendor-specific).
* <P>
* In some (uncommon) situations, a single SQL statement may return
* multiple result sets and/or update counts. Normally you can ignore
* this unless you are (1) executing a stored procedure that you know may
* return multiple results or (2) you are dynamically executing an
* unknown SQL string.
* <P>
* The <code>execute</code> method executes an SQL statement and indicates the
* form of the first result. You must then use the methods
* <code>getResultSet</code> or <code>getUpdateCount</code>
* to retrieve the result, and <code>getMoreResults</code> to
* move to any subsequent result(s).
*
* @param sql any SQL statement
* @param columnNames an array of the names of the columns in the inserted
* row that should be made available for retrieval by a call to the
* method <code>getGeneratedKeys</code>
* @return <code>true</code> if the next result is a <code>ResultSet</code>
* object; <code>false</code> if it is an update count or there
* are no more results
* @exception SQLException if a database access error occurs,
* this method is called on a closed <code>Statement</code> or the
* elements of the <code>String</code> array passed to this
* method are not valid column names
* @throws SQLFeatureNotSupportedException if the JDBC driver does not support this method
* @see #getResultSet
* @see #getUpdateCount
* @see #getMoreResults
* @see #getGeneratedKeys
*
* @since 1.4
*/
boolean execute(String sql, String columnNames[]) throws SQLException;
/** {@collect.stats}
* Retrieves the result set holdability for <code>ResultSet</code> objects
* generated by this <code>Statement</code> object.
*
* @return either <code>ResultSet.HOLD_CURSORS_OVER_COMMIT</code> or
* <code>ResultSet.CLOSE_CURSORS_AT_COMMIT</code>
* @exception SQLException if a database access error occurs or
* this method is called on a closed <code>Statement</code>
*
* @since 1.4
*/
int getResultSetHoldability() throws SQLException;
/** {@collect.stats}
* Retrieves whether this <code>Statement</code> object has been closed. A <code>Statement</code> is closed if the
* method close has been called on it, or if it is automatically closed.
* @return true if this <code>Statement</code> object is closed; false if it is still open
* @throws SQLException if a database access error occurs
* @since 1.6
*/
boolean isClosed() throws SQLException;
/** {@collect.stats}
* Requests that a <code>Statement</code> be pooled or not pooled. The value
* specified is a hint to the statement pool implementation indicating
* whether the applicaiton wants the statement to be pooled. It is up to
* the statement pool manager as to whether the hint is used.
* <p>
* The poolable value of a statement is applicable to both internal
* statement caches implemented by the driver and external statement caches
* implemented by application servers and other applications.
* <p>
* By default, a <code>Statement</code> is not poolable when created, and
* a <code>PreparedStatement</code> and <code>CallableStatement</code>
* are poolable when created.
* <p>
* @param poolable requests that the statement be pooled if true and
* that the statement not be pooled if false
* <p>
* @throws SQLException if this method is called on a closed
* <code>Statement</code>
* <p>
* @since 1.6
*/
void setPoolable(boolean poolable)
throws SQLException;
/** {@collect.stats}
* Returns a value indicating whether the <code>Statement</code>
* is poolable or not.
* <p>
* @return <code>true</code> if the <code>Statement</code>
* is poolable; <code>false</code> otherwise
* <p>
* @throws SQLException if this method is called on a closed
* <code>Statement</code>
* <p>
* @since 1.6
* <p>
* @see java.sql.Statement#setPoolable(boolean) setPoolable(boolean)
*/
boolean isPoolable()
throws SQLException;
}
|
Java
|
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* The subclass of {@link SQLException} thrown when the SQLState class value is '<i>22</i>'. This indicates
* various data errors, including but not limited to not-allowed conversion, division by 0
* and invalid arguments to functions.
*
* @since 1.6
*/
public class SQLDataException extends SQLNonTransientException {
/** {@collect.stats}
* Constructs a <code>SQLDataException</code> object.
* The <code>reason</code>, <code>SQLState</code> are initialized
* to <code>null</code> and the vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
*
* @since 1.6
*/
public SQLDataException() {
super();
}
/** {@collect.stats}
* Constructs a <code>SQLDataException</code> object with a given
* <code>reason</code>.
* The <code>SQLState</code> is initialized
* to <code>null</code> and the vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
*
* @param reason a description of the exception
* @since 1.6
*/
public SQLDataException(String reason) {
super(reason);
}
/** {@collect.stats}
* Constructs a <code>SQLDataException</code> object with a given
* <code>reason</code> and <code>SQLState</code>. The
* vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @since 1.6
*/
public SQLDataException(String reason, String SQLState) {
super(reason, SQLState);
}
/** {@collect.stats}
* Constructs a <code>SQLDataException</code> object with a given
* <code>reason</code>, <code>SQLState</code> and
* <code>vendorCode</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor specific exception code
* @since 1.6
*/
public SQLDataException(String reason, String SQLState, int vendorCode) {
super(reason, SQLState, vendorCode);
}
/** {@collect.stats}
* Constructs a <code>SQLDataException</code> object with a given
* <code>cause</code>.
* The <code>SQLState</code> is initialized
* to <code>null</code> and the vendor code is initialized to 0.
* The <code>reason</code> is initialized to <code>null</code> if
* <code>cause==null</code> or to <code>cause.toString()</code> if
* <code>cause!=null</code>.
* <p>
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLDataException(Throwable cause) {
super(cause);
}
/** {@collect.stats}
* Constructs a <code>SQLDataException</code> object with a given
* <code>reason</code> and <code>cause</code>.
* The <code>SQLState</code> is initialized to <code>null</code>
* and the vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLDataException(String reason, Throwable cause) {
super(reason, cause);
}
/** {@collect.stats}
* Constructs a <code>SQLDataException</code> object with a given
* <code>reason</code>, <code>SQLState</code> and <code>cause</code>.
* The vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLDataException(String reason, String SQLState, Throwable cause) {
super(reason, SQLState, cause);
}
/** {@collect.stats}
* Constructs a <code>SQLDataException</code> object with a given
* <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
* and <code>cause</code>.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor-specific exception code
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLDataException(String reason, String SQLState, int vendorCode, Throwable cause) {
super(reason, SQLState, vendorCode, cause);
}
private static final long serialVersionUID = -6889123282670549800L;
}
|
Java
|
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* Interface for JDBC classes which provide the ability to retrieve the delegate instance when the instance
* in question is in fact a proxy class.
* <p>
* The wrapper pattern is employed by many JDBC driver implementations to provide extensions beyond
* the traditional JDBC API that are specific to a data source. Developers may wish to gain access to
* these resources that are wrapped (the delegates) as proxy class instances representing the
* the actual resources. This interface describes a standard mechanism to access
* these wrapped resources
* represented by their proxy, to permit direct access to the resource delegates.
*
* @since 1.6
*/
public interface Wrapper {
/** {@collect.stats}
* Returns an object that implements the given interface to allow access to
* non-standard methods, or standard methods not exposed by the proxy.
*
* If the receiver implements the interface then the result is the receiver
* or a proxy for the receiver. If the receiver is a wrapper
* and the wrapped object implements the interface then the result is the
* wrapped object or a proxy for the wrapped object. Otherwise return the
* the result of calling <code>unwrap</code> recursively on the wrapped object
* or a proxy for that result. If the receiver is not a
* wrapper and does not implement the interface, then an <code>SQLException</code> is thrown.
*
* @param iface A Class defining an interface that the result must implement.
* @return an object that implements the interface. May be a proxy for the actual implementing object.
* @throws java.sql.SQLException If no object found that implements the interface
* @since 1.6
*/
<T> T unwrap(java.lang.Class<T> iface) throws java.sql.SQLException;
/** {@collect.stats}
* Returns true if this either implements the interface argument or is directly or indirectly a wrapper
* for an object that does. Returns false otherwise. If this implements the interface then return true,
* else if this is a wrapper then return the result of recursively calling <code>isWrapperFor</code> on the wrapped
* object. If this does not implement the interface and is not a wrapper, return false.
* This method should be implemented as a low-cost operation compared to <code>unwrap</code> so that
* callers can use this method to avoid expensive <code>unwrap</code> calls that may fail. If this method
* returns true then calling <code>unwrap</code> with the same argument should succeed.
*
* @param iface a Class defining an interface.
* @return true if this implements the interface or directly or indirectly wraps an object that does.
* @throws java.sql.SQLException if an error occurs while determining whether this is a wrapper
* for an object with the given interface.
* @since 1.6
*/
boolean isWrapperFor(java.lang.Class<?> iface) throws java.sql.SQLException;
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* The interface that every driver class must implement.
* <P>The Java SQL framework allows for multiple database drivers.
*
* <P>Each driver should supply a class that implements
* the Driver interface.
*
* <P>The DriverManager will try to load as many drivers as it can
* find and then for any given connection request, it will ask each
* driver in turn to try to connect to the target URL.
*
* <P>It is strongly recommended that each Driver class should be
* small and standalone so that the Driver class can be loaded and
* queried without bringing in vast quantities of supporting code.
*
* <P>When a Driver class is loaded, it should create an instance of
* itself and register it with the DriverManager. This means that a
* user can load and register a driver by calling
* <pre>
* <code>Class.forName("foo.bah.Driver")</code>
* </pre>
*
* @see DriverManager
* @see Connection
*/
public interface Driver {
/** {@collect.stats}
* Attempts to make a database connection to the given URL.
* The driver should return "null" if it realizes it is the wrong kind
* of driver to connect to the given URL. This will be common, as when
* the JDBC driver manager is asked to connect to a given URL it passes
* the URL to each loaded driver in turn.
*
* <P>The driver should throw an <code>SQLException</code> if it is the right
* driver to connect to the given URL but has trouble connecting to
* the database.
*
* <P>The <code>java.util.Properties</code> argument can be used to pass
* arbitrary string tag/value pairs as connection arguments.
* Normally at least "user" and "password" properties should be
* included in the <code>Properties</code> object.
*
* @param url the URL of the database to which to connect
* @param info a list of arbitrary string tag/value pairs as
* connection arguments. Normally at least a "user" and
* "password" property should be included.
* @return a <code>Connection</code> object that represents a
* connection to the URL
* @exception SQLException if a database access error occurs
*/
Connection connect(String url, java.util.Properties info)
throws SQLException;
/** {@collect.stats}
* Retrieves whether the driver thinks that it can open a connection
* to the given URL. Typically drivers will return <code>true</code> if they
* understand the subprotocol specified in the URL and <code>false</code> if
* they do not.
*
* @param url the URL of the database
* @return <code>true</code> if this driver understands the given URL;
* <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean acceptsURL(String url) throws SQLException;
/** {@collect.stats}
* Gets information about the possible properties for this driver.
* <P>
* The <code>getPropertyInfo</code> method is intended to allow a generic
* GUI tool to discover what properties it should prompt
* a human for in order to get
* enough information to connect to a database. Note that depending on
* the values the human has supplied so far, additional values may become
* necessary, so it may be necessary to iterate though several calls
* to the <code>getPropertyInfo</code> method.
*
* @param url the URL of the database to which to connect
* @param info a proposed list of tag/value pairs that will be sent on
* connect open
* @return an array of <code>DriverPropertyInfo</code> objects describing
* possible properties. This array may be an empty array if
* no properties are required.
* @exception SQLException if a database access error occurs
*/
DriverPropertyInfo[] getPropertyInfo(String url, java.util.Properties info)
throws SQLException;
/** {@collect.stats}
* Retrieves the driver's major version number. Initially this should be 1.
*
* @return this driver's major version number
*/
int getMajorVersion();
/** {@collect.stats}
* Gets the driver's minor version number. Initially this should be 0.
* @return this driver's minor version number
*/
int getMinorVersion();
/** {@collect.stats}
* Reports whether this driver is a genuine JDBC
* Compliant<sup><font size=-2>TM</font></sup> driver.
* A driver may only report <code>true</code> here if it passes the JDBC
* compliance tests; otherwise it is required to return <code>false</code>.
* <P>
* JDBC compliance requires full support for the JDBC API and full support
* for SQL 92 Entry Level. It is expected that JDBC compliant drivers will
* be available for all the major commercial databases.
* <P>
* This method is not intended to encourage the development of non-JDBC
* compliant drivers, but is a recognition of the fact that some vendors
* are interested in using the JDBC API and framework for lightweight
* databases that do not support full database functionality, or for
* special databases such as document information retrieval where a SQL
* implementation may not be feasible.
* @return <code>true</code> if this driver is JDBC Compliant; <code>false</code>
* otherwise
*/
boolean jdbcCompliant();
}
|
Java
|
/*
* Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* An object that can be used to get information about the types
* and properties for each parameter marker in a
* <code>PreparedStatement</code> object. For some queries and driver
* implementations, the data that would be returned by a <code>ParameterMetaData</code>
* object may not be available until the <code>PreparedStatement</code> has
* been executed.
*<p>
*Some driver implementations may not be able to provide information about the
*types and properties for each parameter marker in a <code>CallableStatement</code>
*object.
*
* @since 1.4
*/
public interface ParameterMetaData extends Wrapper {
/** {@collect.stats}
* Retrieves the number of parameters in the <code>PreparedStatement</code>
* object for which this <code>ParameterMetaData</code> object contains
* information.
*
* @return the number of parameters
* @exception SQLException if a database access error occurs
* @since 1.4
*/
int getParameterCount() throws SQLException;
/** {@collect.stats}
* Retrieves whether null values are allowed in the designated parameter.
*
* @param param the first parameter is 1, the second is 2, ...
* @return the nullability status of the given parameter; one of
* <code>ParameterMetaData.parameterNoNulls</code>,
* <code>ParameterMetaData.parameterNullable</code>, or
* <code>ParameterMetaData.parameterNullableUnknown</code>
* @exception SQLException if a database access error occurs
* @since 1.4
*/
int isNullable(int param) throws SQLException;
/** {@collect.stats}
* The constant indicating that a
* parameter will not allow <code>NULL</code> values.
*/
int parameterNoNulls = 0;
/** {@collect.stats}
* The constant indicating that a
* parameter will allow <code>NULL</code> values.
*/
int parameterNullable = 1;
/** {@collect.stats}
* The constant indicating that the
* nullability of a parameter is unknown.
*/
int parameterNullableUnknown = 2;
/** {@collect.stats}
* Retrieves whether values for the designated parameter can be signed numbers.
*
* @param param the first parameter is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
* @since 1.4
*/
boolean isSigned(int param) throws SQLException;
/** {@collect.stats}
* Retrieves the designated parameter's specified column size.
*
* <P>The returned value represents the maximum column size for the given parameter.
* For numeric data, this is the maximum precision. For character data, this is the length in characters.
* For datetime datatypes, this is the length in characters of the String representation (assuming the
* maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes. For the ROWID datatype,
* this is the length in bytes. 0 is returned for data types where the
* column size is not applicable.
*
* @param param the first parameter is 1, the second is 2, ...
* @return precision
* @exception SQLException if a database access error occurs
* @since 1.4
*/
int getPrecision(int param) throws SQLException;
/** {@collect.stats}
* Retrieves the designated parameter's number of digits to right of the decimal point.
* 0 is returned for data types where the scale is not applicable.
*
* @param param the first parameter is 1, the second is 2, ...
* @return scale
* @exception SQLException if a database access error occurs
* @since 1.4
*/
int getScale(int param) throws SQLException;
/** {@collect.stats}
* Retrieves the designated parameter's SQL type.
*
* @param param the first parameter is 1, the second is 2, ...
* @return SQL type from <code>java.sql.Types</code>
* @exception SQLException if a database access error occurs
* @since 1.4
* @see Types
*/
int getParameterType(int param) throws SQLException;
/** {@collect.stats}
* Retrieves the designated parameter's database-specific type name.
*
* @param param the first parameter is 1, the second is 2, ...
* @return type the name used by the database. If the parameter type is
* a user-defined type, then a fully-qualified type name is returned.
* @exception SQLException if a database access error occurs
* @since 1.4
*/
String getParameterTypeName(int param) throws SQLException;
/** {@collect.stats}
* Retrieves the fully-qualified name of the Java class whose instances
* should be passed to the method <code>PreparedStatement.setObject</code>.
*
* @param param the first parameter is 1, the second is 2, ...
* @return the fully-qualified name of the class in the Java programming
* language that would be used by the method
* <code>PreparedStatement.setObject</code> to set the value
* in the specified parameter. This is the class name used
* for custom mapping.
* @exception SQLException if a database access error occurs
* @since 1.4
*/
String getParameterClassName(int param) throws SQLException;
/** {@collect.stats}
* The constant indicating that the mode of the parameter is unknown.
*/
int parameterModeUnknown = 0;
/** {@collect.stats}
* The constant indicating that the parameter's mode is IN.
*/
int parameterModeIn = 1;
/** {@collect.stats}
* The constant indicating that the parameter's mode is INOUT.
*/
int parameterModeInOut = 2;
/** {@collect.stats}
* The constant indicating that the parameter's mode is OUT.
*/
int parameterModeOut = 4;
/** {@collect.stats}
* Retrieves the designated parameter's mode.
*
* @param param the first parameter is 1, the second is 2, ...
* @return mode of the parameter; one of
* <code>ParameterMetaData.parameterModeIn</code>,
* <code>ParameterMetaData.parameterModeOut</code>, or
* <code>ParameterMetaData.parameterModeInOut</code>
* <code>ParameterMetaData.parameterModeUnknown</code>.
* @exception SQLException if a database access error occurs
* @since 1.4
*/
int getParameterMode(int param) throws SQLException;
}
|
Java
|
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* The subclass of {@link SQLException} thrown when the SQLState class value is '<i>42</i>'. This indicates that the
* in-progress query has violated SQL syntax rules.
*
* @since 1.6
*/
public class SQLSyntaxErrorException extends SQLNonTransientException {
/** {@collect.stats}
* Constructs a <code>SQLSyntaxErrorException</code> object.
* The <code>reason</code>, <code>SQLState</code> are initialized
* to <code>null</code> and the vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @since 1.6
*/
public SQLSyntaxErrorException() {
super();
}
/** {@collect.stats}
* Constructs a <code>SQLSyntaxErrorException</code> object
* with a given <code>reason</code>. The <code>SQLState</code>
* is initialized to <code>null</code> and the vender code is initialized
* to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @since 1.6
*/
public SQLSyntaxErrorException(String reason) {
super(reason);
}
/** {@collect.stats}
* Constructs a <code>SQLSyntaxErrorException</code> object
* with a given <code>reason</code> and <code>SQLState</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
* is initialized to 0.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @since 1.6
*/
public SQLSyntaxErrorException(String reason, String SQLState) {
super(reason, SQLState);
}
/** {@collect.stats}
* Constructs a <code>SQLSyntaxErrorException</code> object
* with a given <code>reason</code>, <code>SQLState</code> and
* <code>vendorCode</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor specific exception code
* @since 1.6
*/
public SQLSyntaxErrorException(String reason, String SQLState, int vendorCode) {
super(reason, SQLState, vendorCode);
}
/** {@collect.stats}
* Constructs a <code>SQLSyntaxErrorException</code> object
* with a given <code>cause</code>.
* The <code>SQLState</code> is initialized
* to <code>null</code> and the vendor code is initialized to 0.
* The <code>reason</code> is initialized to <code>null</code> if
* <code>cause==null</code> or to <code>cause.toString()</code> if
* <code>cause!=null</code>.
* <p>
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval bythe <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLSyntaxErrorException(Throwable cause) {
super(cause);
}
/** {@collect.stats}
* Constructs a <code>SQLSyntaxErrorException</code> object
* with a given
* <code>reason</code> and <code>cause</code>.
* The <code>SQLState</code> is initialized to <code>null</code>
* and the vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLSyntaxErrorException(String reason, Throwable cause) {
super(reason, cause);
}
/** {@collect.stats}
* Constructs a <code>SQLSyntaxErrorException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code> and <code>cause</code>.
* The vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param cause the (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLSyntaxErrorException(String reason, String SQLState, Throwable cause) {
super(reason, SQLState, cause);
}
/** {@collect.stats}
* Constructs a <code>SQLSyntaxErrorException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
* and <code>cause</code>.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor-specific exception code
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLSyntaxErrorException(String reason, String SQLState, int vendorCode, Throwable cause) {
super(reason, SQLState, vendorCode, cause);
}
private static final long serialVersionUID = -1843832610477496053L;
}
|
Java
|
/*
* Copyright (c) 1999, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
import java.security.*;
/** {@collect.stats}
* The permission for which the <code>SecurityManager</code> will check
* when code that is running in an applet calls the
* <code>DriverManager.setLogWriter</code> method or the
* <code>DriverManager.setLogStream</code> (deprecated) method.
* If there is no <code>SQLPermission</code> object, these methods
* throw a <code>java.lang.SecurityException</code> as a runtime exception.
* <P>
* A <code>SQLPermission</code> object contains
* a name (also referred to as a "target name") but no actions
* list; there is either a named permission or there is not.
* The target name is the name of the permission (see below). The
* naming convention follows the hierarchical property naming convention.
* In addition, an asterisk
* may appear at the end of the name, following a ".", or by itself, to
* signify a wildcard match. For example: <code>loadLibrary.*</code>
* or <code>*</code> is valid,
* but <code>*loadLibrary</code> or <code>a*b</code> is not valid.
* <P>
* The following table lists all the possible <code>SQLPermission</code> target names.
* Currently, the only name allowed is <code>setLog</code>.
* The table gives a description of what the permission allows
* and a discussion of the risks of granting code the permission.
* <P>
*
* <table border=1 cellpadding=5 summary="permission target name, what the permission allows, and associated risks">
* <tr>
* <th>Permission Target Name</th>
* <th>What the Permission Allows</th>
* <th>Risks of Allowing this Permission</th>
* </tr>
*
* <tr>
* <td>setLog</td>
* <td>Setting of the logging stream</td>
* <td>This is a dangerous permission to grant.
* The contents of the log may contain usernames and passwords,
* SQL statements, and SQL data.</td>
* </tr>
*
* </table>
*
* The person running an applet decides what permissions to allow
* and will run the <code>Policy Tool</code> to create an
* <code>SQLPermission</code> in a policy file. A programmer does
* not use a constructor directly to create an instance of <code>SQLPermission</code>
* but rather uses a tool.
* @since 1.3
* @see java.security.BasicPermission
* @see java.security.Permission
* @see java.security.Permissions
* @see java.security.PermissionCollection
* @see java.lang.SecurityManager
*
*/
public final class SQLPermission extends BasicPermission {
/** {@collect.stats}
* Creates a new <code>SQLPermission</code> object with the specified name.
* The name is the symbolic name of the <code>SQLPermission</code>; currently,
* the only name allowed is "setLog".
*
* @param name the name of this <code>SQLPermission</code> object, which must
* be <code>setLog</code>
* @throws NullPointerException if <code>name</code> is <code>null</code>.
* @throws IllegalArgumentException if <code>name</code> is empty.
*/
public SQLPermission(String name) {
super(name);
}
/** {@collect.stats}
* Creates a new <code>SQLPermission</code> object with the specified name.
* The name is the symbolic name of the <code>SQLPermission</code>; the
* actions <code>String</code> is currently unused and should be
* <code>null</code>.
*
* @param name the name of this <code>SQLPermission</code> object, which must
* be <code>setLog</code>
* @param actions should be <code>null</code>
* @throws NullPointerException if <code>name</code> is <code>null</code>.
* @throws IllegalArgumentException if <code>name</code> is empty.
*/
public SQLPermission(String name, String actions) {
super(name, actions);
}
/** {@collect.stats}
* Private serial version unique ID to ensure serialization
* compatibility.
*/
static final long serialVersionUID = -1439323187199563495L;
}
|
Java
|
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* The subclass of {@link SQLException} thrown when the SQLState class value is '<i>40</i>'. This indicates that the
* current statement was automatically rolled back by the database becuase of deadlock or other
* transaction serialization failures.
*
* @since 1.6
*/
public class SQLTransactionRollbackException extends SQLTransientException {
/** {@collect.stats}
* Constructs a <code>SQLTransactionRollbackException</code> object.
* The <code>reason</code>, <code>SQLState</code> are initialized
* to <code>null</code> and the vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @since 1.6
*/
public SQLTransactionRollbackException() {
super();
}
/** {@collect.stats}
* Constructs a <code>SQLTransactionRollbackException</code> object
* with a given <code>reason</code>. The <code>SQLState</code>
* is initialized to <code>null</code> and the vender code is initialized
* to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @since 1.6
*/
public SQLTransactionRollbackException(String reason) {
super(reason);
}
/** {@collect.stats}
* Constructs a <code>SQLTransactionRollbackException</code> object
* with a given <code>reason</code> and <code>SQLState</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
* is initialized to 0.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @since 1.6
*/
public SQLTransactionRollbackException(String reason, String SQLState) {
super(reason, SQLState);
}
/** {@collect.stats}
* Constructs a <code>SQLTransactionRollbackException</code> object
* with a given <code>reason</code>, <code>SQLState</code> and
* <code>vendorCode</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor specific exception code
* @since 1.6
*/
public SQLTransactionRollbackException(String reason, String SQLState, int vendorCode) {
super(reason, SQLState, vendorCode);
}
/** {@collect.stats}
* Constructs a <code>SQLTransactionRollbackException</code> object
* with a given <code>cause</code>.
* The <code>SQLState</code> is initialized
* to <code>null</code> and the vendor code is initialized to 0.
* The <code>reason</code> is initialized to <code>null</code> if
* <code>cause==null</code> or to <code>cause.toString()</code> if
* <code>cause!=null</code>.
* <p>
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLTransactionRollbackException(Throwable cause) {
super(cause);
}
/** {@collect.stats}
* Constructs a <code>SQLTransactionRollbackException</code> object
* with a given
* <code>reason</code> and <code>cause</code>.
* The <code>SQLState</code> is initialized to <code>null</code>
* and the vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLTransactionRollbackException(String reason, Throwable cause) {
super(reason, cause);
}
/** {@collect.stats}
* Constructs a <code>SQLTransactionRollbackException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code> and <code>cause</code>.
* The vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLTransactionRollbackException(String reason, String SQLState, Throwable cause) {
super(reason, SQLState, cause);
}
/** {@collect.stats}
* Constructs a <code>SQLTransactionRollbackException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
* and <code>cause</code>.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor-specific exception code
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLTransactionRollbackException(String reason, String SQLState, int vendorCode, Throwable cause) {
super(reason, SQLState, vendorCode, cause);
}
private static final long serialVersionUID = 5246680841170837229L;
}
|
Java
|
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* <P> The subclass of {@link SQLException} thrown for the SQLState
* class value '<i>08</i>', representing
* that the connection operation that failed will not succeed when
* the operation is retried without the cause of the failure being corrected.
* <p>
* @since 1.6
*/
public class SQLNonTransientConnectionException extends java.sql.SQLNonTransientException {
/** {@collect.stats}
* Constructs a <code>SQLNonTransientConnectionException</code> object.
* The <code>reason</code>, <code>SQLState</code> are initialized
* to <code>null</code> and the vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
*
* @since 1.6
*/
public SQLNonTransientConnectionException() {
super();
}
/** {@collect.stats}
* Constructs a <code>SQLNonTransientConnectionException</code> object
* with a given <code>reason</code>. The <code>SQLState</code>
* is initialized to <code>null</code> and the vender code is initialized
* to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @since 1.6
*/
public SQLNonTransientConnectionException(String reason) {
super(reason);
}
/** {@collect.stats}
* Constructs a <code>SQLNonTransientConnectionException</code> object
* with a given <code>reason</code> and <code>SQLState</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
* is initialized to 0.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @since 1.6
*/
public SQLNonTransientConnectionException(String reason, String SQLState) {
super(reason,SQLState);
}
/** {@collect.stats}
* Constructs a <code>SQLNonTransientConnectionException</code> object
* with a given <code>reason</code>, <code>SQLState</code> and
* <code>vendorCode</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor specific exception code
* @since 1.6
*/
public SQLNonTransientConnectionException(String reason, String SQLState, int vendorCode) {
super(reason,SQLState,vendorCode);
}
/** {@collect.stats}
* Constructs a <code>SQLNonTransientConnectionException</code> object
* with a given <code>cause</code>.
* The <code>SQLState</code> is initialized
* to <code>null</code> and the vendor code is initialized to 0.
* The <code>reason</code> is initialized to <code>null</code> if
* <code>cause==null</code> or to <code>cause.toString()</code> if
* <code>cause!=null</code>.
* <p>
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLNonTransientConnectionException(Throwable cause) {
super(cause);
}
/** {@collect.stats}
* Constructs a <code>SQLTransientException</code> object
* with a given
* <code>reason</code> and <code>cause</code>.
* The <code>SQLState</code> is initialized to <code>null</code>
* and the vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLNonTransientConnectionException(String reason, Throwable cause) {
super(reason,cause);
}
/** {@collect.stats}
* Constructs a <code>SQLNonTransientConnectionException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code> and <code>cause</code>.
* The vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param cause the (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLNonTransientConnectionException(String reason, String SQLState, Throwable cause) {
super(reason,SQLState,cause);
}
/** {@collect.stats}
* Constructs a <code>SQLNonTransientConnectionException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
* and <code>cause</code>.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor-specific exception code
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLNonTransientConnectionException(String reason, String SQLState, int vendorCode, Throwable cause) {
super(reason,SQLState,vendorCode,cause);
}
private static final long serialVersionUID = -5852318857474782892L;
}
|
Java
|
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* <P>The subclass of {@link SQLException} thrown when the timeout specified by <code>Statement</code>
* has expired.
* <P> This exception does not correspond to a standard SQLState.
*
* @since 1.6
*/
public class SQLTimeoutException extends SQLTransientException {
/** {@collect.stats}
* Constructs a <code>SQLTimeoutException</code> object.
* The <code>reason</code>, <code>SQLState</code> are initialized
* to <code>null</code> and the vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @since 1.6
*/
public SQLTimeoutException() {
super();
}
/** {@collect.stats}
* Constructs a <code>SQLTimeoutException</code> object
* with a given <code>reason</code>. The <code>SQLState</code>
* is initialized to <code>null</code> and the vender code is initialized
* to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @since 1.6
*/
public SQLTimeoutException(String reason) {
super(reason);
}
/** {@collect.stats}
* Constructs a <code>SQLTimeoutException</code> object
* with a given <code>reason</code> and <code>SQLState</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
* is initialized to 0.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @since 1.6
*/
public SQLTimeoutException(String reason, String SQLState) {
super(reason, SQLState);
}
/** {@collect.stats}
* Constructs a <code>SQLTimeoutException</code> object
* with a given <code>reason</code>, <code>SQLState</code> and
* <code>vendorCode</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor specific exception code
* @since 1.6
*/
public SQLTimeoutException(String reason, String SQLState, int vendorCode) {
super(reason, SQLState, vendorCode);
}
/** {@collect.stats}
* Constructs a <code>SQLTimeoutException</code> object
* with a given <code>cause</code>.
* The <code>SQLState</code> is initialized
* to <code>null</code> and the vendor code is initialized to 0.
* The <code>reason</code> is initialized to <code>null</code> if
* <code>cause==null</code> or to <code>cause.toString()</code> if
* <code>cause!=null</code>.
* <p>
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLTimeoutException(Throwable cause) {
super(cause);
}
/** {@collect.stats}
* Constructs a <code>SQLTimeoutException</code> object
* with a given
* <code>reason</code> and <code>cause</code>.
* The <code>SQLState</code> is initialized to <code>null</code>
* and the vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLTimeoutException(String reason, Throwable cause) {
super(reason, cause);
}
/** {@collect.stats}
* Constructs a <code>SQLTimeoutException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code> and <code>cause</code>.
* The vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLTimeoutException(String reason, String SQLState, Throwable cause) {
super(reason, SQLState, cause);
}
/** {@collect.stats}
* Constructs a <code>SQLTimeoutException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
* and <code>cause</code>.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor-specific exception code
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLTimeoutException(String reason, String SQLState, int vendorCode, Throwable cause) {
super(reason, SQLState, vendorCode, cause);
}
private static final long serialVersionUID = -4487171280562520262L;
}
|
Java
|
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
/** {@collect.stats}
* The mapping in the JavaTM programming language for the SQL XML type.
* XML is a built-in type that stores an XML value
* as a column value in a row of a database table.
* By default drivers implement an SQLXML object as
* a logical pointer to the XML data
* rather than the data itself.
* An SQLXML object is valid for the duration of the transaction in which it was created.
* <p>
* The SQLXML interface provides methods for accessing the XML value
* as a String, a Reader or Writer, or as a Stream. The XML value
* may also be accessed through a Source or set as a Result, which
* are used with XML Parser APIs such as DOM, SAX, and StAX, as
* well as with XSLT transforms and XPath evaluations.
* <p>
* Methods in the interfaces ResultSet, CallableStatement, and PreparedStatement,
* such as getSQLXML allow a programmer to access an XML value.
* In addition, this interface has methods for updating an XML value.
* <p>
* The XML value of the SQLXML instance may be obtained as a BinaryStream using
* <pre>
* SQLXML sqlxml = resultSet.getSQLXML(column);
* InputStream binaryStream = sqlxml.getBinaryStream();
* </pre>
* For example, to parse an XML value with a DOM parser:
* <pre>
* DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
* Document result = parser.parse(binaryStream);
* </pre>
* or to parse an XML value with a SAX parser to your handler:
* <pre>
* SAXParser parser = SAXParserFactory.newInstance().newSAXParser();
* parser.parse(binaryStream, myHandler);
* </pre>
* or to parse an XML value with a StAX parser:
* <pre>
* XMLInputFactory factory = XMLInputFactory.newInstance();
* XMLStreamReader streamReader = factory.createXMLStreamReader(binaryStream);
* </pre>
* <p>
* Because databases may use an optimized representation for the XML,
* accessing the value through getSource() and
* setResult() can lead to improved processing performance
* without serializing to a stream representation and parsing the XML.
* <p>
* For example, to obtain a DOM Document Node:
* <pre>
* DOMSource domSource = sqlxml.getSource(DOMSource.class);
* Document document = (Document) domSource.getNode();
* </pre>
* or to set the value to a DOM Document Node to myNode:
* <pre>
* DOMResult domResult = sqlxml.setResult(DOMResult.class);
* domResult.setNode(myNode);
* </pre>
* or, to send SAX events to your handler:
* <pre>
* SAXSource saxSource = sqlxml.getSource(SAXSource.class);
* XMLReader xmlReader = saxSource.getXMLReader();
* xmlReader.setContentHandler(myHandler);
* xmlReader.parse(saxSource.getInputSource());
* </pre>
* or, to set the result value from SAX events:
* <pre>
* SAXResult saxResult = sqlxml.setResult(SAXResult.class);
* ContentHandler contentHandler = saxResult.getXMLReader().getContentHandler();
* contentHandler.startDocument();
* // set the XML elements and attributes into the result
* contentHandler.endDocument();
* </pre>
* or, to obtain StAX events:
* <pre>
* StAXSource staxSource = sqlxml.getSource(StAXSource.class);
* XMLStreamReader streamReader = staxSource.getXMLStreamReader();
* </pre>
* or, to set the result value from StAX events:
* <pre>
* StAXResult staxResult = sqlxml.setResult(StAXResult.class);
* XMLStreamWriter streamWriter = staxResult.getXMLStreamWriter();
* </pre>
* or, to perform XSLT transformations on the XML value using the XSLT in xsltFile
* output to file resultFile:
* <pre>
* File xsltFile = new File("a.xslt");
* File myFile = new File("result.xml");
* Transformer xslt = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltFile));
* Source source = sqlxml.getSource(null);
* Result result = new StreamResult(myFile);
* xslt.transform(source, result);
* </pre>
* or, to evaluate an XPath expression on the XML value:
* <pre>
* XPath xpath = XPathFactory.newInstance().newXPath();
* DOMSource domSource = sqlxml.getSource(DOMSource.class);
* Document document = (Document) domSource.getNode();
* String expression = "/foo/@bar";
* String barValue = xpath.evaluate(expression, document);
* </pre>
* To set the XML value to be the result of an XSLT transform:
* <pre>
* File sourceFile = new File("source.xml");
* Transformer xslt = TransformerFactory.newInstance().newTransformer(new StreamSource(xsltFile));
* Source streamSource = new StreamSource(sourceFile);
* Result result = sqlxml.setResult(null);
* xslt.transform(streamSource, result);
* </pre>
* Any Source can be transformed to a Result using the identity transform
* specified by calling newTransformer():
* <pre>
* Transformer identity = TransformerFactory.newInstance().newTransformer();
* Source source = sqlxml.getSource(null);
* File myFile = new File("result.xml");
* Result result = new StreamResult(myFile);
* identity.transform(source, result);
* </pre>
* To write the contents of a Source to standard output:
* <pre>
* Transformer identity = TransformerFactory.newInstance().newTransformer();
* Source source = sqlxml.getSource(null);
* Result result = new StreamResult(System.out);
* identity.transform(source, result);
* </pre>
* To create a DOMSource from a DOMResult:
* <pre>
* DOMSource domSource = new DOMSource(domResult.getNode());
* </pre>
* <p>
* Incomplete or invalid XML values may cause an SQLException when
* set or the exception may occur when execute() occurs. All streams
* must be closed before execute() occurs or an SQLException will be thrown.
* <p>
* Reading and writing XML values to or from an SQLXML object can happen at most once.
* The conceptual states of readable and not readable determine if one
* of the reading APIs will return a value or throw an exception.
* The conceptual states of writable and not writable determine if one
* of the writing APIs will set a value or throw an exception.
* <p>
* The state moves from readable to not readable once free() or any of the
* reading APIs are called: getBinaryStream(), getCharacterStream(), getSource(), and getString().
* Implementations may also change the state to not writable when this occurs.
* <p>
* The state moves from writable to not writeable once free() or any of the
* writing APIs are called: setBinaryStream(), setCharacterStream(), setResult(), and setString().
* Implementations may also change the state to not readable when this occurs.
* <p>
* <p>
* All methods on the <code>SQLXML</code> interface must be fully implemented if the
* JDBC driver supports the data type.
*
* @see javax.xml.parsers
* @see javax.xml.stream
* @see javax.xml.transform
* @see javax.xml.xpath
* @since 1.6
*/
public interface SQLXML
{
/** {@collect.stats}
* This method closes this object and releases the resources that it held.
* The SQL XML object becomes invalid and neither readable or writeable
* when this method is called.
*
* After <code>free</code> has been called, any attempt to invoke a
* method other than <code>free</code> will result in a <code>SQLException</code>
* being thrown. If <code>free</code> is called multiple times, the subsequent
* calls to <code>free</code> are treated as a no-op.
* @throws SQLException if there is an error freeing the XML value.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void free() throws SQLException;
/** {@collect.stats}
* Retrieves the XML value designated by this SQLXML instance as a stream.
* The bytes of the input stream are interpreted according to appendix F of the XML 1.0 specification.
* The behavior of this method is the same as ResultSet.getBinaryStream()
* when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
* <p>
* The SQL XML object becomes not readable when this method is called and
* may also become not writable depending on implementation.
*
* @return a stream containing the XML data.
* @throws SQLException if there is an error processing the XML value.
* An exception is thrown if the state is not readable.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
InputStream getBinaryStream() throws SQLException;
/** {@collect.stats}
* Retrieves a stream that can be used to write the XML value that this SQLXML instance represents.
* The stream begins at position 0.
* The bytes of the stream are interpreted according to appendix F of the XML 1.0 specification
* The behavior of this method is the same as ResultSet.updateBinaryStream()
* when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
* <p>
* The SQL XML object becomes not writeable when this method is called and
* may also become not readable depending on implementation.
*
* @return a stream to which data can be written.
* @throws SQLException if there is an error processing the XML value.
* An exception is thrown if the state is not writable.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
OutputStream setBinaryStream() throws SQLException;
/** {@collect.stats}
* Retrieves the XML value designated by this SQLXML instance as a java.io.Reader object.
* The format of this stream is defined by org.xml.sax.InputSource,
* where the characters in the stream represent the unicode code points for
* XML according to section 2 and appendix B of the XML 1.0 specification.
* Although an encoding declaration other than unicode may be present,
* the encoding of the stream is unicode.
* The behavior of this method is the same as ResultSet.getCharacterStream()
* when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
* <p>
* The SQL XML object becomes not readable when this method is called and
* may also become not writable depending on implementation.
*
* @return a stream containing the XML data.
* @throws SQLException if there is an error processing the XML value.
* The getCause() method of the exception may provide a more detailed exception, for example,
* if the stream does not contain valid characters.
* An exception is thrown if the state is not readable.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
Reader getCharacterStream() throws SQLException;
/** {@collect.stats}
* Retrieves a stream to be used to write the XML value that this SQLXML instance represents.
* The format of this stream is defined by org.xml.sax.InputSource,
* where the characters in the stream represent the unicode code points for
* XML according to section 2 and appendix B of the XML 1.0 specification.
* Although an encoding declaration other than unicode may be present,
* the encoding of the stream is unicode.
* The behavior of this method is the same as ResultSet.updateCharacterStream()
* when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
* <p>
* The SQL XML object becomes not writeable when this method is called and
* may also become not readable depending on implementation.
*
* @return a stream to which data can be written.
* @throws SQLException if there is an error processing the XML value.
* The getCause() method of the exception may provide a more detailed exception, for example,
* if the stream does not contain valid characters.
* An exception is thrown if the state is not writable.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
Writer setCharacterStream() throws SQLException;
/** {@collect.stats}
* Returns a string representation of the XML value designated by this SQLXML instance.
* The format of this String is defined by org.xml.sax.InputSource,
* where the characters in the stream represent the unicode code points for
* XML according to section 2 and appendix B of the XML 1.0 specification.
* Although an encoding declaration other than unicode may be present,
* the encoding of the String is unicode.
* The behavior of this method is the same as ResultSet.getString()
* when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
* <p>
* The SQL XML object becomes not readable when this method is called and
* may also become not writable depending on implementation.
*
* @return a string representation of the XML value designated by this SQLXML instance.
* @throws SQLException if there is an error processing the XML value.
* The getCause() method of the exception may provide a more detailed exception, for example,
* if the stream does not contain valid characters.
* An exception is thrown if the state is not readable.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
String getString() throws SQLException;
/** {@collect.stats}
* Sets the XML value designated by this SQLXML instance to the given String representation.
* The format of this String is defined by org.xml.sax.InputSource,
* where the characters in the stream represent the unicode code points for
* XML according to section 2 and appendix B of the XML 1.0 specification.
* Although an encoding declaration other than unicode may be present,
* the encoding of the String is unicode.
* The behavior of this method is the same as ResultSet.updateString()
* when the designated column of the ResultSet has a type java.sql.Types of SQLXML.
* <p>
* The SQL XML object becomes not writeable when this method is called and
* may also become not readable depending on implementation.
*
* @param value the XML value
* @throws SQLException if there is an error processing the XML value.
* The getCause() method of the exception may provide a more detailed exception, for example,
* if the stream does not contain valid characters.
* An exception is thrown if the state is not writable.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void setString(String value) throws SQLException;
/** {@collect.stats}
* Returns a Source for reading the XML value designated by this SQLXML instance.
* Sources are used as inputs to XML parsers and XSLT transformers.
* <p>
* Sources for XML parsers will have namespace processing on by default.
* The systemID of the Source is implementation dependent.
* <p>
* The SQL XML object becomes not readable when this method is called and
* may also become not writable depending on implementation.
* <p>
* Note that SAX is a callback architecture, so a returned
* SAXSource should then be set with a content handler that will
* receive the SAX events from parsing. The content handler
* will receive callbacks based on the contents of the XML.
* <pre>
* SAXSource saxSource = sqlxml.getSource(SAXSource.class);
* XMLReader xmlReader = saxSource.getXMLReader();
* xmlReader.setContentHandler(myHandler);
* xmlReader.parse(saxSource.getInputSource());
* </pre>
*
* @param sourceClass The class of the source, or null.
* If the class is null, a vendor specifc Source implementation will be returned.
* The following classes are supported at a minimum:
* <pre>
* javax.xml.transform.dom.DOMSource - returns a DOMSource
* javax.xml.transform.sax.SAXSource - returns a SAXSource
* javax.xml.transform.stax.StAXSource - returns a StAXSource
* javax.xml.transform.stream.StreamSource - returns a StreamSource
* </pre>
* @return a Source for reading the XML value.
* @throws SQLException if there is an error processing the XML value
* or if this feature is not supported.
* The getCause() method of the exception may provide a more detailed exception, for example,
* if an XML parser exception occurs.
* An exception is thrown if the state is not readable.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
<T extends Source> T getSource(Class<T> sourceClass) throws SQLException;
/** {@collect.stats}
* Returns a Result for setting the XML value designated by this SQLXML instance.
* <p>
* The systemID of the Result is implementation dependent.
* <p>
* The SQL XML object becomes not writeable when this method is called and
* may also become not readable depending on implementation.
* <p>
* Note that SAX is a callback architecture and the returned
* SAXResult has a content handler assigned that will receive the
* SAX events based on the contents of the XML. Call the content
* handler with the contents of the XML document to assign the values.
* <pre>
* SAXResult saxResult = sqlxml.setResult(SAXResult.class);
* ContentHandler contentHandler = saxResult.getXMLReader().getContentHandler();
* contentHandler.startDocument();
* // set the XML elements and attributes into the result
* contentHandler.endDocument();
* </pre>
*
* @param resultClass The class of the result, or null.
* If resultClass is null, a vendor specific Result implementation will be returned.
* The following classes are supported at a minimum:
* <pre>
* javax.xml.transform.dom.DOMResult - returns a DOMResult
* javax.xml.transform.sax.SAXResult - returns a SAXResult
* javax.xml.transform.stax.StAXResult - returns a StAXResult
* javax.xml.transform.stream.StreamResult - returns a StreamResult
* </pre>
* @return Returns a Result for setting the XML value.
* @throws SQLException if there is an error processing the XML value
* or if this feature is not supported.
* The getCause() method of the exception may provide a more detailed exception, for example,
* if an XML parser exception occurs.
* An exception is thrown if the state is not writable.
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
<T extends Result> T setResult(Class<T> resultClass) throws SQLException;
}
|
Java
|
/*
* Copyright (c) 1996, 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* An object that can be used to get information about the types
* and properties of the columns in a <code>ResultSet</code> object.
* The following code fragment creates the <code>ResultSet</code> object rs,
* creates the <code>ResultSetMetaData</code> object rsmd, and uses rsmd
* to find out how many columns rs has and whether the first column in rs
* can be used in a <code>WHERE</code> clause.
* <PRE>
*
* ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM TABLE2");
* ResultSetMetaData rsmd = rs.getMetaData();
* int numberOfColumns = rsmd.getColumnCount();
* boolean b = rsmd.isSearchable(1);
*
* </PRE>
*/
public interface ResultSetMetaData extends Wrapper {
/** {@collect.stats}
* Returns the number of columns in this <code>ResultSet</code> object.
*
* @return the number of columns
* @exception SQLException if a database access error occurs
*/
int getColumnCount() throws SQLException;
/** {@collect.stats}
* Indicates whether the designated column is automatically numbered.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean isAutoIncrement(int column) throws SQLException;
/** {@collect.stats}
* Indicates whether a column's case matters.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean isCaseSensitive(int column) throws SQLException;
/** {@collect.stats}
* Indicates whether the designated column can be used in a where clause.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean isSearchable(int column) throws SQLException;
/** {@collect.stats}
* Indicates whether the designated column is a cash value.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean isCurrency(int column) throws SQLException;
/** {@collect.stats}
* Indicates the nullability of values in the designated column.
*
* @param column the first column is 1, the second is 2, ...
* @return the nullability status of the given column; one of <code>columnNoNulls</code>,
* <code>columnNullable</code> or <code>columnNullableUnknown</code>
* @exception SQLException if a database access error occurs
*/
int isNullable(int column) throws SQLException;
/** {@collect.stats}
* The constant indicating that a
* column does not allow <code>NULL</code> values.
*/
int columnNoNulls = 0;
/** {@collect.stats}
* The constant indicating that a
* column allows <code>NULL</code> values.
*/
int columnNullable = 1;
/** {@collect.stats}
* The constant indicating that the
* nullability of a column's values is unknown.
*/
int columnNullableUnknown = 2;
/** {@collect.stats}
* Indicates whether values in the designated column are signed numbers.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean isSigned(int column) throws SQLException;
/** {@collect.stats}
* Indicates the designated column's normal maximum width in characters.
*
* @param column the first column is 1, the second is 2, ...
* @return the normal maximum number of characters allowed as the width
* of the designated column
* @exception SQLException if a database access error occurs
*/
int getColumnDisplaySize(int column) throws SQLException;
/** {@collect.stats}
* Gets the designated column's suggested title for use in printouts and
* displays. The suggested title is usually specified by the SQL <code>AS</code>
* clause. If a SQL <code>AS</code> is not specified, the value returned from
* <code>getColumnLabel</code> will be the same as the value returned by the
* <code>getColumnName</code> method.
*
* @param column the first column is 1, the second is 2, ...
* @return the suggested column title
* @exception SQLException if a database access error occurs
*/
String getColumnLabel(int column) throws SQLException;
/** {@collect.stats}
* Get the designated column's name.
*
* @param column the first column is 1, the second is 2, ...
* @return column name
* @exception SQLException if a database access error occurs
*/
String getColumnName(int column) throws SQLException;
/** {@collect.stats}
* Get the designated column's table's schema.
*
* @param column the first column is 1, the second is 2, ...
* @return schema name or "" if not applicable
* @exception SQLException if a database access error occurs
*/
String getSchemaName(int column) throws SQLException;
/** {@collect.stats}
* Get the designated column's specified column size.
* For numeric data, this is the maximum precision. For character data, this is the length in characters.
* For datetime datatypes, this is the length in characters of the String representation (assuming the
* maximum allowed precision of the fractional seconds component). For binary data, this is the length in bytes. For the ROWID datatype,
* this is the length in bytes. 0 is returned for data types where the
* column size is not applicable.
*
* @param column the first column is 1, the second is 2, ...
* @return precision
* @exception SQLException if a database access error occurs
*/
int getPrecision(int column) throws SQLException;
/** {@collect.stats}
* Gets the designated column's number of digits to right of the decimal point.
* 0 is returned for data types where the scale is not applicable.
*
* @param column the first column is 1, the second is 2, ...
* @return scale
* @exception SQLException if a database access error occurs
*/
int getScale(int column) throws SQLException;
/** {@collect.stats}
* Gets the designated column's table name.
*
* @param column the first column is 1, the second is 2, ...
* @return table name or "" if not applicable
* @exception SQLException if a database access error occurs
*/
String getTableName(int column) throws SQLException;
/** {@collect.stats}
* Gets the designated column's table's catalog name.
*
* @param column the first column is 1, the second is 2, ...
* @return the name of the catalog for the table in which the given column
* appears or "" if not applicable
* @exception SQLException if a database access error occurs
*/
String getCatalogName(int column) throws SQLException;
/** {@collect.stats}
* Retrieves the designated column's SQL type.
*
* @param column the first column is 1, the second is 2, ...
* @return SQL type from java.sql.Types
* @exception SQLException if a database access error occurs
* @see Types
*/
int getColumnType(int column) throws SQLException;
/** {@collect.stats}
* Retrieves the designated column's database-specific type name.
*
* @param column the first column is 1, the second is 2, ...
* @return type name used by the database. If the column type is
* a user-defined type, then a fully-qualified type name is returned.
* @exception SQLException if a database access error occurs
*/
String getColumnTypeName(int column) throws SQLException;
/** {@collect.stats}
* Indicates whether the designated column is definitely not writable.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean isReadOnly(int column) throws SQLException;
/** {@collect.stats}
* Indicates whether it is possible for a write on the designated column to succeed.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean isWritable(int column) throws SQLException;
/** {@collect.stats}
* Indicates whether a write on the designated column will definitely succeed.
*
* @param column the first column is 1, the second is 2, ...
* @return <code>true</code> if so; <code>false</code> otherwise
* @exception SQLException if a database access error occurs
*/
boolean isDefinitelyWritable(int column) throws SQLException;
//--------------------------JDBC 2.0-----------------------------------
/** {@collect.stats}
* <p>Returns the fully-qualified name of the Java class whose instances
* are manufactured if the method <code>ResultSet.getObject</code>
* is called to retrieve a value
* from the column. <code>ResultSet.getObject</code> may return a subclass of the
* class returned by this method.
*
* @param column the first column is 1, the second is 2, ...
* @return the fully-qualified name of the class in the Java programming
* language that would be used by the method
* <code>ResultSet.getObject</code> to retrieve the value in the specified
* column. This is the class name used for custom mapping.
* @exception SQLException if a database access error occurs
* @since 1.2
*/
String getColumnClassName(int column) throws SQLException;
}
|
Java
|
/*
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
import java.util.*;
/** {@collect.stats}
* Enumeration for RowId life-time values.
*
* @since 1.6
*/
public enum RowIdLifetime {
/** {@collect.stats}
* Indicates that this data source does not support the ROWID type.
*/
ROWID_UNSUPPORTED,
/** {@collect.stats}
* Indicates that the lifetime of a RowId from this data source is indeterminate;
* but not one of ROWID_VALID_TRANSACTION, ROWID_VALID_SESSION, or,
* ROWID_VALID_FOREVER.
*/
ROWID_VALID_OTHER,
/** {@collect.stats}
* Indicates that the lifetime of a RowId from this data source is at least the
* containing session.
*/
ROWID_VALID_SESSION,
/** {@collect.stats}
* Indicates that the lifetime of a RowId from this data source is at least the
* containing transaction.
*/
ROWID_VALID_TRANSACTION,
/** {@collect.stats}
* Indicates that the lifetime of a RowId from this data source is, effectively,
* unlimited.
*/
ROWID_VALID_FOREVER
}
|
Java
|
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
import java.util.Map;
/** {@collect.stats}
* The subclass of {@link SQLException} is thrown when one or more client info properties
* could not be set on a <code>Connection</code>. In addition to the information provided
* by <code>SQLException</code>, a <code>SQLClientInfoException</code> provides a list of client info
* properties that were not set.
*
* Some databases do not allow multiple client info properties to be set
* atomically. For those databases, it is possible that some of the client
* info properties had been set even though the <code>Connection.setClientInfo</code>
* method threw an exception. An application can use the <code>getFailedProperties </code>
* method to retrieve a list of client info properties that were not set. The
* properties are identified by passing a
* <code>Map<String,ClientInfoStatus></code> to
* the appropriate <code>SQLClientInfoException</code> constructor.
* <p>
* @see ClientInfoStatus
* @see Connection#setClientInfo
* @since 1.6
*/
public class SQLClientInfoException extends SQLException {
private Map<String, ClientInfoStatus> failedProperties;
/** {@collect.stats}
* Constructs a <code>SQLClientInfoException</code> Object.
* The <code>reason</code>,
* <code>SQLState</code>, and failedProperties list are initialized to
* <code> null</code> and the vendor code is initialized to 0.
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
*
* @since 1.6
*/
public SQLClientInfoException() {
this.failedProperties = null;
}
/** {@collect.stats}
* Constructs a <code>SQLClientInfoException</code> object initialized with a
* given <code>failedProperties</code>.
* The <code>reason</code> and <code>SQLState</code> are initialized
* to <code>null</code> and the vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
*
* @param failedProperties A Map containing the property values that could not
* be set. The keys in the Map
* contain the names of the client info
* properties that could not be set and
* the values contain one of the reason codes
* defined in <code>ClientInfoStatus</code>
* <p>
* @since 1.6
*/
public SQLClientInfoException(Map<String, ClientInfoStatus> failedProperties) {
this.failedProperties = failedProperties;
}
/** {@collect.stats}
* Constructs a <code>SQLClientInfoException</code> object initialized with
* a given <code>cause</code> and <code>failedProperties</code>.
*
* The <code>reason</code> is initialized to <code>null</code> if
* <code>cause==null</code> or to <code>cause.toString()</code> if
* <code>cause!=null</code> and the vendor code is initialized to 0.
*
* <p>
*
* @param failedProperties A Map containing the property values that could not
* be set. The keys in the Map
* contain the names of the client info
* properties that could not be set and
* the values contain one of the reason codes
* defined in <code>ClientInfoStatus</code>
* @param cause the (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* <p>
* @since 1.6
*/
public SQLClientInfoException(Map<String, ClientInfoStatus> failedProperties,
Throwable cause) {
super(cause != null?cause.toString():null);
initCause(cause);
this.failedProperties = failedProperties;
}
/** {@collect.stats}
* Constructs a <code>SQLClientInfoException</code> object initialized with a
* given <code>reason</code> and <code>failedProperties</code>.
* The <code>SQLState</code> is initialized
* to <code>null</code> and the vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
*
* @param reason a description of the exception
* @param failedProperties A Map containing the property values that could not
* be set. The keys in the Map
* contain the names of the client info
* properties that could not be set and
* the values contain one of the reason codes
* defined in <code>ClientInfoStatus</code>
* <p>
* @since 1.6
*/
public SQLClientInfoException(String reason,
Map<String, ClientInfoStatus> failedProperties) {
super(reason);
this.failedProperties = failedProperties;
}
/** {@collect.stats}
* Constructs a <code>SQLClientInfoException</code> object initialized with a
* given <code>reason</code>, <code>cause</code> and
* <code>failedProperties</code>.
* The <code>SQLState</code> is initialized
* to <code>null</code> and the vendor code is initialized to 0.
* <p>
*
* @param reason a description of the exception
* @param failedProperties A Map containing the property values that could not
* be set. The keys in the Map
* contain the names of the client info
* properties that could not be set and
* the values contain one of the reason codes
* defined in <code>ClientInfoStatus</code>
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* <p>
* @since 1.6
*/
public SQLClientInfoException(String reason,
Map<String, ClientInfoStatus> failedProperties,
Throwable cause) {
super(reason);
initCause(cause);
this.failedProperties = failedProperties;
}
/** {@collect.stats}
* Constructs a <code>SQLClientInfoException</code> object initialized with a
* given <code>reason</code>, <code>SQLState</code> and
* <code>failedProperties</code>.
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
* is initialized to 0.
* <p>
*
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param failedProperties A Map containing the property values that could not
* be set. The keys in the Map
* contain the names of the client info
* properties that could not be set and
* the values contain one of the reason codes
* defined in <code>ClientInfoStatus</code>
* <p>
* @since 1.6
*/
public SQLClientInfoException(String reason,
String SQLState,
Map<String, ClientInfoStatus> failedProperties) {
super(reason, SQLState);
this.failedProperties = failedProperties;
}
/** {@collect.stats}
* Constructs a <code>SQLClientInfoException</code> object initialized with a
* given <code>reason</code>, <code>SQLState</code>, <code>cause</code>
* and <code>failedProperties</code>. The vendor code is initialized to 0.
* <p>
*
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param failedProperties A Map containing the property values that could not
* be set. The keys in the Map
* contain the names of the client info
* properties that could not be set and
* the values contain one of the reason codes
* defined in <code>ClientInfoStatus</code>
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* <p>
* @since 1.6
*/
public SQLClientInfoException(String reason,
String SQLState,
Map<String, ClientInfoStatus> failedProperties,
Throwable cause) {
super(reason, SQLState);
initCause(cause);
this.failedProperties = failedProperties;
}
/** {@collect.stats}
* Constructs a <code>SQLClientInfoException</code> object initialized with a
* given <code>reason</code>, <code>SQLState</code>,
* <code>vendorCode</code> and <code>failedProperties</code>.
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
*
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor-specific exception code
* @param failedProperties A Map containing the property values that could not
* be set. The keys in the Map
* contain the names of the client info
* properties that could not be set and
* the values contain one of the reason codes
* defined in <code>ClientInfoStatus</code>
* <p>
* @since 1.6
*/
public SQLClientInfoException(String reason,
String SQLState,
int vendorCode,
Map<String, ClientInfoStatus> failedProperties) {
super(reason, SQLState, vendorCode);
this.failedProperties = failedProperties;
}
/** {@collect.stats}
* Constructs a <code>SQLClientInfoException</code> object initialized with a
* given <code>reason</code>, <code>SQLState</code>,
* <code>cause</code>, <code>vendorCode</code> and
* <code>failedProperties</code>.
* <p>
*
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor-specific exception code
* @param failedProperties A Map containing the property values that could not
* be set. The keys in the Map
* contain the names of the client info
* properties that could not be set and
* the values contain one of the reason codes
* defined in <code>ClientInfoStatus</code>
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* <p>
* @since 1.6
*/
public SQLClientInfoException(String reason,
String SQLState,
int vendorCode,
Map<String, ClientInfoStatus> failedProperties,
Throwable cause) {
super(reason, SQLState, vendorCode);
initCause(cause);
this.failedProperties = failedProperties;
}
/** {@collect.stats}
* Returns the list of client info properties that could not be set. The
* keys in the Map contain the names of the client info
* properties that could not be set and the values contain one of the
* reason codes defined in <code>ClientInfoStatus</code>
* <p>
*
* @return Map list containing the client info properties that could
* not be set
* <p>
* @since 1.6
*/
public Map<String, ClientInfoStatus> getFailedProperties() {
return this.failedProperties;
}
private static final long serialVersionUID = -4319604256824655880L;
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* <P>A thin wrapper around a millisecond value that allows
* JDBC to identify this as an SQL <code>DATE</code> value. A
* milliseconds value represents the number of milliseconds that
* have passed since January 1, 1970 00:00:00.000 GMT.
* <p>
* To conform with the definition of SQL <code>DATE</code>, the
* millisecond values wrapped by a <code>java.sql.Date</code> instance
* must be 'normalized' by setting the
* hours, minutes, seconds, and milliseconds to zero in the particular
* time zone with which the instance is associated.
*/
public class Date extends java.util.Date {
/** {@collect.stats}
* Constructs a <code>Date</code> object initialized with the given
* year, month, and day.
* <P>
* The result is undefined if a given argument is out of bounds.
*
* @param year the year minus 1900; must be 0 to 8099. (Note that
* 8099 is 9999 minus 1900.)
* @param month 0 to 11
* @param day 1 to 31
* @deprecated instead use the constructor <code>Date(long date)</code>
*/
public Date(int year, int month, int day) {
super(year, month, day);
}
/** {@collect.stats}
* Constructs a <code>Date</code> object using the given milliseconds
* time value. If the given milliseconds value contains time
* information, the driver will set the time components to the
* time in the default time zone (the time zone of the Java virtual
* machine running the application) that corresponds to zero GMT.
*
* @param date milliseconds since January 1, 1970, 00:00:00 GMT not
* to exceed the milliseconds representation for the year 8099.
* A negative number indicates the number of milliseconds
* before January 1, 1970, 00:00:00 GMT.
*/
public Date(long date) {
// If the millisecond date value contains time info, mask it out.
super(date);
}
/** {@collect.stats}
* Sets an existing <code>Date</code> object
* using the given milliseconds time value.
* If the given milliseconds value contains time information,
* the driver will set the time components to the
* time in the default time zone (the time zone of the Java virtual
* machine running the application) that corresponds to zero GMT.
*
* @param date milliseconds since January 1, 1970, 00:00:00 GMT not
* to exceed the milliseconds representation for the year 8099.
* A negative number indicates the number of milliseconds
* before January 1, 1970, 00:00:00 GMT.
*/
public void setTime(long date) {
// If the millisecond date value contains time info, mask it out.
super.setTime(date);
}
/** {@collect.stats}
* Converts a string in JDBC date escape format to
* a <code>Date</code> value.
*
* @param s a <code>String</code> object representing a date in
* in the format "yyyy-mm-dd"
* @return a <code>java.sql.Date</code> object representing the
* given date
* @throws IllegalArgumentException if the date given is not in the
* JDBC date escape format (yyyy-mm-dd)
*/
public static Date valueOf(String s) {
int year;
int month;
int day;
int firstDash;
int secondDash;
if (s == null) throw new java.lang.IllegalArgumentException();
firstDash = s.indexOf('-');
secondDash = s.indexOf('-', firstDash+1);
if ((firstDash > 0) & (secondDash > 0) & (secondDash < s.length()-1)) {
year = Integer.parseInt(s.substring(0, firstDash)) - 1900;
month = Integer.parseInt(s.substring(firstDash+1, secondDash)) - 1;
day = Integer.parseInt(s.substring(secondDash+1));
} else {
throw new java.lang.IllegalArgumentException();
}
return new Date(year, month, day);
}
/** {@collect.stats}
* Formats a date in the date escape format yyyy-mm-dd.
* <P>
* @return a String in yyyy-mm-dd format
*/
public String toString () {
int year = super.getYear() + 1900;
int month = super.getMonth() + 1;
int day = super.getDate();
char buf[] = "2000-00-00".toCharArray();
buf[0] = Character.forDigit(year/1000,10);
buf[1] = Character.forDigit((year/100)%10,10);
buf[2] = Character.forDigit((year/10)%10,10);
buf[3] = Character.forDigit(year%10,10);
buf[5] = Character.forDigit(month/10,10);
buf[6] = Character.forDigit(month%10,10);
buf[8] = Character.forDigit(day/10,10);
buf[9] = Character.forDigit(day%10,10);
return new String(buf);
}
// Override all the time operations inherited from java.util.Date;
/** {@collect.stats}
* This method is deprecated and should not be used because SQL Date
* values do not have a time component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this method is invoked
* @see #setHours
*/
public int getHours() {
throw new java.lang.IllegalArgumentException();
}
/** {@collect.stats}
* This method is deprecated and should not be used because SQL Date
* values do not have a time component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this method is invoked
* @see #setMinutes
*/
public int getMinutes() {
throw new java.lang.IllegalArgumentException();
}
/** {@collect.stats}
* This method is deprecated and should not be used because SQL Date
* values do not have a time component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this method is invoked
* @see #setSeconds
*/
public int getSeconds() {
throw new java.lang.IllegalArgumentException();
}
/** {@collect.stats}
* This method is deprecated and should not be used because SQL Date
* values do not have a time component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this method is invoked
* @see #getHours
*/
public void setHours(int i) {
throw new java.lang.IllegalArgumentException();
}
/** {@collect.stats}
* This method is deprecated and should not be used because SQL Date
* values do not have a time component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this method is invoked
* @see #getMinutes
*/
public void setMinutes(int i) {
throw new java.lang.IllegalArgumentException();
}
/** {@collect.stats}
* This method is deprecated and should not be used because SQL Date
* values do not have a time component.
*
* @deprecated
* @exception java.lang.IllegalArgumentException if this method is invoked
* @see #getSeconds
*/
public void setSeconds(int i) {
throw new java.lang.IllegalArgumentException();
}
/** {@collect.stats}
* Private serial version unique ID to ensure serialization
* compatibility.
*/
static final long serialVersionUID = 1511598038487230103L;
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* <P>The class that defines the constants that are used to identify generic
* SQL types, called JDBC types.
* <p>
* This class is never instantiated.
*/
public class Types {
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>BIT</code>.
*/
public final static int BIT = -7;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>TINYINT</code>.
*/
public final static int TINYINT = -6;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>SMALLINT</code>.
*/
public final static int SMALLINT = 5;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>INTEGER</code>.
*/
public final static int INTEGER = 4;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>BIGINT</code>.
*/
public final static int BIGINT = -5;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>FLOAT</code>.
*/
public final static int FLOAT = 6;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>REAL</code>.
*/
public final static int REAL = 7;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>DOUBLE</code>.
*/
public final static int DOUBLE = 8;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>NUMERIC</code>.
*/
public final static int NUMERIC = 2;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>DECIMAL</code>.
*/
public final static int DECIMAL = 3;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>CHAR</code>.
*/
public final static int CHAR = 1;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>VARCHAR</code>.
*/
public final static int VARCHAR = 12;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>LONGVARCHAR</code>.
*/
public final static int LONGVARCHAR = -1;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>DATE</code>.
*/
public final static int DATE = 91;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>TIME</code>.
*/
public final static int TIME = 92;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>TIMESTAMP</code>.
*/
public final static int TIMESTAMP = 93;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>BINARY</code>.
*/
public final static int BINARY = -2;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>VARBINARY</code>.
*/
public final static int VARBINARY = -3;
/** {@collect.stats}
* <P>The constant in the Java programming language, sometimes referred
* to as a type code, that identifies the generic SQL type
* <code>LONGVARBINARY</code>.
*/
public final static int LONGVARBINARY = -4;
/** {@collect.stats}
* <P>The constant in the Java programming language
* that identifies the generic SQL value
* <code>NULL</code>.
*/
public final static int NULL = 0;
/** {@collect.stats}
* The constant in the Java programming language that indicates
* that the SQL type is database-specific and
* gets mapped to a Java object that can be accessed via
* the methods <code>getObject</code> and <code>setObject</code>.
*/
public final static int OTHER = 1111;
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type
* <code>JAVA_OBJECT</code>.
* @since 1.2
*/
public final static int JAVA_OBJECT = 2000;
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type
* <code>DISTINCT</code>.
* @since 1.2
*/
public final static int DISTINCT = 2001;
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type
* <code>STRUCT</code>.
* @since 1.2
*/
public final static int STRUCT = 2002;
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type
* <code>ARRAY</code>.
* @since 1.2
*/
public final static int ARRAY = 2003;
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type
* <code>BLOB</code>.
* @since 1.2
*/
public final static int BLOB = 2004;
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type
* <code>CLOB</code>.
* @since 1.2
*/
public final static int CLOB = 2005;
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type
* <code>REF</code>.
* @since 1.2
*/
public final static int REF = 2006;
/** {@collect.stats}
* The constant in the Java programming language, somtimes referred to
* as a type code, that identifies the generic SQL type <code>DATALINK</code>.
*
* @since 1.4
*/
public final static int DATALINK = 70;
/** {@collect.stats}
* The constant in the Java programming language, somtimes referred to
* as a type code, that identifies the generic SQL type <code>BOOLEAN</code>.
*
* @since 1.4
*/
public final static int BOOLEAN = 16;
//------------------------- JDBC 4.0 -----------------------------------
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type <code>ROWID</code>
*
* @since 1.6
*
*/
public final static int ROWID = -8;
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type <code>NCHAR</code>
*
* @since 1.6
*/
public static final int NCHAR = -15;
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type <code>NVARCHAR</code>.
*
* @since 1.6
*/
public static final int NVARCHAR = -9;
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type <code>LONGNVARCHAR</code>.
*
* @since 1.6
*/
public static final int LONGNVARCHAR = -16;
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type <code>NCLOB</code>.
*
* @since 1.6
*/
public static final int NCLOB = 2011;
/** {@collect.stats}
* The constant in the Java programming language, sometimes referred to
* as a type code, that identifies the generic SQL type <code>XML</code>.
*
* @since 1.6
*/
public static final int SQLXML = 2009;
// Prevent instantiation
private Types() {}
}
|
Java
|
/*
* Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* <P>An exception that provides information on database access
* warnings. Warnings are silently chained to the object whose method
* caused it to be reported.
* <P>
* Warnings may be retrieved from <code>Connection</code>, <code>Statement</code>,
* and <code>ResultSet</code> objects. Trying to retrieve a warning on a
* connection after it has been closed will cause an exception to be thrown.
* Similarly, trying to retrieve a warning on a statement after it has been
* closed or on a result set after it has been closed will cause
* an exception to be thrown. Note that closing a statement also
* closes a result set that it might have produced.
*
* @see Connection#getWarnings
* @see Statement#getWarnings
* @see ResultSet#getWarnings
*/
public class SQLWarning extends SQLException {
/** {@collect.stats}
* Constructs a <code>SQLWarning</code> object
* with a given <code>reason</code>, <code>SQLState</code> and
* <code>vendorCode</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the warning
* @param SQLState an XOPEN or SQL:2003 code identifying the warning
* @param vendorCode a database vendor-specific warning code
*/
public SQLWarning(String reason, String SQLState, int vendorCode) {
super(reason, SQLState, vendorCode);
DriverManager.println("SQLWarning: reason(" + reason +
") SQLState(" + SQLState +
") vendor code(" + vendorCode + ")");
}
/** {@collect.stats}
* Constructs a <code>SQLWarning</code> object
* with a given <code>reason</code> and <code>SQLState</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
* is initialized to 0.
* <p>
* @param reason a description of the warning
* @param SQLState an XOPEN or SQL:2003 code identifying the warning
*/
public SQLWarning(String reason, String SQLState) {
super(reason, SQLState);
DriverManager.println("SQLWarning: reason(" + reason +
") SQLState(" + SQLState + ")");
}
/** {@collect.stats}
* Constructs a <code>SQLWarning</code> object
* with a given <code>reason</code>. The <code>SQLState</code>
* is initialized to <code>null</code> and the vender code is initialized
* to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the warning
*/
public SQLWarning(String reason) {
super(reason);
DriverManager.println("SQLWarning: reason(" + reason + ")");
}
/** {@collect.stats}
* Constructs a <code>SQLWarning</code> object.
* The <code>reason</code>, <code>SQLState</code> are initialized
* to <code>null</code> and the vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
*/
public SQLWarning() {
super();
DriverManager.println("SQLWarning: ");
}
/** {@collect.stats}
* Constructs a <code>SQLWarning</code> object
* with a given <code>cause</code>.
* The <code>SQLState</code> is initialized
* to <code>null</code> and the vendor code is initialized to 0.
* The <code>reason</code> is initialized to <code>null</code> if
* <code>cause==null</code> or to <code>cause.toString()</code> if
* <code>cause!=null</code>.
* <p>
* @param cause the underlying reason for this <code>SQLWarning</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
*/
public SQLWarning(Throwable cause) {
super(cause);
DriverManager.println("SQLWarning");
}
/** {@collect.stats}
* Constructs a <code>SQLWarning</code> object
* with a given
* <code>reason</code> and <code>cause</code>.
* The <code>SQLState</code> is initialized to <code>null</code>
* and the vendor code is initialized to 0.
* <p>
* @param reason a description of the warning
* @param cause the underlying reason for this <code>SQLWarning</code>
* (which is saved for later retrieval by the <code>getCause()</code> method);
* may be null indicating the cause is non-existent or unknown.
*/
public SQLWarning(String reason, Throwable cause) {
super(reason,cause);
DriverManager.println("SQLWarning : reason("+ reason + ")");
}
/** {@collect.stats}
* Constructs a <code>SQLWarning</code> object
* with a given
* <code>reason</code>, <code>SQLState</code> and <code>cause</code>.
* The vendor code is initialized to 0.
* <p>
* @param reason a description of the warning
* @param SQLState an XOPEN or SQL:2003 code identifying the warning
* @param cause the underlying reason for this <code>SQLWarning</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
*/
public SQLWarning(String reason, String SQLState, Throwable cause) {
super(reason,SQLState,cause);
DriverManager.println("SQLWarning: reason(" + reason +
") SQLState(" + SQLState + ")");
}
/** {@collect.stats}
* Constructs a<code>SQLWarning</code> object
* with a given
* <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
* and <code>cause</code>.
* <p>
* @param reason a description of the warning
* @param SQLState an XOPEN or SQL:2003 code identifying the warning
* @param vendorCode a database vendor-specific warning code
* @param cause the underlying reason for this <code>SQLWarning</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
*/
public SQLWarning(String reason, String SQLState, int vendorCode, Throwable cause) {
super(reason,SQLState,vendorCode,cause);
DriverManager.println("SQLWarning: reason(" + reason +
") SQLState(" + SQLState +
") vendor code(" + vendorCode + ")");
}
/** {@collect.stats}
* Retrieves the warning chained to this <code>SQLWarning</code> object by
* <code>setNextWarning</code>.
*
* @return the next <code>SQLException</code> in the chain; <code>null</code> if none
* @see #setNextWarning
*/
public SQLWarning getNextWarning() {
try {
return ((SQLWarning)getNextException());
} catch (ClassCastException ex) {
// The chained value isn't a SQLWarning.
// This is a programming error by whoever added it to
// the SQLWarning chain. We throw a Java "Error".
throw new Error("SQLWarning chain holds value that is not a SQLWarning");
}
}
/** {@collect.stats}
* Adds a <code>SQLWarning</code> object to the end of the chain.
*
* @param w the new end of the <code>SQLException</code> chain
* @see #getNextWarning
*/
public void setNextWarning(SQLWarning w) {
setNextException(w);
}
private static final long serialVersionUID = 3917336774604784856L;
}
|
Java
|
/*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* The subclass of {@link SQLException} thrown in situations where a
* previously failed operation might be able to succeed if the application performs
* some recovery steps and retries the entire transaction or in the case of a
* distributed transaction, the transaction branch. At a minimum,
* the recovery operation must include closing the current connection and getting
* a new connection.
*<p>
*
* @since 1.6
*/
public class SQLRecoverableException extends java.sql.SQLException {
/** {@collect.stats}
* Constructs a <code>SQLRecoverableException</code> object.
* The <code>reason</code>, <code>SQLState</code> are initialized
* to <code>null</code> and the vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @since 1.6
*/
public SQLRecoverableException() {
super();
}
/** {@collect.stats}
* Constructs a <code>SQLRecoverableException</code> object
* with a given <code>reason</code>. The <code>SQLState</code>
* is initialized to <code>null</code> and the vender code is initialized
* to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @since 1.6
*/
public SQLRecoverableException(String reason) {
super(reason);
}
/** {@collect.stats}
* Constructs a <code>SQLRecoverableException</code> object
* with a given <code>reason</code> and <code>SQLState</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
* is initialized to 0.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @since 1.6
*/
public SQLRecoverableException(String reason, String SQLState) {
super(reason, SQLState);
}
/** {@collect.stats}
* Constructs a <code>SQLRecoverableException</code> object
* with a given <code>reason</code>, <code>SQLState</code> and
* <code>vendorCode</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor specific exception code
* @since 1.6
*/
public SQLRecoverableException(String reason, String SQLState, int vendorCode) {
super(reason, SQLState, vendorCode);
}
/** {@collect.stats}
* Constructs a <code>SQLRecoverableException</code> object
* with a given <code>cause</code>.
* The <code>SQLState</code> is initialized
* to <code>null</code> and the vendor code is initialized to 0.
* The <code>reason</code> is initialized to <code>null</code> if
* <code>cause==null</code> or to <code>cause.toString()</code> if
* <code>cause!=null</code>.
* <p>
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLRecoverableException(Throwable cause) {
super(cause);
}
/** {@collect.stats}
* Constructs a <code>SQLRecoverableException</code> object
* with a given
* <code>reason</code> and <code>cause</code>.
* The <code>SQLState</code> is initialized to <code>null</code>
* and the vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLRecoverableException(String reason, Throwable cause) {
super(reason, cause);
}
/** {@collect.stats}
* Constructs a <code>SQLRecoverableException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code> and <code>cause</code>.
* The vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLRecoverableException(String reason, String SQLState, Throwable cause) {
super(reason, SQLState, cause);
}
/** {@collect.stats}
* Constructs a <code>SQLRecoverableException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
* and <code>cause</code>.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor-specific exception code
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLRecoverableException(String reason, String SQLState, int vendorCode, Throwable cause) {
super(reason, SQLState, vendorCode, cause);
}
private static final long serialVersionUID = -4144386502923131579L;
}
|
Java
|
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
*
* The representation (mapping) in the Java programming language of an SQL ROWID
* value. An SQL ROWID is a built-in type, a value of which can be thought of as
* an address for its identified row in a database table. Whether that address
* is logical or, in any respects, physical is determined by its originating data
* source.
* <p>
* Methods in the interfaces <code>ResultSet</code>, <code>CallableStatement</code>,
* and <code>PreparedStatement</code>, such as <code>getRowId</code> and <code>setRowId</code>
* allow a programmer to access a SQL <code>ROWID</code> value. The <code>RowId</code>
* interface provides a method
* for representing the value of the <code>ROWID</code> as a byte array or as a
* <code>String</code>.
* <p>
* The method <code>getRowIdLifetime</code> in the interface <code>DatabaseMetaData</code>,
* can be used
* to determine if a <code>RowId</code> object remains valid for the duration of the transaction in
* which the <code>RowId</code> was created, the duration of the session in which
* the <code>RowId</code> was created,
* or, effectively, for as long as its identified row is not deleted. In addition
* to specifying the duration of its valid lifetime outside its originating data
* source, <code>getRowIdLifetime</code> specifies the duration of a <code>ROWID</code>
* value's valid lifetime
* within its originating data source. In this, it differs from a large object,
* because there is no limit on the valid lifetime of a large object within its
* originating data source.
* <p>
* All methods on the <code>RowId</code> interface must be fully implemented if the
* JDBC driver supports the data type.
*
* @see java.sql.DatabaseMetaData
* @since 1.6
*/
public interface RowId {
/** {@collect.stats}
* Compares this <code>RowId</code> to the specified object. The result is
* <code>true</code> if and only if the argument is not null and is a RowId
* object that represents the same ROWID as this object.
* <p>
* It is important
* to consider both the origin and the valid lifetime of a <code>RowId</code>
* when comparing it to another <code>RowId</code>. If both are valid, and
* both are from the same table on the same data source, then if they are equal
* they identify
* the same row; if one or more is no longer guaranteed to be valid, or if
* they originate from different data sources, or different tables on the
* same data source, they may be equal but still
* not identify the same row.
*
* @param obj the <code>Object</code> to compare this <code>RowId</code> object
* against.
* @return true if the <code>RowId</code>s are equal; false otherwise
* @since 1.6
*/
boolean equals(Object obj);
/** {@collect.stats}
* Returns an array of bytes representing the value of the SQL <code>ROWID</code>
* designated by this <code>java.sql.RowId</code> object.
*
* @return an array of bytes, whose length is determined by the driver supplying
* the connection, representing the value of the ROWID designated by this
* java.sql.RowId object.
*/
byte[] getBytes();
/** {@collect.stats}
* Returns a String representing the value of the SQL ROWID designated by this
* <code>java.sql.RowId</code> object.
* <p>
*Like <code>java.sql.Date.toString()</code>
* returns the contents of its DATE as the <code>String</code> "2004-03-17"
* rather than as DATE literal in SQL (which would have been the <code>String</code>
* DATE "2004-03-17"), toString()
* returns the contents of its ROWID in a form specific to the driver supplying
* the connection, and possibly not as a <code>ROWID</code> literal.
*
* @return a String whose format is determined by the driver supplying the
* connection, representing the value of the <code>ROWID</code> designated
* by this <code>java.sql.RowId</code> object.
*/
String toString();
/** {@collect.stats}
* Returns a hash code value of this <code>RowId</code> object.
*
* @return a hash code for the <code>RowId</code>
*/
int hashCode();
}
|
Java
|
/*
* Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* The subclass of {@link SQLException} for the SQLState class
* value '<i>08</i>', representing
* that the connection operation that failed might be able to succeed when
* the operation is retried without any application-level changes.
*<p>
*
* @since 1.6
*/
public class SQLTransientConnectionException extends java.sql.SQLTransientException {
/** {@collect.stats}
* Constructs a <code>SQLTransientConnectionException</code> object.
* The <code>reason</code>, <code>SQLState</code> are initialized
* to <code>null</code> and the vendor code is initialized to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @since 1.6
*/
public SQLTransientConnectionException() {
super();
}
/** {@collect.stats}
* Constructs a <code>SQLTransientConnectionException</code> object
* with a given <code>reason</code>. The <code>SQLState</code>
* is initialized to <code>null</code> and the vender code is initialized
* to 0.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @since 1.6
*/
public SQLTransientConnectionException(String reason) {
super(reason);
}
/** {@collect.stats}
* Constructs a <code>SQLTransientConnectionException</code> object
* with a given <code>reason</code> and <code>SQLState</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method. The vendor code
* is initialized to 0.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @since 1.6
*/
public SQLTransientConnectionException(String reason, String SQLState) {
super(reason,SQLState);
}
/** {@collect.stats}
* Constructs a <code>SQLTransientConnectionException</code> object
* with a given <code>reason</code>, <code>SQLState</code> and
* <code>vendorCode</code>.
*
* The <code>cause</code> is not initialized, and may subsequently be
* initialized by a call to the
* {@link Throwable#initCause(java.lang.Throwable)} method.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor specific exception code
* @since 1.6
*/
public SQLTransientConnectionException(String reason, String SQLState, int vendorCode) {
super(reason,SQLState,vendorCode);
}
/** {@collect.stats}
* Constructs a <code>SQLTransientConnectionException</code> object
* with a given <code>cause</code>.
* The <code>SQLState</code> is initialized
* to <code>null</code> and the vendor code is initialized to 0.
* The <code>reason</code> is initialized to <code>null</code> if
* <code>cause==null</code> or to <code>cause.toString()</code> if
* <code>cause!=null</code>.
* <p>
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLTransientConnectionException(Throwable cause) {
super(cause);
}
/** {@collect.stats}
* Constructs a <code>SQLTransientConnectionException</code> object
* with a given
* <code>reason</code> and <code>cause</code>.
* The <code>SQLState</code> is initialized to <code>null</code>
* and the vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param cause the underlying reason for this <code>SQLException</code>(which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLTransientConnectionException(String reason, Throwable cause) {
super(reason,cause);
}
/** {@collect.stats}
* Constructs a <code>SQLTransientConnectionException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code> and <code>cause</code>.
* The vendor code is initialized to 0.
* <p>
* @param reason a description of the exception.
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLTransientConnectionException(String reason, String SQLState, Throwable cause) {
super(reason,SQLState,cause);
}
/** {@collect.stats}
* Constructs a <code>SQLTransientConnectionException</code> object
* with a given
* <code>reason</code>, <code>SQLState</code>, <code>vendorCode</code>
* and <code>cause</code>.
* <p>
* @param reason a description of the exception
* @param SQLState an XOPEN or SQL:2003 code identifying the exception
* @param vendorCode a database vendor-specific exception code
* @param cause the underlying reason for this <code>SQLException</code> (which is saved for later retrieval by the <code>getCause()</code> method); may be null indicating
* the cause is non-existent or unknown.
* @since 1.6
*/
public SQLTransientConnectionException(String reason, String SQLState, int vendorCode, Throwable cause) {
super(reason,SQLState,vendorCode,cause);
}
private static final long serialVersionUID = -2520155553543391200L;
}
|
Java
|
/*
* Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* The mapping in the Java programming language for the SQL type
* <code>ARRAY</code>.
* By default, an <code>Array</code> value is a transaction-duration
* reference to an SQL <code>ARRAY</code> value. By default, an <code>Array</code>
* object is implemented using an SQL LOCATOR(array) internally, which
* means that an <code>Array</code> object contains a logical pointer
* to the data in the SQL <code>ARRAY</code> value rather
* than containing the <code>ARRAY</code> value's data.
* <p>
* The <code>Array</code> interface provides methods for bringing an SQL
* <code>ARRAY</code> value's data to the client as either an array or a
* <code>ResultSet</code> object.
* If the elements of the SQL <code>ARRAY</code>
* are a UDT, they may be custom mapped. To create a custom mapping,
* a programmer must do two things:
* <ul>
* <li>create a class that implements the {@link SQLData}
* interface for the UDT to be custom mapped.
* <li>make an entry in a type map that contains
* <ul>
* <li>the fully-qualified SQL type name of the UDT
* <li>the <code>Class</code> object for the class implementing
* <code>SQLData</code>
* </ul>
* </ul>
* <p>
* When a type map with an entry for
* the base type is supplied to the methods <code>getArray</code>
* and <code>getResultSet</code>, the mapping
* it contains will be used to map the elements of the <code>ARRAY</code> value.
* If no type map is supplied, which would typically be the case,
* the connection's type map is used by default.
* If the connection's type map or a type map supplied to a method has no entry
* for the base type, the elements are mapped according to the standard mapping.
* <p>
* All methods on the <code>Array</code> interface must be fully implemented if the
* JDBC driver supports the data type.
*
* @since 1.2
*/
public interface Array {
/** {@collect.stats}
* Retrieves the SQL type name of the elements in
* the array designated by this <code>Array</code> object.
* If the elements are a built-in type, it returns
* the database-specific type name of the elements.
* If the elements are a user-defined type (UDT),
* this method returns the fully-qualified SQL type name.
*
* @return a <code>String</code> that is the database-specific
* name for a built-in base type; or the fully-qualified SQL type
* name for a base type that is a UDT
* @exception SQLException if an error occurs while attempting
* to access the type name
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
String getBaseTypeName() throws SQLException;
/** {@collect.stats}
* Retrieves the JDBC type of the elements in the array designated
* by this <code>Array</code> object.
*
* @return a constant from the class {@link java.sql.Types} that is
* the type code for the elements in the array designated by this
* <code>Array</code> object
* @exception SQLException if an error occurs while attempting
* to access the base type
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
int getBaseType() throws SQLException;
/** {@collect.stats}
* Retrieves the contents of the SQL <code>ARRAY</code> value designated
* by this
* <code>Array</code> object in the form of an array in the Java
* programming language. This version of the method <code>getArray</code>
* uses the type map associated with the connection for customizations of
* the type mappings.
* <p>
* <strong>Note:</strong> When <code>getArray</code> is used to materialize
* a base type that maps to a primitive data type, then it is
* implementation-defined whether the array returned is an array of
* that primitive data type or an array of <code>Object</code>.
*
* @return an array in the Java programming language that contains
* the ordered elements of the SQL <code>ARRAY</code> value
* designated by this <code>Array</code> object
* @exception SQLException if an error occurs while attempting to
* access the array
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Object getArray() throws SQLException;
/** {@collect.stats}
* Retrieves the contents of the SQL <code>ARRAY</code> value designated by this
* <code>Array</code> object.
* This method uses
* the specified <code>map</code> for type map customizations
* unless the base type of the array does not match a user-defined
* type in <code>map</code>, in which case it
* uses the standard mapping. This version of the method
* <code>getArray</code> uses either the given type map or the standard mapping;
* it never uses the type map associated with the connection.
* <p>
* <strong>Note:</strong> When <code>getArray</code> is used to materialize
* a base type that maps to a primitive data type, then it is
* implementation-defined whether the array returned is an array of
* that primitive data type or an array of <code>Object</code>.
*
* @param map a <code>java.util.Map</code> object that contains mappings
* of SQL type names to classes in the Java programming language
* @return an array in the Java programming language that contains the ordered
* elements of the SQL array designated by this object
* @exception SQLException if an error occurs while attempting to
* access the array
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Object getArray(java.util.Map<String,Class<?>> map) throws SQLException;
/** {@collect.stats}
* Retrieves a slice of the SQL <code>ARRAY</code>
* value designated by this <code>Array</code> object, beginning with the
* specified <code>index</code> and containing up to <code>count</code>
* successive elements of the SQL array. This method uses the type map
* associated with the connection for customizations of the type mappings.
* <p>
* <strong>Note:</strong> When <code>getArray</code> is used to materialize
* a base type that maps to a primitive data type, then it is
* implementation-defined whether the array returned is an array of
* that primitive data type or an array of <code>Object</code>.
*
* @param index the array index of the first element to retrieve;
* the first element is at index 1
* @param count the number of successive SQL array elements to retrieve
* @return an array containing up to <code>count</code> consecutive elements
* of the SQL array, beginning with element <code>index</code>
* @exception SQLException if an error occurs while attempting to
* access the array
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Object getArray(long index, int count) throws SQLException;
/** {@collect.stats}
* Retreives a slice of the SQL <code>ARRAY</code> value
* designated by this <code>Array</code> object, beginning with the specified
* <code>index</code> and containing up to <code>count</code>
* successive elements of the SQL array.
* <P>
* This method uses
* the specified <code>map</code> for type map customizations
* unless the base type of the array does not match a user-defined
* type in <code>map</code>, in which case it
* uses the standard mapping. This version of the method
* <code>getArray</code> uses either the given type map or the standard mapping;
* it never uses the type map associated with the connection.
* <p>
* <strong>Note:</strong> When <code>getArray</code> is used to materialize
* a base type that maps to a primitive data type, then it is
* implementation-defined whether the array returned is an array of
* that primitive data type or an array of <code>Object</code>.
*
* @param index the array index of the first element to retrieve;
* the first element is at index 1
* @param count the number of successive SQL array elements to
* retrieve
* @param map a <code>java.util.Map</code> object
* that contains SQL type names and the classes in
* the Java programming language to which they are mapped
* @return an array containing up to <code>count</code>
* consecutive elements of the SQL <code>ARRAY</code> value designated by this
* <code>Array</code> object, beginning with element
* <code>index</code>
* @exception SQLException if an error occurs while attempting to
* access the array
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
Object getArray(long index, int count, java.util.Map<String,Class<?>> map)
throws SQLException;
/** {@collect.stats}
* Retrieves a result set that contains the elements of the SQL
* <code>ARRAY</code> value
* designated by this <code>Array</code> object. If appropriate,
* the elements of the array are mapped using the connection's type
* map; otherwise, the standard mapping is used.
* <p>
* The result set contains one row for each array element, with
* two columns in each row. The second column stores the element
* value; the first column stores the index into the array for
* that element (with the first array element being at index 1).
* The rows are in ascending order corresponding to
* the order of the indices.
*
* @return a {@link ResultSet} object containing one row for each
* of the elements in the array designated by this <code>Array</code>
* object, with the rows in ascending order based on the indices.
* @exception SQLException if an error occurs while attempting to
* access the array
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
ResultSet getResultSet () throws SQLException;
/** {@collect.stats}
* Retrieves a result set that contains the elements of the SQL
* <code>ARRAY</code> value designated by this <code>Array</code> object.
* This method uses
* the specified <code>map</code> for type map customizations
* unless the base type of the array does not match a user-defined
* type in <code>map</code>, in which case it
* uses the standard mapping. This version of the method
* <code>getResultSet</code> uses either the given type map or the standard mapping;
* it never uses the type map associated with the connection.
* <p>
* The result set contains one row for each array element, with
* two columns in each row. The second column stores the element
* value; the first column stores the index into the array for
* that element (with the first array element being at index 1).
* The rows are in ascending order corresponding to
* the order of the indices.
*
* @param map contains the mapping of SQL user-defined types to
* classes in the Java programming language
* @return a <code>ResultSet</code> object containing one row for each
* of the elements in the array designated by this <code>Array</code>
* object, with the rows in ascending order based on the indices.
* @exception SQLException if an error occurs while attempting to
* access the array
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
ResultSet getResultSet (java.util.Map<String,Class<?>> map) throws SQLException;
/** {@collect.stats}
* Retrieves a result set holding the elements of the subarray that
* starts at index <code>index</code> and contains up to
* <code>count</code> successive elements. This method uses
* the connection's type map to map the elements of the array if
* the map contains an entry for the base type. Otherwise, the
* standard mapping is used.
* <P>
* The result set has one row for each element of the SQL array
* designated by this object, with the first row containing the
* element at index <code>index</code>. The result set has
* up to <code>count</code> rows in ascending order based on the
* indices. Each row has two columns: The second column stores
* the element value; the first column stores the index into the
* array for that element.
*
* @param index the array index of the first element to retrieve;
* the first element is at index 1
* @param count the number of successive SQL array elements to retrieve
* @return a <code>ResultSet</code> object containing up to
* <code>count</code> consecutive elements of the SQL array
* designated by this <code>Array</code> object, starting at
* index <code>index</code>.
* @exception SQLException if an error occurs while attempting to
* access the array
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
ResultSet getResultSet(long index, int count) throws SQLException;
/** {@collect.stats}
* Retrieves a result set holding the elements of the subarray that
* starts at index <code>index</code> and contains up to
* <code>count</code> successive elements.
* This method uses
* the specified <code>map</code> for type map customizations
* unless the base type of the array does not match a user-defined
* type in <code>map</code>, in which case it
* uses the standard mapping. This version of the method
* <code>getResultSet</code> uses either the given type map or the standard mapping;
* it never uses the type map associated with the connection.
* <P>
* The result set has one row for each element of the SQL array
* designated by this object, with the first row containing the
* element at index <code>index</code>. The result set has
* up to <code>count</code> rows in ascending order based on the
* indices. Each row has two columns: The second column stores
* the element value; the first column stroes the index into the
* array for that element.
*
* @param index the array index of the first element to retrieve;
* the first element is at index 1
* @param count the number of successive SQL array elements to retrieve
* @param map the <code>Map</code> object that contains the mapping
* of SQL type names to classes in the Java(tm) programming language
* @return a <code>ResultSet</code> object containing up to
* <code>count</code> consecutive elements of the SQL array
* designated by this <code>Array</code> object, starting at
* index <code>index</code>.
* @exception SQLException if an error occurs while attempting to
* access the array
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
ResultSet getResultSet (long index, int count,
java.util.Map<String,Class<?>> map)
throws SQLException;
/** {@collect.stats}
* This method frees the <code>Array</code> object and releases the resources that
* it holds. The object is invalid once the <code>free</code>
* method is called.
*<p>
* After <code>free</code> has been called, any attempt to invoke a
* method other than <code>free</code> will result in a <code>SQLException</code>
* being thrown. If <code>free</code> is called multiple times, the subsequent
* calls to <code>free</code> are treated as a no-op.
*<p>
*
* @throws SQLException if an error occurs releasing
* the Array's resources
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.6
*/
void free() throws SQLException;
}
|
Java
|
/*
* Copyright (c) 1998, 2006, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package java.sql;
/** {@collect.stats}
* The mapping in the Java programming language of an SQL <code>REF</code>
* value, which is a reference to an SQL structured type value in the database.
* <P>
* SQL <code>REF</code> values are stored in a table that contains
* instances of a referenceable SQL structured type, and each <code>REF</code>
* value is a unique identifier for one instance in that table.
* An SQL <code>REF</code> value may be used in place of the
* SQL structured type it references, either as a column value in a
* table or an attribute value in a structured type.
* <P>
* Because an SQL <code>REF</code> value is a logical pointer to an
* SQL structured type, a <code>Ref</code> object is by default also a logical
* pointer. Thus, retrieving an SQL <code>REF</code> value as
* a <code>Ref</code> object does not materialize
* the attributes of the structured type on the client.
* <P>
* A <code>Ref</code> object can be stored in the database using the
* <code>PreparedStatement.setRef</code> method.
* <p>
* All methods on the <code>Ref</code> interface must be fully implemented if the
* JDBC driver supports the data type.
*
* @see Struct
* @since 1.2
*/
public interface Ref {
/** {@collect.stats}
* Retrieves the fully-qualified SQL name of the SQL structured type that
* this <code>Ref</code> object references.
*
* @return the fully-qualified SQL name of the referenced SQL structured type
* @exception SQLException if a database access error occurs
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.2
*/
String getBaseTypeName() throws SQLException;
/** {@collect.stats}
* Retrieves the referenced object and maps it to a Java type
* using the given type map.
*
* @param map a <code>java.util.Map</code> object that contains
* the mapping to use (the fully-qualified name of the SQL
* structured type being referenced and the class object for
* <code>SQLData</code> implementation to which the SQL
* structured type will be mapped)
* @return a Java <code>Object</code> that is the custom mapping for
* the SQL structured type to which this <code>Ref</code>
* object refers
* @exception SQLException if a database access error occurs
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
* @see #setObject
*/
Object getObject(java.util.Map<String,Class<?>> map) throws SQLException;
/** {@collect.stats}
* Retrieves the SQL structured type instance referenced by
* this <code>Ref</code> object. If the connection's type map has an entry
* for the structured type, the instance will be custom mapped to
* the Java class indicated in the type map. Otherwise, the
* structured type instance will be mapped to a <code>Struct</code> object.
*
* @return a Java <code>Object</code> that is the mapping for
* the SQL structured type to which this <code>Ref</code>
* object refers
* @exception SQLException if a database access error occurs
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
* @see #setObject
*/
Object getObject() throws SQLException;
/** {@collect.stats}
* Sets the structured type value that this <code>Ref</code>
* object references to the given instance of <code>Object</code>.
* The driver converts this to an SQL structured type when it
* sends it to the database.
*
* @param value an <code>Object</code> representing the SQL
* structured type instance that this
* <code>Ref</code> object will reference
* @exception SQLException if a database access error occurs
* @exception SQLFeatureNotSupportedException if the JDBC driver does not support
* this method
* @since 1.4
* @see #getObject()
* @see #getObject(Map)
* @see PreparedStatement#setObject(int, Object)
* @see CallableStatement#setObject(String, Object)
*/
void setObject(Object value) throws SQLException;
}
|
Java
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.