code: public static byte[] convertStringToBinary(String text,String encoding)
      {
          byte[] data=null;
          if(text!=null)
          {
              if(text.length()==0)
              {
                  data=new byte[0];
              }
              else
              {
                  //get logger
                  LoggerManager loggerManager=LoggerManager.getInstance();
                  Logger logger=loggerManager.getLogger();
  
                  String encodingToUse=encoding;
                  if((encodingToUse!=null)&&(encodingToUse.length()>0))
                  {
                      try
                      {
                          data=text.getBytes(encodingToUse);
                      }
                      catch(UnsupportedEncodingException exception)
                      {
                          logger.logError(new Object[]{"Unable to convert text to binary using encoding: ",encodingToUse," using default system encoding."},exception);
                      }
                  }
                  
                  if(data==null)
                  {
                      encodingToUse=IOHelper.getDefaultEncoding();
  
                      try
                      {
                          data=text.getBytes(encodingToUse);
                      }
                      catch(UnsupportedEncodingException exception)
                      {
                          logger.logError(new Object[]{"Unable to convert text to binary using default encoding: ",encodingToUse},exception);
                          
                          throw new FaxException("Unable to convert text to binary using encoding: "+encodingToUse,exception);
                      }
                  }
              }
          }
          
          return data;
      }
docs: This function converts the provided string to binary data.
  
  @param   text
  The text to convert
  @param   encoding
  The text encoding
  @return  The binary data