Java ByteArrayOutputStream Write loadAsciiTxt()

Here you can find the source of loadAsciiTxt()

Description

load Ascii Txt

License

Apache License

Declaration

private static void loadAsciiTxt() throws IOException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayOutputStream;
import java.io.Closeable;

import java.io.IOException;
import java.io.InputStream;

public class Main {
    private static char[][] ascii;

    private static void loadAsciiTxt() throws IOException {
        if (ascii == null) {
            try {
                String[] split = readInputStream("ascii.txt").split("\n");
                ascii = new char[16][16];
                for (int i = 0; i < split.length; i++) {
                    ascii[i] = split[i].toCharArray();
                }//ww  w  .  jav  a  2 s  .c  om
            } catch (Exception e) {
                throw new IOException("Ascii file is invalid.", e);
            }
        }
    }

    private static String readInputStream(String name) throws IOException {
        InputStream in = ClassLoader.getSystemResourceAsStream(name);
        if (in == null) {
            throw new IOException(name + " does not exist.");
        }
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        try {
            while (in.available() > 0) {
                baos.write(in.read());
            }
            return baos.toString("utf-8");
        } finally {
            closeQuietly(in);
            closeQuietly(baos);
        }
    }

    private static void closeQuietly(Closeable close) {
        if (close != null) {
            try {
                close.close();
            } catch (IOException e) {
                // be quiet
            }
        }
    }
}

Related

  1. load(InputStream inputStream, Class type)
  2. load(InputStream is)
  3. load(InputStream is, boolean close)
  4. load(String fileName)
  5. loadAFileToString(File f)
  6. loadAsText(Class cls, String name)
  7. loadBinFile(java.io.File f)
  8. loadFully(final InputStream aStream)
  9. loadIfileAsBytes(final IFile ifile)