Here you can find the source of writeStringAsAsciiBytes(String in, OutputStream out)
Parameter | Description |
---|---|
in | the given string |
out | the output stream |
Parameter | Description |
---|---|
IOException | if an I/O error occurs |
public static void writeStringAsAsciiBytes(String in, OutputStream out) throws IOException
//package com.java2s; /*/*from w w w . j ava 2 s .c o m*/ * Copyright 2010-2011 the original author or authors. * * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ import java.io.IOException; import java.io.OutputStream; public class Main { /** * Writes the given {@link String string} as ASCII bytes (0-127) * to the given {@link OutputStream output stream}. * <p> * This method ignores the 24 high-order bits of the characters * in the given string. It does not check if the characters in * the string are indeed ASCII characters or not. It <em>assumes</em> * that the given string only contains valid ASCII characters. * * @param in the given string * @param out the output stream * @throws IOException if an I/O error occurs */ public static void writeStringAsAsciiBytes(String in, OutputStream out) throws IOException { final int length = in.length(); for (int i = 0; i < length; i++) { // The byte to be written is the eight low-order bits // of charAt(i). The 24 high-order bits are ignored. out.write(in.charAt(i)); } } }