⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bits.java

📁 CmisJavaApi
💻 JAVA
字号:
/* * The contents of this file are subject to the Dyade Public License,  * as defined by the file DYADE_PUBLIC_LICENSE.TXT * * You may not use this file except in compliance with the License. You may * obtain a copy of the License on the Dyade web site (www.dyade.fr). * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for * the specific terms governing rights and limitations under the License. * * The Original Code is CmisJava API, including the java package  * fr.dyade.cmis, released September 5, 2000. * * The Initial Developer of the Original Code is Dyade. The Original Code and * portions created by Dyade are Copyright Bull and Copyright INRIA.  * All Rights Reserved. *//*      Copyright 1996-2000 by Institut National de Recherche en Informatique  *                             et en Automatique (INRIA) *          All rights reserved.  See COPYRIGHT in top-level directory. * *      Authors: Laurent Andrey, Eric Dillon, Olivier Festor */// $Id: Bits.java,v 1.2 2000/09/05 13:30:33 festor Exp $// $Source: /local/resedas/CVS-Repository/CmisJavaApi/src/fr/dyade/cmis/api/types/Bits.java,v $//// ToDopackage fr.dyade.cmis.api.types;import java.util.Enumeration;/**  * Top level class for Java representation for ASN.1 BitString&Any datatypes.  * <p>  * The Java type is implemented according to the C-fmkapi, ie. with an array of <code>byte</code>.  * However, the user should not instantiate this class, since the "Value discriminant" inherited from  * {@link fr.dyade.cmis.api.types.Value Value} is not set.  * Indeed Bits is used in External... So the user can create a Bits that is not really a Value   * (ValueType set to VALUE_UNKNOWN). See the only public constructor. This kind of instance MUST NOT be used as Value.  * @see fr.dyade.cmis.api.types.BitString  * @see fr.dyade.cmis.api.types.External  * @version cvs $Id: Bits.java,v 1.2 2000/09/05 13:30:33 festor Exp $  */public  class Bits  extends Value {      /** 	* Creates a new instance of Bits, from the given <code>byte</code> array.	* @param pValueType the value for tagging this instance.	* @param pV see public constructor	* @param pBbits see public constructor	* NOTE: use {@link fr.dyade.cmis.api.types.Bits#Bits(byte[], int) public construtor}	*/      protected Bits( short pValueType, byte pV[], int pNbits ) {	 super(pValueType);	 fNbits = pNbits;	 fV = pV;      }      /**	* Creates a new instance of Bits for use in External.	* The new instance  MUST NOT be used as a Value.	* @param pV the binary stuff, NOT NULL. Bit 0 is the most significant bits in pV[0].	* @param pNbits (0<pNbits<=pV.length*8) number of bits to consider from bit 0 in pV.	*	* <p><b>NOTE</b>: The bit string pV is ordered from left to right.	* Furthermore, if the number of bits (pNbits) is not a multiple	* of 8, only the higher bits are used in the last    octet.   	* <p>Example:<p>	* for the bitstring "1111000011" (number of bits is 10)	* the pV parameter   is  2 octets long: octet 0 = 0xF0   ("11110000") and	* octet 1 = 0xC0   ("11XXXXXX)	* @see fr.dyade.cmis.api.types.External	*/      public Bits( byte pV[], int pNbits ) {	 this(VALUE_UNKNOWN, pV, pNbits);      }      /** Enumeration for individual bits.	* Use cast to java Boolean wrapper when calling <code>java.util.Enumeration.nextElement()</code>	* method of the result. This method garanties to return one of the Boolean TRUE/FALSE singletons.	* @see java.lang.Boolean	*/      public Enumeration getBitsEnumeration() {	 // no anonymous inner class: java 1.1.x does not handle it....	 return new BitsEnumeration(this);      }      /** 	* Returns the <code>byte</code> array represented by this Bits object.	* @return the <code>byte</code> array.	* NOTE: no copy, this method gives direct access to inner representation.	* @see Bits#getBitsEnumeration 	*/      public final byte[] getBits() {	 return fV;      }      /** Number of significant bits.	* @return the number of significant bits from the most significant bits of	* octect 0 in the supporting array of bytes.	*/      public final int getNbits(){	 return fNbits;      }      public boolean isValid() {	 return (fV!=null) && ((0<fNbits) && (fNbits <= fV.length*8));      }      public String toString() {	 String res="";	 for (Enumeration e=getBitsEnumeration();e.hasMoreElements();) {	    res += (((Boolean)e.nextElement()).booleanValue())?"1":"0";	 }	 return res;      }      protected int fNbits;      protected byte fV[];      class BitsEnumeration implements Enumeration {	    BitsEnumeration( Bits pThis ) {	       fThis=pThis;	    } 	    public final boolean  hasMoreElements(){	       return lIdx<fThis.fNbits;	    }	    public final Object nextElement() {	       synchronized(fThis) {		  if (lIdx<fThis.fNbits) {		     if ((lIdx % 8) == 0) {			fCurrentByte=fThis.fV[lIdx/8];		     } else {			fCurrentByte<<=1;		     }		     lIdx++;		     // A peek to java.lang.Boolean source does show that Boolean(boolean) creator		     // returns unique instance TRUE or FALSE... Event if Boolean looks 		     // pretty unmutable... so do so !		     return ((fCurrentByte&-127)!=0)?Boolean.TRUE:Boolean.FALSE;		  }		  throw new java.util.NoSuchElementException("Bits Enumeration");	       }	    }	    private Bits fThis;	    private int lIdx;	    private byte fCurrentByte;      }} // Bits

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -