Solved

bFile and getBinaryStream()

Posted on 2004-10-18
5
551 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
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…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

914 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now