Java Byte Array to String by Charset yaml2List(Charset charset, byte[] data)

Here you can find the source of yaml2List(Charset charset, byte[] data)

Description

yaml List

License

Apache License

Parameter

Parameter Description
charset a parameter
data a parameter

Exception

Parameter Description
IOException an exception

Declaration

public static List<String> yaml2List(Charset charset, byte[] data) throws IOException 

Method Source Code


//package com.java2s;
/*//from  w w  w  . jav  a2 s .c om
 * Copyright (C) 2012~2013 dinstone<dinstone@163.com>
 * 
 * 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.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * @param charset
     * @param data
     * @return
     * @throws IOException
     */
    public static List<String> yaml2List(Charset charset, byte[] data) throws IOException {
        List<String> list = new ArrayList<String>();
        BufferedReader reader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(data), charset));
        String line = null;
        while ((line = reader.readLine()) != null) {
            String[] kvs = line.split(" ");
            if (kvs.length == 2) {
                list.add(kvs[1].trim());
            }
        }
        return list;
    }
}

Related

  1. toString(byte[] bytes, String charsetName)
  2. toString(byte[] data, int from, int length, Charset charset)
  3. toString(final byte[] bytes, final String charsetName)
  4. toUnicode(byte[] isoStr, String charset)
  5. truncateByByteLength(String string, int maxBytes, Charset charset)