Solved

bFile and getBinaryStream()

Posted on 2004-10-18
5
572 Views
Last Modified: 2012-06-27
     
      
hi!

can anybody explain why getBinaryStream()  is used and the purpose of variable 'offset' in the following function?
++++++++++++++++++++++
      public AssessTestType select(String typeId) {
            log.debug("start");
            String sql =
                  "SELECT test_type_title, test_template_xml, test_template_xsl"
                        + " FROM Assess_Test_Types WHERE assess_test_type_id="
                        + typeId;

            AssessTestType testType = null;
            Statement stmt = null;
            ResultSet rs = null;

            try {
                  stmt = db.createStatement();
                  rs = stmt.executeQuery(sql);

                  if (rs.next()) {
                        testType = new AssessTestType();
                        testType.setTestTypeId(typeId);
                        testType.setTypeTitle(rs.getString("test_type_title"));

                        String[] bfileNames =
                              { "test_template_xml", "test_template_xsl" };
                        String[] xmlXslOut = new String[2];

                        try {
                              for (int i = 0; i < 2; i++) {
                                    StringBuffer tmpBuffer = new StringBuffer();
                                    // Note : Using Oracle Extension oracle.sql.BFILE to get BFILE Locator
                                    oracle.sql.BFILE bfile = null;
                                    bfile = ((OracleResultSet) rs).getBFILE(bfileNames[i]);
                                    
                                    if (bfile == null) {
                                          if ("test_template_xsl".equals(bfileNames[i])) {
                                                xmlXslOut[i] = getGenericXSL();
                                          }
                                    } else { // bfile is not null

                                          // Get the BFILE Locator
                                          // Open the file with openFile Method of oracle.sql.BFILE class
                                          bfile.openFile();

                                          InputStream is = bfile.getBinaryStream();
                                          int offset = 1024;
                                          int len = 0;
                                          byte[] buffer = new byte[offset];

                                          while ((len = is.read(buffer)) > 0) {
                                                tmpBuffer.append(new String(buffer, 0, len));
                                          }
                                          xmlXslOut[i] = tmpBuffer.toString();
                                          log.debug(
                                                "String Size: "
                                                      + xmlXslOut[i].getBytes().length);
                                          log.debug("Returned XML: \n" + xmlXslOut[i]);

                                          is.close();
                                          bfile.closeFile();

                                          is = null;
                                    }
                              }
                        } catch (SQLException e) {
                              log.error(e);
                        } catch (IOException e) {
                              log.error(e);
                        }

                        testType.setXmlTemplate(xmlXslOut[0]);
                        testType.setHtmlXSLFile(xmlXslOut[1]);

                  }
            } catch (SQLException e) {
                  log.error(e);
            } finally {
                  try {
                        if (rs != null)
                              rs.close();
                        if (stmt != null)
                              stmt.close();
                  } catch (SQLException e1) {
                        log.error(e1);
                  }
            }

            return testType;
      }
++++++++++++
thanks,
0
Comment
Question by:dkim18
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 125 total points
ID: 12342372
These are binary fields to hold files that are being retrieved, hence the use of streams to get the files. Personally i think CLOB should be used or Unicode can't really be supported without doing one's own decoding
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12342393
'offset' is a misleading name. All it does in the above is to specify the buffer size for the file read
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses

624 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question