Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  //  The contents of this file are subject to the Mozilla Public License
  //  Version 1.1 (the "License"); you may not use this file except in
  //  compliance with the License. You may obtain a copy of the License
  //  at http://www.mozilla.org/MPL/
  //
  //  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 language governing rights and
  //  limitations under the License.
 //
 //  The Original Code is RabbitMQ.
 //
 //  The Initial Developer of the Original Code is VMware, Inc.
 //  Copyright (c) 2007-2011 VMware, Inc.  All rights reserved.
 //
 
 
 package com.rabbitmq.client.impl;
 
 
Utility for working with com.rabbitmq.client.LongStrings.
 
 public class LongStringHelper
 {
    
Private API - Implementation of com.rabbitmq.client.LongString. When interpreting bytes as a string, uses UTF-8 encoding.
 
     private static class ByteArrayLongString
         implements LongString
     {
         private byte [] bytes;
 
         public ByteArrayLongString(byte[] bytes)
         {
             this. = bytes;
         }
 
         @Override public boolean equals(Object o)
         {
             if(o instanceof LongString) {
                 LongString other = (LongString)o;
                 return Arrays.equals(this.other.getBytes());
             }
 
             return false;
         }
 
         @Override public int hashCode()
         {
            return Arrays.hashCode(this.);
         }

        
 
         public byte[] getBytes()
         {
             return ;
         }

        
 
         public DataInputStream getStream()
             throws IOException
         {
             return new DataInputStream(new ByteArrayInputStream());
         }

        
 
         public long length()
         {
             return .;
         }
 
         @Override public String toString()
         {
             try {
                 return new String("utf-8");
             }
             catch (UnsupportedEncodingException e) {
                 throw new Error("utf-8 encoding support required");
             }
         }
     }

    
Converts a String to a LongString using UTF-8 encoding.

Parameters:
string the string to wrap
Returns:
a LongString wrapping it
 
     public static LongString asLongString(String string)
     {
         if (string==nullreturn null;
        try {
            return new ByteArrayLongString(string.getBytes("utf-8"));
        }
        catch (UnsupportedEncodingException e) {
            throw new Error("utf-8 encoding support required");
        }
    }

    
Converts a binary block to a LongString.

Parameters:
bytes the data to wrap
Returns:
a LongString wrapping it
    public static LongString asLongString(byte [] bytes)
    {
        if (bytes==nullreturn null;
        return new ByteArrayLongString(bytes);
    }
New to GrepCode? Check out our FAQ X