Ejemplo n.º 1
0
 /**
  * Encodes an array of bytes into an array of quoted-printable 7-bit characters. Unsafe characters are escaped.
  *
  * <p>
  * This function implements a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in
  * RFC 1521 and is suitable for encoding binary data and unformatted text.
  * </p>
  *
  * @param printable
  *                  bitset of characters deemed quoted-printable
  * @param bytes
  *                  array of bytes to be encoded
  * @return array of bytes containing quoted-printable data
  */
 public static byte[] encodeQuotedPrintable(java.util.BitSet printable, byte[] bytes)
 {
     if (bytes == null)
     {
         return(null);
     }
     if (printable == null)
     {
         printable = PRINTABLE_CHARS;
     }
     java.io.ByteArrayOutputStream buffer = new java.io.ByteArrayOutputStream();
     for (int i = 0; i < bytes.Length; i++)
     {
         int b = bytes[i];
         if (b < 0)
         {
             b = 256 + b;
         }
         if (printable.get(b))
         {
             buffer.write(b);
         }
         else
         {
             encodeQuotedPrintable(b, buffer);
         }
     }
     return(buffer.toByteArray());
 }
Ejemplo n.º 2
0
 /**
  * Construct a Comparator chain with a single Comparator,
  * sorting in the given order
  *
  * @param comparator First Comparator in the ComparatorChain
  * @param reverse    false = forward sort; true = reverse sort
  */
 public ComparatorChain(java.util.Comparator <Object> comparator, bool reverse)
 {
     comparatorChain = new java.util.ArrayList <Object>();
     comparatorChain.add(comparator);
     orderingBits = new java.util.BitSet(1);
     if (reverse == true)
     {
         orderingBits.set(0);
     }
 }
 /**
  * Returns <code>true</code> iff any bit in the given set is
  * <code>true</code>.
  */
 private bool anyValueSet(java.util.BitSet set)
 {
     for (int i = 0; i < set.size(); i++)
     {
         if (set.get(i))
         {
             return(true);
         }
     }
     return(false);
 }
        // Private Methods
        // -------------------------------------------------------------------

        /**
         * Initializes the collating state if it hasn't been already.
         */
        private void start()
        {
            if (values == null)
            {
                values   = new java.util.ArrayList <Object>(iterators.size());
                valueSet = new java.util.BitSet(iterators.size());
                for (int i = 0; i < iterators.size(); i++)
                {
                    values.add(null);
                    valueSet.clear(i);
                }
            }
        }
Ejemplo n.º 5
0
        /**
         * Encodes an array of bytes into an array of URL safe 7-bit characters. Unsafe characters are escaped.
         *
         * @param urlsafe
         *            bitset of characters deemed URL safe
         * @param bytes
         *            array of bytes to convert to URL safe characters
         * @return array of bytes containing URL safe characters
         */
        public static byte[] encodeUrl(java.util.BitSet urlsafe, byte[] bytes)
        {
            if (bytes == null)
            {
                return(null);
            }
            if (urlsafe == null)
            {
                urlsafe = WWW_FORM_URL;
            }

            java.io.ByteArrayOutputStream buffer = new java.io.ByteArrayOutputStream();
            for (int i = 0; i < bytes.Length; i++)
            {
                int b = bytes[i];
                if (b < 0)
                {
                    b = 256 + b;
                }
                if (urlsafe.get(b))
                {
                    if (b == ' ')
                    {
                        b = '+';
                    }
                    buffer.write(b);
                }
                else
                {
                    buffer.write(ESCAPE_CHAR);
                    char hex1 = java.lang.Character.toUpperCase(java.lang.Character.forDigit((b >> 4) & 0xF, RADIX));
                    char hex2 = java.lang.Character.toUpperCase(java.lang.Character.forDigit(b & 0xF, RADIX));
                    buffer.write(hex1);
                    buffer.write(hex2);
                }
            }
            return(buffer.toByteArray());
        }
Ejemplo n.º 6
0
 /**
  * Construct a ComparatorChain from the Comparators in the
  * given List.  The sort order of each column will be
  * drawn from the given BitSet.  When determining the sort
  * order for Comparator at index <i>i</i> in the List,
  * the ComparatorChain will call BitSet.get(<i>i</i>).
  * If that method returns <i>false</i>, the forward
  * sort order is used; a return value of <i>true</i>
  * indicates reverse sort order.
  *
  * @param list   List of Comparators.  NOTE: This constructor does not perform a
  *               defensive copy of the list
  * @param bits   Sort order for each Comparator.  Extra bits are ignored,
  *               unless extra Comparators are added by another method.
  */
 public ComparatorChain(java.util.List <Object> list, java.util.BitSet bits)
 {
     comparatorChain = list;
     orderingBits    = bits;
 }