1 /*
   2  * Copyright (c) 2013, 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
  23  * questions.
  24  */
  25 
  26 package sun.corba;
  27 
  28 import com.sun.corba.se.impl.corba.AnyImpl;
  29 import com.sun.corba.se.impl.encoding.BufferManagerWrite;
  30 import com.sun.corba.se.impl.encoding.CDROutputObject;
  31 import com.sun.corba.se.impl.encoding.EncapsOutputStream;
  32 import com.sun.corba.se.impl.encoding.TypeCodeOutputStream;
  33 import com.sun.corba.se.impl.protocol.giopmsgheaders.Message;
  34 
  35 import com.sun.corba.se.pept.protocol.MessageMediator;
  36 
  37 import com.sun.corba.se.spi.orb.ORB;
  38 import com.sun.corba.se.spi.transport.CorbaConnection;
  39 import com.sun.corba.se.spi.ior.iiop.GIOPVersion;
  40 import com.sun.corba.se.spi.protocol.CorbaMessageMediator;
  41 
  42 import java.security.AccessController;
  43 import java.security.PrivilegedAction;
  44 
  45 public final class OutputStreamFactory {
  46 
  47     private OutputStreamFactory() {
  48     }
  49 
  50     public static TypeCodeOutputStream newTypeCodeOutputStream(
  51             final ORB orb) {
  52         return AccessController.doPrivileged(
  53             new PrivilegedAction<TypeCodeOutputStream>() {
  54                 @Override
  55                 public TypeCodeOutputStream run() {
  56                     return new TypeCodeOutputStream(orb);
  57                 }
  58         });
  59     }
  60 
  61     public static TypeCodeOutputStream newTypeCodeOutputStream(
  62             final ORB orb, final boolean littleEndian) {
  63         return AccessController.doPrivileged(
  64             new PrivilegedAction<TypeCodeOutputStream>() {
  65                 @Override
  66                 public TypeCodeOutputStream run() {
  67                     return new TypeCodeOutputStream(orb, littleEndian);
  68                 }
  69         });
  70     }
  71 
  72     public static EncapsOutputStream newEncapsOutputStream(
  73             final ORB orb) {
  74         return AccessController.doPrivileged(
  75             new PrivilegedAction<EncapsOutputStream>() {
  76                 @Override
  77                 public EncapsOutputStream run() {
  78                     return new EncapsOutputStream(
  79                         (com.sun.corba.se.spi.orb.ORB)orb);
  80                 }
  81         });
  82     }
  83 
  84     public static EncapsOutputStream newEncapsOutputStream(
  85             final ORB orb, final GIOPVersion giopVersion) {
  86         return AccessController.doPrivileged(
  87             new PrivilegedAction<EncapsOutputStream>() {
  88                 @Override
  89                 public EncapsOutputStream run() {
  90                     return new EncapsOutputStream(
  91                         (com.sun.corba.se.spi.orb.ORB)orb, giopVersion);
  92                 }
  93         });
  94     }
  95 
  96     public static EncapsOutputStream newEncapsOutputStream(
  97             final ORB orb, final boolean isLittleEndian) {
  98         return AccessController.doPrivileged(
  99             new PrivilegedAction<EncapsOutputStream>() {
 100                 @Override
 101                 public EncapsOutputStream run() {
 102                     return new EncapsOutputStream(
 103                         (com.sun.corba.se.spi.orb.ORB)orb, isLittleEndian);
 104                 }
 105         });
 106     }
 107 
 108     public static CDROutputObject newCDROutputObject(
 109             final ORB orb, final MessageMediator messageMediator,
 110             final Message header, final byte streamFormatVersion) {
 111         return AccessController.doPrivileged(
 112             new PrivilegedAction<CDROutputObject>() {
 113                 @Override
 114                 public CDROutputObject run() {
 115                     return new CDROutputObject(orb, messageMediator,
 116                         header, streamFormatVersion);
 117                 }
 118         });
 119     }
 120 
 121     public static CDROutputObject newCDROutputObject(
 122             final ORB orb, final MessageMediator messageMediator,
 123             final Message header, final byte streamFormatVersion,
 124             final int strategy) {
 125         return AccessController.doPrivileged(
 126             new PrivilegedAction<CDROutputObject>() {
 127                 @Override
 128                 public CDROutputObject run() {
 129                     return new CDROutputObject(orb, messageMediator,
 130                         header, streamFormatVersion, strategy);
 131                 }
 132         });
 133     }
 134 
 135     public static CDROutputObject newCDROutputObject(
 136             final ORB orb, final CorbaMessageMediator mediator,
 137             final GIOPVersion giopVersion, final CorbaConnection connection,
 138             final Message header, final byte streamFormatVersion) {
 139         return AccessController.doPrivileged(
 140             new PrivilegedAction<CDROutputObject>() {
 141                 @Override
 142                 public CDROutputObject run() {
 143                     return new CDROutputObject(orb, mediator,
 144                         giopVersion, connection, header, streamFormatVersion);
 145                 }
 146         });
 147     }
 148 
 149 }