【问题标题】:cassandra row fetch gives junk characterscassandra row fetch 给出了垃圾字符
【发布时间】:2015-04-20 05:44:52
【问题描述】:

正在学习 Cassandra,并编写了一个可以从数据库读取文件的 restclient。

下面是我从数据库中检索数据的代码。

        ResultSet rs = getFile(fileName);
        Row row=rs.one();

        ByteBuffer filecontent =row.getBytes("file_content");
        byte[] data = new byte[filecontent.remaining()];
        ByteBuffer bb = filecontent.get(data);

        String filelocation = row.getString("file_location");
        String filename = row.getString("filename");

        ByteArrayInputStream filecontentfromDB= new ByteArrayInputStream(bb.array());
        File file=writeToFile(filecontentfromDB,fileName);

        if (rs == null) {
            return null;
        }
        return file;

当我查看返回的文件时,我发现开头有一些垃圾字符,然后是我的文件内容。

请帮我删除垃圾数据

【问题讨论】:

    标签: java cassandra bigdata


    【解决方案1】:

    Yipee,找到了解决方案,下面的行应该被替换

    String filelocation = row.getString("file_location");
            String filename = row.getString("filename");
    
            ByteArrayInputStream filecontentfromDB= new ByteArrayInputStream(bb.array());
    

    String filelocation = row.getString("file_location");
            String filename = row.getString("filename");
    String bb = new String(filecontent.array(), filecontent.arrayOffset() + filecontent.position(), filecontent.remaining());
            ByteArrayInputStream filecontentfromDB= new ByteArrayInputStream(bb.getBytes());
    

    它有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-23
      • 1970-01-01
      • 2015-04-29
      • 2011-11-21
      • 2015-01-28
      • 1970-01-01
      • 2018-02-14
      • 2023-03-20
      相关资源
      最近更新 更多