Solved

bFile and getBinaryStream()

Posted on 2004-10-18
5
554 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
  • 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
 
LVL 92

Expert Comment

by:objects
ID: 12342833
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

770 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