corba/src/share/classes/com/sun/corba/se/impl/encoding/CDRInputStream_1_0.java

Print this page
rev 502 : 8000631: Restrict access to class constructor
Reviewed-by: alanb, ahgross
   1 /*
   2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 252             CORBALogDomains.RPC_ENCODING ) ;
 253         this.omgWrapper = OMGSystemException.get( (ORB)orb,
 254             CORBALogDomains.RPC_ENCODING ) ;
 255         this.littleEndian = littleEndian;
 256         this.bufferManagerRead = bufferManager;
 257         this.bbwi = new ByteBufferWithInfo(orb,byteBuffer,0);
 258         this.bbwi.buflen = size;
 259         this.bbwi.byteBuffer.limit(bbwi.buflen);
 260         this.markAndResetHandler = bufferManagerRead.getMarkAndResetHandler();
 261 
 262         debug = ((ORB)orb).transportDebugFlag;
 263     }
 264 
 265     // See description in CDRInputStream
 266     void performORBVersionSpecificInit() {
 267         createRepositoryIdHandlers();
 268     }
 269 
 270     private final void createRepositoryIdHandlers()
 271     {
 272         repIdUtil = RepositoryIdFactory.getRepIdUtility(orb);
 273         repIdStrs = RepositoryIdFactory.getRepIdStringsFactory(orb);
 274     }
 275 
 276     public GIOPVersion getGIOPVersion() {
 277         return GIOPVersion.V1_0;
 278     }
 279 
 280     // Called by Request and Reply message. Valid for GIOP versions >= 1.2 only.
 281     // Illegal for GIOP versions < 1.2.
 282     void setHeaderPadding(boolean headerPadding) {
 283         throw wrapper.giopVersionError();
 284     }
 285 
 286     protected final int computeAlignment(int index, int align) {
 287         if (align > 1) {
 288             int incr = index & (align - 1);
 289             if (incr != 0)
 290                 return align - incr;
 291         }
 292 
 293         return 0;


 547             throw wrapper.negativeStringLength( CompletionStatus.COMPLETED_MAYBE,
 548                 new Integer(length) ) ;
 549     }
 550 
 551     protected final String readStringOrIndirection(boolean allowIndirection) {
 552 
 553         int len = read_long();
 554 
 555         //
 556         // Check for indirection
 557         //
 558         if (allowIndirection) {
 559             if (len == 0xffffffff)
 560                 return null;
 561             else
 562                 stringIndirection = get_offset() - 4;
 563         }
 564 
 565         checkForNegativeLength(len);
 566 
 567         if (orb != null && ORBUtility.isLegacyORB((ORB)orb))
 568             return legacyReadString(len);
 569         else
 570             return internalReadString(len);
 571     }
 572 
 573     private final String internalReadString(int len) {
 574         // Workaround for ORBs which send string lengths of
 575         // zero to mean empty string.
 576         //
 577         // IMPORTANT: Do not replace 'new String("")' with "", it may result
 578         // in a Serialization bug (See serialization.zerolengthstring) and
 579         // bug id: 4728756 for details
 580         if (len == 0)
 581             return new String("");
 582 
 583         char[] result = getConvertedChars(len - 1, getCharConverter());
 584 
 585         // Skip over the 1 byte null
 586         read_octet();
 587 
 588         return new String(result, 0, getCharConverter().getNumChars());
 589     }
 590 
 591     private final String legacyReadString(int len) {
 592 
 593         //
 594         // Workaround for ORBs which send string lengths of
 595         // zero to mean empty string.
 596         //
 597         //
 598         // IMPORTANT: Do not replace 'new String("")' with "", it may result
 599         // in a Serialization bug (See serialization.zerolengthstring) and
 600         // bug id: 4728756 for details
 601         if (len == 0)
 602             return new String("");
 603 
 604         len--;
 605         char[] c = new char[len];
 606 
 607         int n = 0;
 608         while (n < len) {
 609             int avail;
 610             int bytes;
 611             int wanted;
 612 
 613             avail = bbwi.buflen - bbwi.position();
 614             if (avail <= 0) {
 615                 grow(1, 1);
 616                 avail = bbwi.buflen - bbwi.position();
 617             }
 618             wanted = len - n;
 619             bytes = (wanted < avail) ? wanted : avail;
 620             // Microbenchmarks are showing a loop of ByteBuffer.get(int) being
 621             // faster than ByteBuffer.get(byte[], int, int).
 622             for (int i=0; i<bytes; i++) {
 623                 c[n+i] = (char) (bbwi.byteBuffer.get(bbwi.position()+i) & 0xFF);
 624             }
 625             bbwi.position(bbwi.position() + bytes);
 626             n += bytes;
 627         }
 628 
 629         //
 630         // Skip past terminating null byte
 631         //
 632         if (bbwi.position() + 1 > bbwi.buflen)
 633             alignAndCheck(1, 1);
 634         bbwi.position(bbwi.position() + 1);
 635 
 636         return new String(c);
 637     }
 638 
 639     public final String read_string() {
 640         return readStringOrIndirection(false);
 641     }
 642 
 643     public String read_wstring() {
 644         // Don't allow transmission of wchar/wstring data with
 645         // foreign ORBs since it's against the spec.
 646         if (ORBUtility.isForeignORB((ORB)orb)) {
 647             throw wrapper.wcharDataInGiop10( CompletionStatus.COMPLETED_MAYBE);
 648         }
 649 
 650         int len = read_long();
 651 
 652         //
 653         // Workaround for ORBs which send string lengths of
 654         // zero to mean empty string.
 655         //
 656         //
 657         // IMPORTANT: Do not replace 'new String("")' with "", it may result
 658         // in a Serialization bug (See serialization.zerolengthstring) and


1028                 // class information is not available.
1029                 throw wrapper.couldNotFindClass(
1030                     CompletionStatus.COMPLETED_MAYBE,
1031                     new ClassNotFoundException());
1032             }
1033 
1034             if (valueClass != null &&
1035                 org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(valueClass)) {
1036 
1037                 value =  readIDLValue(indirection,
1038                                       repositoryIDString,
1039                                       valueClass,
1040                                       codebase_URL);
1041 
1042             } else {
1043 
1044                 // Must be some form of RMI-IIOP valuetype
1045 
1046                 try {
1047                     if (valueHandler == null)
1048                         valueHandler = ORBUtility.createValueHandler(orb);
1049 
1050                     value = valueHandler.readValue(parent,
1051                                                    indirection,
1052                                                    valueClass,
1053                                                    repositoryIDString,
1054                                                    getCodeBase());
1055 
1056                 } catch(SystemException sysEx) {
1057                     // Just rethrow any CORBA system exceptions
1058                     // that come out of the ValueHandler
1059                     throw sysEx;
1060                 } catch(Exception ex) {
1061                     throw wrapper.valuehandlerReadException(
1062                         CompletionStatus.COMPLETED_MAYBE, ex ) ;
1063                 } catch(Error e) {
1064                     throw wrapper.valuehandlerReadError(
1065                         CompletionStatus.COMPLETED_MAYBE, e ) ;
1066                 }
1067             }
1068         }


   1 /*
   2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


 252             CORBALogDomains.RPC_ENCODING ) ;
 253         this.omgWrapper = OMGSystemException.get( (ORB)orb,
 254             CORBALogDomains.RPC_ENCODING ) ;
 255         this.littleEndian = littleEndian;
 256         this.bufferManagerRead = bufferManager;
 257         this.bbwi = new ByteBufferWithInfo(orb,byteBuffer,0);
 258         this.bbwi.buflen = size;
 259         this.bbwi.byteBuffer.limit(bbwi.buflen);
 260         this.markAndResetHandler = bufferManagerRead.getMarkAndResetHandler();
 261 
 262         debug = ((ORB)orb).transportDebugFlag;
 263     }
 264 
 265     // See description in CDRInputStream
 266     void performORBVersionSpecificInit() {
 267         createRepositoryIdHandlers();
 268     }
 269 
 270     private final void createRepositoryIdHandlers()
 271     {
 272         repIdUtil = RepositoryIdFactory.getRepIdUtility();
 273         repIdStrs = RepositoryIdFactory.getRepIdStringsFactory();
 274     }
 275 
 276     public GIOPVersion getGIOPVersion() {
 277         return GIOPVersion.V1_0;
 278     }
 279 
 280     // Called by Request and Reply message. Valid for GIOP versions >= 1.2 only.
 281     // Illegal for GIOP versions < 1.2.
 282     void setHeaderPadding(boolean headerPadding) {
 283         throw wrapper.giopVersionError();
 284     }
 285 
 286     protected final int computeAlignment(int index, int align) {
 287         if (align > 1) {
 288             int incr = index & (align - 1);
 289             if (incr != 0)
 290                 return align - incr;
 291         }
 292 
 293         return 0;


 547             throw wrapper.negativeStringLength( CompletionStatus.COMPLETED_MAYBE,
 548                 new Integer(length) ) ;
 549     }
 550 
 551     protected final String readStringOrIndirection(boolean allowIndirection) {
 552 
 553         int len = read_long();
 554 
 555         //
 556         // Check for indirection
 557         //
 558         if (allowIndirection) {
 559             if (len == 0xffffffff)
 560                 return null;
 561             else
 562                 stringIndirection = get_offset() - 4;
 563         }
 564 
 565         checkForNegativeLength(len);
 566 



 567         return internalReadString(len);
 568     }
 569 
 570     private final String internalReadString(int len) {
 571         // Workaround for ORBs which send string lengths of
 572         // zero to mean empty string.
 573         //
 574         // IMPORTANT: Do not replace 'new String("")' with "", it may result
 575         // in a Serialization bug (See serialization.zerolengthstring) and
 576         // bug id: 4728756 for details
 577         if (len == 0)
 578             return new String("");
 579 
 580         char[] result = getConvertedChars(len - 1, getCharConverter());
 581 
 582         // Skip over the 1 byte null
 583         read_octet();
 584 
 585         return new String(result, 0, getCharConverter().getNumChars());
 586     }
 587 
















































 588     public final String read_string() {
 589         return readStringOrIndirection(false);
 590     }
 591 
 592     public String read_wstring() {
 593         // Don't allow transmission of wchar/wstring data with
 594         // foreign ORBs since it's against the spec.
 595         if (ORBUtility.isForeignORB((ORB)orb)) {
 596             throw wrapper.wcharDataInGiop10( CompletionStatus.COMPLETED_MAYBE);
 597         }
 598 
 599         int len = read_long();
 600 
 601         //
 602         // Workaround for ORBs which send string lengths of
 603         // zero to mean empty string.
 604         //
 605         //
 606         // IMPORTANT: Do not replace 'new String("")' with "", it may result
 607         // in a Serialization bug (See serialization.zerolengthstring) and


 977                 // class information is not available.
 978                 throw wrapper.couldNotFindClass(
 979                     CompletionStatus.COMPLETED_MAYBE,
 980                     new ClassNotFoundException());
 981             }
 982 
 983             if (valueClass != null &&
 984                 org.omg.CORBA.portable.IDLEntity.class.isAssignableFrom(valueClass)) {
 985 
 986                 value =  readIDLValue(indirection,
 987                                       repositoryIDString,
 988                                       valueClass,
 989                                       codebase_URL);
 990 
 991             } else {
 992 
 993                 // Must be some form of RMI-IIOP valuetype
 994 
 995                 try {
 996                     if (valueHandler == null)
 997                         valueHandler = ORBUtility.createValueHandler();
 998 
 999                     value = valueHandler.readValue(parent,
1000                                                    indirection,
1001                                                    valueClass,
1002                                                    repositoryIDString,
1003                                                    getCodeBase());
1004 
1005                 } catch(SystemException sysEx) {
1006                     // Just rethrow any CORBA system exceptions
1007                     // that come out of the ValueHandler
1008                     throw sysEx;
1009                 } catch(Exception ex) {
1010                     throw wrapper.valuehandlerReadException(
1011                         CompletionStatus.COMPLETED_MAYBE, ex ) ;
1012                 } catch(Error e) {
1013                     throw wrapper.valuehandlerReadError(
1014                         CompletionStatus.COMPLETED_MAYBE, e ) ;
1015                 }
1016             }
1017         }