josefmezera / h2database

Automatically exported from code.google.com/p/h2database
0 stars 0 forks source link

valueString.getInputStream() : Hexadecimal string contains non hex character #436

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Try this java test :
{code}
import java.io.InputStream;
import org.h2.value.ValueString;
import org.testng.annotations.Test;

@Test
public class ValueStringTest {

    @Test
    public void shouldTest() {
        //given
        final String myVarcharColumn = "<p>Link $activationLink, password: $password</p>";
        final ValueString valueString = ValueString.get(myVarcharColumn);

        //when
        final InputStream inputStream = valueString.getInputStream();

        //then
    }
}
{code}

What is the expected output? What do you see instead?
Expected output is a valid inputStream, however H2 throws an exception.

What version of the product are you using? On what operating system, file
system, and virtual machine?

- H2 v1.3.170
- Linux ginger 3.2.0-36-generic #57-Ubuntu SMP Tue Jan 8 21:41:24 UTC 2013 i686 
i686 i386 GNU/Linux
- java version "1.6.0_35"

Do you know a workaround?
Temporary, I can use hex representation of myVarcharColumn i.e. 
3c703e4c696e6b202461637469766174696f6e4c696e6b2c2070617373776f72643a202470617373
776f72643c2f703e

What is your use case, meaning why do you need this feature?
I would like to have readable template in DB, instead of HEX.

Original issue reported on code.google.com by sergiusz...@gmail.com on 1 Feb 2013 at 9:20

GoogleCodeExporter commented 9 years ago
Instead of using an InputStream, why don't you use a Reader?

In any case, you are not supposed to use the Value class directly.

Original comment by thomas.t...@gmail.com on 1 Feb 2013 at 10:12

GoogleCodeExporter commented 9 years ago
I see, but my case is wider. I am using the apache velocity engine v1.6.4 
(http://velocity.apache.org/) within spring application. My templates are 
stored in H2.
During preparing message, I get :
{exception}
    at org.h2.message.DbException.getJdbcSQLException(DbException.java:329)
    at org.h2.message.DbException.get(DbException.java:169)
    at org.h2.message.DbException.get(DbException.java:146)
    at org.h2.util.StringUtils.convertHexToBytes(StringUtils.java:990)
    at org.h2.value.Value.convertTo(Value.java:821)
    at org.h2.value.Value.getBytesNoCopy(Value.java:393)
    at org.h2.value.Value.getInputStream(Value.java:425)
    at org.h2.jdbc.JdbcResultSet.getBinaryStream(JdbcResultSet.java:1029)
    at org.apache.velocity.runtime.resource.loader.DataSourceResourceLoader.getResourceStream(DataSourceResourceLoader.java:235)
    at org.apache.velocity.Template.process(Template.java:98)
    at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:446)
    at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:354)
    at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1400)
    at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:370)
    at org.apache.velocity.app.VelocityEngine.mergeTemplate(VelocityEngine.java:345)
    at org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplate(VelocityEngineUtils.java:58)
    at org.springframework.ui.velocity.VelocityEngineUtils.mergeTemplateIntoString(VelocityEngineUtils.java:122)
{exception}

As you can see, the DataSourceResourceLoader.getResourceStream uses within an 
InputStream.

Original comment by sergiusz...@gmail.com on 1 Feb 2013 at 10:29

GoogleCodeExporter commented 9 years ago
Well, if you store data as a VARCHAR and then don't try to open it as a BLOB. 
Just use BLOB.

For support, please use StackOverflow. The issue tracker isn't a support forum.

Original comment by thomas.t...@gmail.com on 1 Feb 2013 at 10:57

GoogleCodeExporter commented 9 years ago
I'll try. Thanks for suggestion and sorry for it.

Original comment by sergiusz...@gmail.com on 1 Feb 2013 at 11:03