Returns an EncodingWriter to translate characters to bytes.

@param encoding the encoding name.

@return a writer for the translation
351373
public static EncodingWriter getWriteEncoding(String encoding)
  {
    if (encoding == null)
      encoding = "iso-8859-1";

    EncodingWriter factory = _writeEncodingFactories.get(encoding);

    if (factory != null)
      return factory.create();

    factory = _writeEncodingFactories.get(encoding);

    if (factory == null) {
      try {
        String javaEncoding = Encoding.getJavaName(encoding);

        if (javaEncoding == null)
          javaEncoding = "ISO8859_1";

        String className = "com.caucho.v5.vfs.i18n." + javaEncoding + "Writer";

        Class<?> cl = Class.forName(className);

        factory = (EncodingWriter) cl.newInstance();
        factory.setJavaEncoding(javaEncoding);
      } catch (Throwable e) {
      }

      if (factory == null) {
        factory = new JDKWriter();
        String javaEncoding = Encoding.getJavaName(encoding);

        if (javaEncoding == null)
          javaEncoding = "ISO8859_1";
        factory.setJavaEncoding(javaEncoding);
      }

      _writeEncodingFactories.put(encoding, factory);
    }

    // return factory.create(factory.getJavaEncoding());
    // charset uses the original encoding, not the java encoding
    return factory.create(encoding);
  }
67692
public static String format (
            final List <? extends NameValuePair> parameters,
            final String encoding) {
        final StringBuilder result = new StringBuilder();
        for (final NameValuePair parameter : parameters) {
            final String encodedName = encode(parameter.getName(), encoding);
            final String value = parameter.getValue();
            final String encodedValue = value != null ? encode(value, encoding) : "";
            if (result.length() > 0)
                result.append(PARAMETER_SEPARATOR);
            result.append(encodedName);
            result.append(NAME_VALUE_SEPARATOR);
            result.append(encodedValue);
        }
        return result.toString();
    }
750473
public boolean setEncoding(String encoding) {
        for(Map.Entry<Byte, String> entry : CODE_PAGE_ENCODING.entrySet()) {
            if(entry.getValue().equalsIgnoreCase(encoding)) {
                this.fileEncoding = entry.getValue();
                return true;
            }
        }
        return false;
    }
1371185
def get_encoded_writer (out=sys.stdout, encoding=None, errors='replace'):
    """"""
    if encoding is None:
        encoding = default_encoding
    Writer = codecs.getwriter(encoding)
    return Writer(out, errors)
437256
public static OutputStreamWriter getWriter(OutputStream out, String charsetName) {
		return getWriter(out, Charset.forName(charsetName));
	}
454345
public static String inputStreamToString(InputStream x,
            String encoding) throws IOException {

        InputStreamReader in        = new InputStreamReader(x, encoding);
        StringWriter      writer    = new StringWriter();
        int               blocksize = 8 * 1024;
        char[]            buffer    = new char[blocksize];

        for (;;) {
            int read = in.read(buffer);

            if (read == -1) {
                break;
            }

            writer.write(buffer, 0, read);
        }

        writer.close();

        return writer.toString();
    }
372323
public static CharBuffer bytesToChars(CharsetDecoder decoder, ByteBuffer bytes, CharBuffer chars) {
    assert decoder.malformedInputAction() == CodingErrorAction.REPORT;

    chars = clearAndEnsureCapacity(chars, (int) (bytes.remaining() * decoder.maxCharsPerByte()));

    bytes.mark();
    decoder.reset();
    CoderResult cr = decoder.decode(bytes, chars, true);
    if (cr.isError()) {
      bytes.reset();
      try {
        cr.throwException();
      } catch (CharacterCodingException e) {
        throw new RuntimeException("Input cannot be mapped to bytes using encoding "
            + decoder.charset().name() + ": " + Arrays.toString(toArray(bytes)), e);
      }
    }

    assert cr.isUnderflow();  // This should be guaranteed by ensuring max. capacity.
    cr = decoder.flush(chars);
    assert cr.isUnderflow();

    chars.flip();
    bytes.reset();

    return chars;
  }
678487
@Override
    public String getCharacterEncoding() {
        if (null == this.encoding) {
            EncodingUtils encodingUtils = connection.getEncodingUtils();
            this.encoding = encodingUtils.getEncodingFromLocale(this.locale);
            if (null == this.encoding) {
                this.encoding = encodingUtils.getDefaultEncoding();
            }
        }
        return this.encoding;
    }
1074541
public static String encode(byte[] bytes) {
		int bytesLength = bytes.length;
		int base64Length = (bytesLength * 4 + 2) / 3; // base64 encoded string length, without padding

		StringBuilder base64Builder = new StringBuilder();
		int bytesIndex = 0;

		while (bytesIndex < bytesLength) {
			int i0 = bytes[bytesIndex++] & 0xff;
			int i1 = bytesIndex < bytesLength ? bytes[bytesIndex++] & 0xff : 0;
			int i2 = bytesIndex < bytesLength ? bytes[bytesIndex++] & 0xff : 0;

			int o0 = i0 >>> 2;
			int o1 = ((i0 & 3) << 4) | (i1 >>> 4);
			int o2 = ((i1 & 0xf) << 2) | (i2 >>> 6);
			int o3 = i2 & 0x3F;

			base64Builder.append(NIBLES_2_CHARS[o0]);
			base64Builder.append(NIBLES_2_CHARS[o1]);
			base64Builder.append(base64Builder.length() < base64Length ? NIBLES_2_CHARS[o2] : '=');
			base64Builder.append(base64Builder.length() < base64Length ? NIBLES_2_CHARS[o3] : '=');
		}

		return base64Builder.toString();
	}
274734
public static String readStreamToString(InputStream is, String encoding) throws IOException {
		try {
			StringBuilder sb = new StringBuilder();
			byte[] buf = new byte[1024 * 10];
			int read;
			while ((read = is.read(buf)) >= 0) {
				sb.append(new String(buf, 0, read, encoding));
			}
			return sb.toString();
		} finally {
			is.close();
		}
	}
617573
public PrintWriter getWriter() throws IOException, UnsupportedEncodingException {
        final boolean isTraceOn = com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled();
        if (isTraceOn&&logger.isLoggable (Level.FINE))  //306998.15
            logger.entering(CLASS_NAME,"getWriter","gotOutputStream="+String.valueOf(_gotOutputStream)+" ["+this+"]");

        if (!_ignoreStateErrors && _gotOutputStream) {

            if (isTraceOn&&logger.isLoggable (Level.FINE))  //306998.15
                logger.exiting(CLASS_NAME,"getWriter","throw IllegalStateException");

            throw new IllegalStateException(nls.getString("OutputStream.already.obtained", "OutputStream already obtained"));
        }
        if (!_gotWriter) {
            String charEncoding = getCharacterEncoding();

            // begin 249506, part 1 Set content-type charset if not set already
            // begin PK27527  DEFAULT CONTENT-TYPE SETTING ON WEBSPHERE V6.0.X IS "TEXT/PLAN"
            // only add charset if we are in v6 mode.
            if (contentTypeCompatibility==null || (!contentTypeCompatibility.equalsIgnoreCase("V4")&&
                            !contentTypeCompatibility.equalsIgnoreCase("V5"))){
                String contentType = getContentType();
                //PK33871 - added check to make sure the content type started with 'text'.
                if (contentType!=null && contentType.indexOf("charset")==-1 && contentType.startsWith(WebContainerConstants.TEXT))  
                {
                    if (contentType.endsWith(";"))
                        setContentType(contentType + "charset=" + charEncoding);
                    else
                        setContentType(contentType + ";charset=" + charEncoding);
                }
            }
            // end PK27527  DEFAULT CONTENT-TYPE SETTING ON WEBSPHERE V6.0.X IS "TEXT/PLAN"  
            // end 249506, part 1

            //              if ((_outWriter == null) || (writerClosed == true) || (!charEncoding.equals(_outWriterEncoding)))
            if ((_outWriter == null) || (writerException == true) || (!charEncoding.equals(_outWriterEncoding))) {
                if (isTraceOn&&logger.isLoggable (Level.FINE) && writerException){  //306998.15
                    logger.logp(Level.FINE, CLASS_NAME,"getWriter", "writerException --> " + writerException + "--> creating new OutputStreamWriter");
                }
                _outWriter = new OutputStreamWriter(_rawOut, EncodingUtils.getJvmConverter(charEncoding));
                _outWriterEncoding = charEncoding;
                writerException = false;
            }
            else{
                if (isTraceOn&&logger.isLoggable (Level.FINE)){  //306998.15
                    logger.logp(Level.FINE, CLASS_NAME,"getWriter", "reusing _outWriter: --> " + _outWriter);
                }
            }

            if (isTraceOn&&logger.isLoggable (Level.FINE))  //306998.15
                logger.logp(Level.FINE, CLASS_NAME,"getWriter", "created writer with encoding: " + _outWriter.getEncoding());

            _bufferedWriter.init(_outWriter, getBufferSize());
            _bufferedWriter.setLimitLong(_contentLength);
            _bufferedWriter.setResponse(_response);

            _pwriter = new PrintWriter(_bufferedWriter, false);
            // LIBERTY _responseBuffer = _bufferedWriter;
            _gotWriter = true;

            writerClosed = false;
        }
        this.fireWriterRetrievedEvent(_pwriter);
        if (isTraceOn&&logger.isLoggable (Level.FINE))  //306998.15
            logger.exiting(CLASS_NAME,"getWriter");
        return _pwriter;
    }
1171147
public static String encode( String url, String encoding )
    {
        String encodedURL = null;
        try
        {
            encodedURL = URLCodec.encode( url, encoding );
        }
        catch ( java.io.UnsupportedEncodingException e )
        {
            // try utf-8 as a default encoding
            try
            {
                encodedURL = URLCodec.encode( url, DEFAULT_ENCODING );
            }
            catch ( java.io.UnsupportedEncodingException ignore )
            {
            }
        }
        return encodedURL;
    }
432531
public static ByteBuffer charsToBytes(CharsetEncoder encoder, CharBuffer chars, ByteBuffer bytes) 
      throws UnmappableInputException {
    assert encoder.malformedInputAction() == CodingErrorAction.REPORT;

    bytes = clearAndEnsureCapacity(bytes, (int) (chars.remaining() * encoder.maxBytesPerChar()));

    chars.mark();
    encoder.reset();

    CoderResult cr = encoder.encode(chars, bytes, true);
    if (cr.isError()) {
      chars.reset();
      try {
        cr.throwException();
      } catch (CharacterCodingException e) {
        throw new UnmappableInputException("Input cannot be mapped to characters using encoding "
            + encoder.charset().name() + ": " + Arrays.toString(toArray(bytes)), e);
      }
    }

    assert cr.isUnderflow();  // This should be guaranteed by ensuring max. capacity.
    cr = encoder.flush(bytes);
    assert cr.isUnderflow();

    bytes.flip();
    chars.reset();

    return bytes;
  }
267481
public PrintWriter pw(OutputStream o) {
    String encoding = outputEncoding;
    if (!java.nio.charset.Charset.isSupported(encoding)) {
      System.out.println("Warning: desired encoding " + encoding + " not accepted. ");
      System.out.println("Using UTF-8 to construct PrintWriter");
      encoding = "UTF-8";
    }

    try {
      return new PrintWriter(new OutputStreamWriter(o, encoding), true);
    } catch (UnsupportedEncodingException e) {
      System.out.println("Warning: desired encoding " + outputEncoding + " not accepted. " + e);
      try {
        return new PrintWriter(new OutputStreamWriter(o, "UTF-8"), true);
      } catch (UnsupportedEncodingException e1) {
        System.out.println("Something is really wrong.  Your system doesn't even support UTF-8!" + e1);
        return new PrintWriter(o, true);
      }
    }
  }
216757
public static BufferedReader getConfigBufferedReader(final String resource, final String encoding) throws IOException {
		return new BufferedReader(getConfigInputStreamReader(resource, encoding));
	}
1236168
public void setEncoding(String encoding)
    throws UnsupportedEncodingException
  {
    if (encoding != null) {
      _readEncoding = Encoding.getReadEncoding(this, encoding);
      _readEncodingName = Encoding.getMimeName(encoding);
    }
    else {
      _readEncoding = null;
      _readEncodingName = null;
    }
  }
1205958
public Request acceptEncoding(String encoding){
        final String acceptEncoding = RequestHeaderFields.ACCEPT_ENCODING.getName();
        String encodingValue = headers.get(acceptEncoding);
        if (encodingValue == null){
            encodingValue = encoding;
        } else {
            encodingValue = encodingValue + ", " + encoding;
        }
        return this.setHeader(acceptEncoding, encodingValue);
    }