Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

bFile and getBinaryStream()

Posted on 2004-10-18
5
Medium Priority
?
586 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
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses

773 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