Package java.io

Examples of java.io.Reader


   * @throws TransformationException if value is an incorrect input type or
   * the transformation fails
   */
  public Object transformDirect(Object value) throws TransformationException {
        String xml = (String)value;
        Reader reader = new StringReader(xml);
        Type type = isXml(reader);
        XMLType result = new XMLType(new SQLXMLImpl(xml));
        result.setType(type);
        return result;
  }
View Full Code Here


     * Note this doesn't close the stream.
     * @throws IOException if a problem occurred reading the stream.
     */
    public static char[] convertToCharArray(InputStream stream, int length, String encoding)
        throws IOException {
      Reader r = null;
      if (encoding == null) {
        r = new InputStreamReader(stream);
      } else {
        r = new InputStreamReader(stream, encoding);
      }
View Full Code Here

    }
  }
 
    public Reader getCharacterStream() throws SQLException {
      try {
      Reader r = this.getStreamFactory().getCharacterStream();
      if (r != null) {
        return r;
      }
    } catch (IOException e) {
      SQLException ex = new SQLException(e.getMessage());
View Full Code Here

     * Utility method to convert to String 
     * @param clob
     * @return string form of the clob passed.
     */
    public static String getString(Clob clob) throws SQLException, IOException {
        Reader reader = clob.getCharacterStream();
        StringWriter writer = new StringWriter();
        int c = reader.read();
        while (c != -1) {
            writer.write((char)c);
            c = reader.read();
        }
        reader.close();
        String data = writer.toString();
        writer.close();
        return data;       
    }
View Full Code Here

     * @throws TransformationException if value is an incorrect input type or
     * the transformation fails
     */
    public Object transformDirect(Object value) throws TransformationException {
        XMLType source = (XMLType)value;
        Reader reader = null;
        try {      
            char[] result = new char[DataTypeManager.MAX_STRING_LENGTH];
            reader = source.getCharacterStream();
            int read = reader.read(result);
            return new String(result, 0, read);
        } catch (SQLException e) {
            throw new TransformationException(e, CorePlugin.Util.getString("failed_convert", new Object[] {getSourceType().getName(), getTargetType().getName()})); //$NON-NLS-1$           
        } catch (IOException e) {
            throw new TransformationException(e, CorePlugin.Util.getString("failed_convert", new Object[] {getSourceType().getName(), getTargetType().getName()})); //$NON-NLS-1$
        } finally {
          try {
            if (reader != null) {
              reader.close();
            }
      } catch (IOException e) {
      }
        }
    }
View Full Code Here

            Object[] params = new Object[] {new Integer( length)};
            throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.1", params)); //$NON-NLS-1$
        } else if ((pos+length) > length()) {
            length = (int)(length()-pos);
        }
        Reader in = getCharacterStream();
        try {
          try {
            long skipped = 0;
            while (pos > 0) {
              skipped = in.skip(pos);
              pos -= skipped;
            }
            return new String(ObjectConverterUtil.convertToCharArray(in, length));
          } finally {
            in.close();
          }
        } catch (IOException e) {
          throw new SQLException(e);
        }
    }
View Full Code Here

     * @return length of the <code>CLOB</code> in characters
     */
    public long length() throws SQLException {
      if (len == -1) {
        long length = 0;
        Reader r = new BufferedReader(getCharacterStream());
        try {
        while (r.read() != -1) {
          length++;
        }
      } catch (IOException e) {
        throw new SQLException(e);
      } finally {
        try {
          r.close();
        } catch (IOException e) {
        }
      }
        this.len = length;
      }
View Full Code Here

    }
   
    @Test public void testGetString1() throws Exception {
      SQLXMLImpl clob = new SQLXMLImpl() {
        public java.io.Reader getCharacterStream() throws java.sql.SQLException {
          return new Reader() {

            int pos = 0;
           
          @Override
          public void close() throws IOException {
View Full Code Here

  }

  @SuppressWarnings("unchecked")
  public void load() throws IOException {
    if (_file.exists()) {
      Reader reader = null;
      try {
        reader = new FileReader(_file);
        _beans = (List<T>) _xstream.fromXML(reader);
      } finally {
        if (reader != null) {
          try {
            reader.close();
          } catch (IOException e) {
          }
        }
      }
    }
View Full Code Here

      FactoryConfigurationError, XMLStreamException,
      TransformerException {
    if (object == null) {
      return;
    }
    Reader r = null;
    try {
      if (object instanceof XMLType) {
        XMLType xml = (XMLType)object;
        r = xml.getCharacterStream();
        Type type = xml.getType();
        convertReader(writer, eventWriter, r, type);
      } else if (object instanceof Clob) {
        Clob clob = (Clob)object;
        r = clob.getCharacterStream();
        convertReader(writer, eventWriter, r, Type.TEXT);
      } else {
        String val = convertToAtomicValue(object).getStringValue();
        eventWriter.add(eventFactory.createCharacters(val));
      }
    } catch (SQLException e) {
      throw new IOException(e);
    } finally {
      if (r != null) {
        r.close();
      }
    }
    //TODO: blob - with base64 encoding
  }
View Full Code Here

TOP

Related Classes of java.io.Reader

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.