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

📄 bytes.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 *///---------------------------------------------------------------------------////  CVS Info//---------------------------------------------------------------------------//////  $Id: Bytes.java,v 1.2 2000/09/05 13:30:34 festor Exp $//  $Source: /local/resedas/CVS-Repository/CmisJavaApi/src/fr/dyade/cmis/api/types/Bytes.java,v $//---------------------------------------------------------------------------////  Todo//---------------------------------------------------------------------------////package fr.dyade.cmis.api.types;// java related packagesimport java.lang.*;/**  *  Top level class for Java representation of all ASN.1 *String datatypes.  * <p>  * These Java datatypes follow the implementation described in the C-fmkapi,   * ie.  an array of <code>byte</code>s.  * <p>  * However, the user should not instantiate this class, because it does not set the   * "Value discriminant" field inherited from {@link fr.dyade.cmis.api.types.Value Value}.  * But indeed he can use it to create External type fields. In this case  * we want a Byte that is not an ASN1 value (ValueType set to VALUE_UNKNOWN).   * See the only public constructor. This kind of instance MUST NOT be used as Value.  * Yes, sure, there is something wrong in this class hierarchy design.  *  * @see fr.dyade.cmis.api.types.NumericString  * @see fr.dyade.cmis.api.types.PrintableString  * @see fr.dyade.cmis.api.types.TeletexString  * @see fr.dyade.cmis.api.types.VideotexString  * @see fr.dyade.cmis.api.types.IA5String  * @see fr.dyade.cmis.api.types.GraphicString  * @see fr.dyade.cmis.api.types.VisibleString  * @see fr.dyade.cmis.api.types.Verbatim  * @see fr.dyade.cmis.api.types.OctetString  * @see fr.dyade.cmis.api.types.ValueDescriptor  * @see fr.dyade.cmis.api.types.GeneralString  * @see fr.dyade.cmis.api.types.IPAddress  * @see fr.dyade.cmis.api.types.Opaque  * @see fr.dyade.cmis.api.types.NSAPAddress  * @see fr.dyade.cmis.api.types.Any  * @see fr.dyade.cmis.api.types.External  *  * @version cvs $Id: Bytes.java,v 1.2 2000/09/05 13:30:34 festor Exp $  */public  class Bytes extends Value implements Comparable {      /**	* Creates a new instance of Bytes.	* <strong>This method is only call by other class inheriting <code>Bytes</code></strong>.	* @param pV The <code>byte</code> used to represent the ASN.1 String.	*/      protected Bytes(short pValueType, byte pV[]) {	 super(pValueType);	 fV = pV;      }      /** Creates a new intance of Bytes for use in External class or nonSpecificForm of ObjectInstance	* The new instance  MUST NOT be use as a Value.	* @see fr.dyade.cmis.api.types.External	* @see fr.dyade.cmis.api.types.ObjectIdentifier	*/      public Bytes(byte pV[]) {	 this(VALUE_UNKNOWN, pV);      }      /** String form for an ASN1 bytes;	* @return a new string build from the internal array of bytes.	* NOTE: this string value is not obviously meaningful. This is NOT the ascii string	* containing the hexa or decimal form for the internal stuff of Byte, but	* a string which displays internal stuff as legal ascii code. 	*/      public String toString(){	 // optimization ?	 return (fV!=null)?new String(fV):"";      }      /** List Byte elements in decimal UNSIGNED form, as a string.	* @return the elements of the Byte for left to right in decimal form separated by a space, or	* empty string if internal stuff is null.	*/      public String toDecimalString(){	 if (fV==null) return "";	 String res="";	 for (int i=0; i<fV.length; i++) {	    res+=Integer.toString(fV[i]<0?256+fV[i]:fV[i])+" ";	 }	 return res;      }      /** List Byte elements in hexadecimal form, as a string.	* @return the elements of the Bytes for left to right in hexadecimal with 	* <b>two</b> digits for each byte - or	* empty string if internal stuff is null.	*/      public String toHexaString(){	 if (fV==null) return "";	 String res="";	 for (int i=0; i<fV.length; i++) {	    String s=Integer.toHexString(fV[i]<0?256+fV[i]:fV[i]);	    res+=((s.length()<2)? "0"+s:s);	 }	 return res;      }      /**	* To compare equality of Bytes	* Mandatory to use Byte (and derived classes) in hastable. 	* @return true, if both <code>ObjectIdentifiers</code> have the same value.	*/      public boolean equals( Object other ){	 byte otherV[] = ((Bytes)other).fV;      	 if (otherV.length == fV.length) {	    int i;	    for (i=0; i<fV.length; i++)	       if (fV[i] != otherV[i])		  return false;	    return true;	 }	 	 return false;      }      /** Get internal bytes.	* @return the array of java <code>byte</code> that supports 	* this <code>Bytes</code> object.	* <p>NOTE: Beware this method return a reference to an inner field of the 	* <code>Bytes</code> object, so any change in this array would	* change the object itself. 	* @see Bytes#getUnsignedBytes()	*/      public final byte[] getBytes() {	 return fV;      }      /**	* To compare 2 Bytes	* Mandatory to use Byte (and derived classes) in ordered container.	* @return a negative integer, zero, or a positive integer 	* as this Object is less than, equal to, or greater than the given Object	* Mandatory by Comparable interface.	*/      public int compareTo(Object other) {	  byte otherV[] = ((Bytes)other).fV;	  int lgThis=fV.length;	  int lgOther=otherV.length;	  int min=(lgThis<lgOther)?lgThis:lgOther;	  for (int i=0; i<min; i++) {	     int vThis=fV[i];	     int vOther=otherV[i];	     if (vThis<vOther) return -1;	     if (vThis>vOther) return 1;	  }	  // the shorter is a prefix of the longer...	  if (lgThis<lgOther) return -1;	  if (lgThis>lgOther) return 1;	  return 0;      }      /** Hash function to allow use as index.	* Mandatory to use Bytes in hastable.	* TODO: PROFIL this function.	* @see java.lang.Object#hashCode	*/      public int hashCode(){	 switch(fV.length) {	    case 0: return 0; 	    case 1: return fV[0]; 	       //LA: don't ask me why such a formula !!!! 	       // -- Just believing that prefixes are more common than suffixes	    default: return fV[fV.length-1]*10+fV[0];	 }      }      /** Get internal stuff as UNSIGNED byte.	* @return an array of POSITIVE integer (int) between 0 and 255.	* <p>NOTE: this array is calcultated from <code>fV</code> internal	* field each time this method is invoked.	*/      public final int[] getUnsignedBytes() {	 int[] res=new int[fV.length];	 for (int i=0; i<fV.length; i++) {	    res[i]=(fV[i]<0)?256+fV[i]:fV[i];	 }	 return res;      }      protected byte fV[];      //only byte stuff are shipped by Serialization      //transient private int[] fV_unsigned;}

⌨️ 快捷键说明

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