Package net.sf.collabreview.mediawiki

Source Code of net.sf.collabreview.mediawiki.WikiStringEncoder

/*
   Copyright 2012 Christian Prause and Fraunhofer FIT

   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.
*/

package net.sf.collabreview.mediawiki;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class WikiStringEncoder {

  public String encodeUTF8(String label) throws IOException {
   
    StringBuffer stringBuffer = new StringBuffer();

    byte[] byteArray = label.getBytes("ISO-8859-1");
    //new String(byteArray, "UTF-8");
    //byte[] byteArray = label.getBytes("UTF-8");

    InputStream stream = new ByteArrayInputStream(byteArray);
    InputStreamReader reader;
   
    reader = new InputStreamReader(stream, "UTF-8");

    char[] cbuf = new char[label.length()];
   
    while(reader.ready()){
      reader.read(cbuf);
     
      for(int i=0; i<cbuf.length; i++){
        stringBuffer.append(cbuf[i]);
      }
    }
   
    return stringBuffer.toString().trim();
  }

}
TOP

Related Classes of net.sf.collabreview.mediawiki.WikiStringEncoder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.