001: /***
002: * Retrotranslator: a Java bytecode transformer that translates Java classes
003: * compiled with JDK 5.0 into classes that can be run on JVM 1.4.
004: *
005: * Copyright (c) 2005 - 2008 Taras Puchko
006: * All rights reserved.
007: *
008: * Redistribution and use in source and binary forms, with or without
009: * modification, are permitted provided that the following conditions
010: * are met:
011: * 1. Redistributions of source code must retain the above copyright
012: * notice, this list of conditions and the following disclaimer.
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in the
015: * documentation and/or other materials provided with the distribution.
016: * 3. Neither the name of the copyright holders nor the names of its
017: * contributors may be used to endorse or promote products derived from
018: * this software without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
021: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
022: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
023: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
024: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
025: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
026: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
027: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
028: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
029: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
030: * THE POSSIBILITY OF SUCH DAMAGE.
031: */package net.sf.retrotranslator.runtime.java.lang;
032:
033: import java.io.*;
034: import java.nio.CharBuffer;
035: import net.sf.retrotranslator.runtime.java.io.*;
036: import net.sf.retrotranslator.runtime.java.nio._CharBuffer;
037:
038: /**
039: * @author Taras Puchko
040: */
041: public class _Appendable {
042:
043: public static boolean executeInstanceOfInstruction(Object object) {
044: return object instanceof StringBuffer
045: || object instanceof PrintStream
046: || object instanceof Writer
047: || object instanceof CharBuffer
048: || object instanceof Appendable_;
049: }
050:
051: public static Object executeCheckCastInstruction(Object object) {
052: if (object instanceof StringBuffer) {
053: return (StringBuffer) object;
054: }
055: if (object instanceof PrintStream) {
056: return (PrintStream) object;
057: }
058: if (object instanceof Writer) {
059: return (Writer) object;
060: }
061: if (object instanceof CharBuffer) {
062: return (CharBuffer) object;
063: }
064: return (Appendable_) object;
065: }
066:
067: public static Object append(Object object, CharSequence csq)
068: throws IOException {
069: if (object instanceof StringBuffer) {
070: return _StringBuffer.append((StringBuffer) object, csq);
071: }
072: if (object instanceof PrintStream) {
073: return _PrintStream.append((PrintStream) object, csq);
074: }
075: if (object instanceof Writer) {
076: return _Writer.append((Writer) object, csq);
077: }
078: if (object instanceof CharBuffer) {
079: return _CharBuffer.append((CharBuffer) object, csq);
080: }
081: return ((Appendable_) object).append(csq);
082: }
083:
084: public static Object append(Object object, CharSequence csq,
085: int start, int end) throws IOException {
086: if (object instanceof StringBuffer) {
087: return _StringBuffer.append((StringBuffer) object, csq,
088: start, end);
089: }
090: if (object instanceof PrintStream) {
091: return _PrintStream.append((PrintStream) object, csq,
092: start, end);
093: }
094: if (object instanceof Writer) {
095: return _Writer.append((Writer) object, csq, start, end);
096: }
097: if (object instanceof CharBuffer) {
098: return _CharBuffer.append((CharBuffer) object, csq, start,
099: end);
100: }
101: return ((Appendable_) object).append(csq, start, end);
102: }
103:
104: public static Object append(Object object, char c)
105: throws IOException {
106: if (object instanceof StringBuffer) {
107: return ((StringBuffer) object).append(c);
108: }
109: if (object instanceof PrintStream) {
110: return _PrintStream.append((PrintStream) object, c);
111: }
112: if (object instanceof Writer) {
113: return _Writer.append((Writer) object, c);
114: }
115: if (object instanceof CharBuffer) {
116: return _CharBuffer.append((CharBuffer) object, c);
117: }
118: return ((Appendable_) object).append(c);
119: }
120:
121: }
|