1 /*
2 * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
548 * @throws SerialException if the {@code free} method had been previously
549 * called on this object
550 * @since 1.6
551 */
552 public Reader getCharacterStream(long pos, long length) throws SQLException {
553 isValid();
554 if (pos < 1 || pos > len) {
555 throw new SerialException("Invalid position in Clob object set");
556 }
557
558 if ((pos-1) + length > len) {
559 throw new SerialException("Invalid position and substring length");
560 }
561 if (length <= 0) {
562 throw new SerialException("Invalid length specified");
563 }
564 return new CharArrayReader(buf, (int)pos, (int)length);
565 }
566
567 /**
568 * This method frees the {@code SeriableClob} object and releases the
569 * resources that it holds.
570 * The object is invalid once the {@code free} method is called.
571 * <p>
572 * If {@code free} is called multiple times, the subsequent
573 * calls to {@code free} are treated as a no-op.
574 * </P>
575 * @throws SQLException if an error occurs releasing
576 * the Clob's resources
577 * @since 1.6
578 */
579 public void free() throws SQLException {
580 if (buf != null) {
581 buf = null;
582 if (clob != null) {
583 clob.free();
584 }
585 clob = null;
586 }
587 }
588
653 buf = tmp.clone();
654 len = fields.get("len", 0L);
655 if (buf.length != len)
656 throw new InvalidObjectException("buf is not the expected size");
657 origLen = fields.get("origLen", 0L);
658 clob = (Clob) fields.get("clob", null);
659 }
660
661 /**
662 * writeObject is called to save the state of the SerialClob
663 * to a stream.
664 */
665 private void writeObject(ObjectOutputStream s)
666 throws IOException, ClassNotFoundException {
667
668 ObjectOutputStream.PutField fields = s.putFields();
669 fields.put("buf", buf);
670 fields.put("len", len);
671 fields.put("origLen", origLen);
672 // Note: this check to see if it is an instance of Serializable
673 // is for backwards compatibiity
674 fields.put("clob", clob instanceof Serializable ? clob : null);
675 s.writeFields();
676 }
677
678 /**
679 * Check to see if this object had previously had its {@code free} method
680 * called
681 *
682 * @throws SerialException
683 */
684 private void isValid() throws SerialException {
685 if (buf == null) {
686 throw new SerialException("Error: You cannot call a method on a "
687 + "SerialClob instance once free() has been called.");
688 }
689 }
690
691 /**
692 * The identifier that assists in the serialization of this {@code SerialClob}
693 * object.
|
1 /*
2 * Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
548 * @throws SerialException if the {@code free} method had been previously
549 * called on this object
550 * @since 1.6
551 */
552 public Reader getCharacterStream(long pos, long length) throws SQLException {
553 isValid();
554 if (pos < 1 || pos > len) {
555 throw new SerialException("Invalid position in Clob object set");
556 }
557
558 if ((pos-1) + length > len) {
559 throw new SerialException("Invalid position and substring length");
560 }
561 if (length <= 0) {
562 throw new SerialException("Invalid length specified");
563 }
564 return new CharArrayReader(buf, (int)pos, (int)length);
565 }
566
567 /**
568 * This method frees the {@code SerialClob} object and releases the
569 * resources that it holds.
570 * The object is invalid once the {@code free} method is called.
571 * <p>
572 * If {@code free} is called multiple times, the subsequent
573 * calls to {@code free} are treated as a no-op.
574 * </P>
575 * @throws SQLException if an error occurs releasing
576 * the Clob's resources
577 * @since 1.6
578 */
579 public void free() throws SQLException {
580 if (buf != null) {
581 buf = null;
582 if (clob != null) {
583 clob.free();
584 }
585 clob = null;
586 }
587 }
588
653 buf = tmp.clone();
654 len = fields.get("len", 0L);
655 if (buf.length != len)
656 throw new InvalidObjectException("buf is not the expected size");
657 origLen = fields.get("origLen", 0L);
658 clob = (Clob) fields.get("clob", null);
659 }
660
661 /**
662 * writeObject is called to save the state of the SerialClob
663 * to a stream.
664 */
665 private void writeObject(ObjectOutputStream s)
666 throws IOException, ClassNotFoundException {
667
668 ObjectOutputStream.PutField fields = s.putFields();
669 fields.put("buf", buf);
670 fields.put("len", len);
671 fields.put("origLen", origLen);
672 // Note: this check to see if it is an instance of Serializable
673 // is for backwards compatibility
674 fields.put("clob", clob instanceof Serializable ? clob : null);
675 s.writeFields();
676 }
677
678 /**
679 * Check to see if this object had previously had its {@code free} method
680 * called
681 *
682 * @throws SerialException
683 */
684 private void isValid() throws SerialException {
685 if (buf == null) {
686 throw new SerialException("Error: You cannot call a method on a "
687 + "SerialClob instance once free() has been called.");
688 }
689 }
690
691 /**
692 * The identifier that assists in the serialization of this {@code SerialClob}
693 * object.
|