You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Vitaly Repetenko <vi...@mtu.ru> on 2001/11/12 12:08:09 UTC

An extention of ResourceLoader

Good day!

I have a problem with developing an extention of ResourceLoader. I use
CLOB to store templates in the db.
Clob class has a method getAsciiStream which returns InputStream, but
this method does not work with Russian charset.
I can not use method getCharacterStream because it returns a Reader
stream and ResourceLoader does not work with Reader. I was trying to use
a temporary variable (String) and class StringBufferInputStream but this
class does not properly convert characters into bytes.
Any idea?

Thanks in advance,
Vitaly


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: An extention of ResourceLoader -OT

Posted by "Geir Magnusson Jr." <ge...@yahoo.com>.
On 11/13/01 1:11 PM, "Nick Bauman" <ni...@cortexity.com> wrote:

>> On 11/13/01 6:33 AM, "Vitaly Repetenko" <vi...@mtu.ru> wrote:
>> 
>>> 
>>> 
>>> Vitaly Repetenko wrote:
>>> 
>>>> Good day!
>>>> 
>>>> I have a problem with developing an extention of ResourceLoader. I
>>>> use CLOB to store templates in the db.
>>>> Clob class has a method getAsciiStream which returns InputStream, but
>>>> this method does not work with Russian charset.
>>>> I can not use method getCharacterStream because it returns a Reader
>>>> stream and ResourceLoader does not work with Reader. I was trying to
>>>> use a temporary variable (String) and class StringBufferInputStream
>>>> but this class does not properly convert characters into bytes.
>>>> Any idea?
>>>> 
>>>> Thanks in advance,
>>>> Vitaly
>>>> 
>>>> --
>>>> To unsubscribe, e-mail:
>>>> <ma...@jakarta.apache.org>
>>>> For additional commands, e-mail:
>>>> <ma...@jakarta.apache.org>
>>> 
>>> Good day!
>>> 
>>> I have found some solution.
>>> 
>>>    public synchronized InputStream getResourceStream( String name )
>>>        throws ResourceNotFoundException
>>>    {
>>>      ...
>>>                    if (rs.next())
>>>                    {
>>>                        Clob clob = rs.getClob(templateColumn);
>>>                        String s = clob.getSubString(1,
>>>                        (int)clob.length());
>>> 
>>>                        return new
>>> ByteArrayInputStream(s.getBytes(inputEncoding));
>>>                    }
>>>       ...
>>>    }
>>> 
>>> But I don't think that this is a good solution.
>>> Is it possible to have ResourceLoader which can work with a Byte
>>> stream and  a Character stream?
>>> 
>>> Thanks in advance,
>>> Vitaly
>> 
>> You should be able to do that.  The resource loader just needs to
>> delliver a stream of bytes.
>> 
>> You have to be a touch careful with things like this - I just
>> discovered the challenges that dealing with CLOBs in Oracle seems to
>> require non-standard JDBC code...
> 
> Large object support in JDBC for Oracle (8.1.7) is very very slow. In my
> tests, I found that it's like 10x slower than using a stored procedure and
> calling that from JDBC. Also, our data architect showed me tests that
> indicated that straight JDBC PreparedStatements (no stored proc) generated
> close to 100 I/O requests on the database per transaction!
> 


That's interesting.  I was more worried about the fact I had to downcast a
ResultSet to an OracleResultSet to get to the CLOB, and had to insert an
empty CLOB first, then select for update, etc, etc, etc.

Geir

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: An extention of ResourceLoader -OT

Posted by Nick Bauman <ni...@cortexity.com>.
> On 11/13/01 6:33 AM, "Vitaly Repetenko" <vi...@mtu.ru> wrote:
> 
>> 
>> 
>> Vitaly Repetenko wrote:
>> 
>>> Good day!
>>> 
>>> I have a problem with developing an extention of ResourceLoader. I
>>> use CLOB to store templates in the db.
>>> Clob class has a method getAsciiStream which returns InputStream, but
>>> this method does not work with Russian charset.
>>> I can not use method getCharacterStream because it returns a Reader
>>> stream and ResourceLoader does not work with Reader. I was trying to
>>> use a temporary variable (String) and class StringBufferInputStream
>>> but this class does not properly convert characters into bytes.
>>> Any idea?
>>> 
>>> Thanks in advance,
>>> Vitaly
>>> 
>>> --
>>> To unsubscribe, e-mail:
>>> <ma...@jakarta.apache.org>
>>> For additional commands, e-mail:
>>> <ma...@jakarta.apache.org>
>> 
>> Good day!
>> 
>> I have found some solution.
>> 
>>    public synchronized InputStream getResourceStream( String name )
>>        throws ResourceNotFoundException
>>    {
>>      ...
>>                    if (rs.next())
>>                    {
>>                        Clob clob = rs.getClob(templateColumn);
>>                        String s = clob.getSubString(1,
>>                        (int)clob.length());
>> 
>>                        return new
>> ByteArrayInputStream(s.getBytes(inputEncoding));
>>                    }
>>       ...
>>    }
>> 
>> But I don't think that this is a good solution.
>> Is it possible to have ResourceLoader which can work with a Byte
>> stream and  a Character stream?
>> 
>> Thanks in advance,
>> Vitaly
> 
> You should be able to do that.  The resource loader just needs to
> delliver a stream of bytes.
> 
> You have to be a touch careful with things like this - I just
> discovered the challenges that dealing with CLOBs in Oracle seems to
> require non-standard JDBC code... 

Large object support in JDBC for Oracle (8.1.7) is very very slow. In my
tests, I found that it's like 10x slower than using a stored procedure and
calling that from JDBC. Also, our data architect showed me tests that
indicated that straight JDBC PreparedStatements (no stored proc) generated
close to 100 I/O requests on the database per transaction!

> Geir
> 
> 
> -- 
> Geir Magnusson Jr.                                    
> geirm@optonline.net System and Software Consulting
> "He who throws mud only loses ground." - Fat Albert
> 
> 

--
Nick Bauman 
Cortexity Development
Intellectual Process is more important than
Intellectual Property -- you'll see.
http://www.cortexity.com/


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: An extention of ResourceLoader

Posted by "Geir Magnusson Jr." <ge...@yahoo.com>.
On 11/14/01 4:22 AM, "Vitaly Repetenko" <vi...@mtu.ru> wrote:

> 
> 
> "Geir Magnusson Jr." wrote:
> 
>> On 11/13/01 6:33 AM, "Vitaly Repetenko" <vi...@mtu.ru> wrote:
>> 
>>> 
>>> 
>>> Vitaly Repetenko wrote:
>>> 
>>>> Good day!
>>>> 
>>>> I have a problem with developing an extention of ResourceLoader. I use
>>>> CLOB to store templates in the db.
>>>> Clob class has a method getAsciiStream which returns InputStream, but
>>>> this method does not work with Russian charset.
>>>> I can not use method getCharacterStream because it returns a Reader
>>>> stream and ResourceLoader does not work with Reader. I was trying to use
>>>> a temporary variable (String) and class StringBufferInputStream but this
>>>> class does not properly convert characters into bytes.
>>>> Any idea?
>>>> 
>>>> Thanks in advance,
>>>> Vitaly
>>>> 
>>>> --
>>>> To unsubscribe, e-mail:
>>>> <ma...@jakarta.apache.org>
>>>> For additional commands, e-mail:
>>>> <ma...@jakarta.apache.org>
>>> 
>>> Good day!
>>> 
>>> I have found some solution.
>>> 
>>>    public synchronized InputStream getResourceStream( String name )
>>>        throws ResourceNotFoundException
>>>    {
>>>      ...
>>>                    if (rs.next())
>>>                    {
>>>                        Clob clob = rs.getClob(templateColumn);
>>>                        String s = clob.getSubString(1, (int)clob.length());
>>> 
>>>                        return new
>>> ByteArrayInputStream(s.getBytes(inputEncoding));
>>>                    }
>>>       ...
>>>    }
>>> 
>>> But I don't think that this is a good solution.
>>> Is it possible to have ResourceLoader which can work with a Byte stream and
>>> a
>>> Character stream?
>>> 
>>> Thanks in advance,
>>> Vitaly
>> 
>> You should be able to do that.  The resource loader just needs to delliver a
>> stream of bytes.
>> 
> 
> Good day!
> 
> In this case, is it possible to work with templates in Unicode?
> 
> Thanks in advance,
> Vitaly

Disclaimer : I am barely literate in this stuff...

I don't know if I am answering the question correctly (See the disclaimer
above...)  

Velocity will allow you to use any encoding you wish for your templates.  We
have examples available to show how this works - see the EncodingTestCase in
org.apache.velocity.test to see how we do it.  It includes a KOI8-R encoding
example.

Is that what you were looking for?

geir

-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"They that can give up essential liberty to obtain a little temporary safety
deserve neither liberty nor safety." - Benjamin Franklin



_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: An extention of ResourceLoader

Posted by Vitaly Repetenko <vi...@mtu.ru>.

"Geir Magnusson Jr." wrote:

> On 11/13/01 6:33 AM, "Vitaly Repetenko" <vi...@mtu.ru> wrote:
>
> >
> >
> > Vitaly Repetenko wrote:
> >
> >> Good day!
> >>
> >> I have a problem with developing an extention of ResourceLoader. I use
> >> CLOB to store templates in the db.
> >> Clob class has a method getAsciiStream which returns InputStream, but
> >> this method does not work with Russian charset.
> >> I can not use method getCharacterStream because it returns a Reader
> >> stream and ResourceLoader does not work with Reader. I was trying to use
> >> a temporary variable (String) and class StringBufferInputStream but this
> >> class does not properly convert characters into bytes.
> >> Any idea?
> >>
> >> Thanks in advance,
> >> Vitaly
> >>
> >> --
> >> To unsubscribe, e-mail:
> >> <ma...@jakarta.apache.org>
> >> For additional commands, e-mail:
> >> <ma...@jakarta.apache.org>
> >
> > Good day!
> >
> > I have found some solution.
> >
> >    public synchronized InputStream getResourceStream( String name )
> >        throws ResourceNotFoundException
> >    {
> >      ...
> >                    if (rs.next())
> >                    {
> >                        Clob clob = rs.getClob(templateColumn);
> >                        String s = clob.getSubString(1, (int)clob.length());
> >
> >                        return new
> > ByteArrayInputStream(s.getBytes(inputEncoding));
> >                    }
> >       ...
> >    }
> >
> > But I don't think that this is a good solution.
> > Is it possible to have ResourceLoader which can work with a Byte stream and  a
> > Character stream?
> >
> > Thanks in advance,
> > Vitaly
>
> You should be able to do that.  The resource loader just needs to delliver a
> stream of bytes.
>

Good day!

In this case, is it possible to work with templates in Unicode?

Thanks in advance,
Vitaly


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: An extention of ResourceLoader

Posted by "Geir Magnusson Jr." <ge...@yahoo.com>.
On 11/13/01 6:33 AM, "Vitaly Repetenko" <vi...@mtu.ru> wrote:

> 
> 
> Vitaly Repetenko wrote:
> 
>> Good day!
>> 
>> I have a problem with developing an extention of ResourceLoader. I use
>> CLOB to store templates in the db.
>> Clob class has a method getAsciiStream which returns InputStream, but
>> this method does not work with Russian charset.
>> I can not use method getCharacterStream because it returns a Reader
>> stream and ResourceLoader does not work with Reader. I was trying to use
>> a temporary variable (String) and class StringBufferInputStream but this
>> class does not properly convert characters into bytes.
>> Any idea?
>> 
>> Thanks in advance,
>> Vitaly
>> 
>> --
>> To unsubscribe, e-mail:
>> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
>> <ma...@jakarta.apache.org>
> 
> Good day!
> 
> I have found some solution.
> 
>    public synchronized InputStream getResourceStream( String name )
>        throws ResourceNotFoundException
>    {
>      ...
>                    if (rs.next())
>                    {
>                        Clob clob = rs.getClob(templateColumn);
>                        String s = clob.getSubString(1, (int)clob.length());
> 
>                        return new
> ByteArrayInputStream(s.getBytes(inputEncoding));
>                    }
>       ...
>    }
> 
> But I don't think that this is a good solution.
> Is it possible to have ResourceLoader which can work with a Byte stream and  a
> Character stream?
> 
> Thanks in advance,
> Vitaly

You should be able to do that.  The resource loader just needs to delliver a
stream of bytes.

You have to be a touch careful with things like this - I just discovered the
challenges that dealing with CLOBs in Oracle seems to require non-standard
JDBC code... 

Geir


-- 
Geir Magnusson Jr.                                     geirm@optonline.net
System and Software Consulting
"He who throws mud only loses ground." - Fat Albert


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: An extention of ResourceLoader

Posted by Vitaly Repetenko <vi...@mtu.ru>.

Vitaly Repetenko wrote:

> Good day!
>
> I have a problem with developing an extention of ResourceLoader. I use
> CLOB to store templates in the db.
> Clob class has a method getAsciiStream which returns InputStream, but
> this method does not work with Russian charset.
> I can not use method getCharacterStream because it returns a Reader
> stream and ResourceLoader does not work with Reader. I was trying to use
> a temporary variable (String) and class StringBufferInputStream but this
> class does not properly convert characters into bytes.
> Any idea?
>
> Thanks in advance,
> Vitaly
>
> --
> To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
> For additional commands, e-mail: <ma...@jakarta.apache.org>

Good day!

I have found some solution.

     public synchronized InputStream getResourceStream( String name )
         throws ResourceNotFoundException
     {
       ...
                     if (rs.next())
                     {
                         Clob clob = rs.getClob(templateColumn);
                         String s = clob.getSubString(1, (int)clob.length());

                         return new
ByteArrayInputStream(s.getBytes(inputEncoding));
                     }
        ...
     }

But I don't think that this is a good solution.
Is it possible to have ResourceLoader which can work with a Byte stream and  a
Character stream?

Thanks in advance,
Vitaly


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>