Example usage for org.apache.commons.io Charsets ISO_8859_1

List of usage examples for org.apache.commons.io Charsets ISO_8859_1

Introduction

In this page you can find the example usage for org.apache.commons.io Charsets ISO_8859_1.

Prototype

Charset ISO_8859_1

To view the source code for org.apache.commons.io Charsets ISO_8859_1.

Click Source Link

Document

CharEncodingISO Latin Alphabet No.

Usage

From source file:ch.algotrader.esper.EsperTestBase.java

protected static Module load(final URL resource, final String name) throws IOException, ParseException {
    try (Reader reader = new InputStreamReader(resource.openStream(), Charsets.ISO_8859_1)) {
        return load(reader, name);
    }// ww w  . j a  v a  2s .  c om
}

From source file:magixcel.FileMan.java

public static boolean getLinesFromFile() {
    InputStream inputStream = null;
    Reader reader = null;/*  w  w w .j  a  v  a2 s. c  o  m*/
    BufferedReader bufferedReader = null;

    try {
        inputStream = new FileInputStream(INPUT_FILE_PATH);
        reader = new InputStreamReader(inputStream, Charsets.ISO_8859_1);
        bufferedReader = new BufferedReader(reader);

        String line = bufferedReader.readLine();
        while (line != null && line.length() > 0) {
            LINES_FROM_INPUT_FILE.add(line);
            line = bufferedReader.readLine();
        }

    } catch (FileNotFoundException ex) {
        Logger.getLogger(FileMan.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    } catch (IOException ex) {
        Logger.getLogger(FileMan.class.getName()).log(Level.SEVERE, null, ex);
        return false;
    } finally {
        try {
            inputStream.close();
            reader.close();
            bufferedReader.close();
        } catch (IOException ex) {
            Logger.getLogger(FileMan.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    return true;
}

From source file:com.nesscomputing.httpclient.factory.httpclient4.BetterStringEntity.java

/**
 * Creates a StringEntity with the specified content and charset
 *
 * @param string content to be used. Not {@code null}.
 * @param charset character set to be used. May be {@code null}, in which case the default is {@link HTTP#DEFAULT_CONTENT_CHARSET} i.e. "ISO-8859-1"
 *
 * @throws IllegalArgumentException if the string parameter is null
 *///  ww  w.j  a  v  a  2  s . c om
BetterStringEntity(final String string, Charset charset) {
    super();
    Preconditions.checkArgument(string != null, "Source string may not be null");

    final Charset charsetObj = ObjectUtils.firstNonNull(charset, Charsets.ISO_8859_1);
    this.content = string.getBytes(charsetObj);
    setContentType(HTTP.PLAIN_TEXT_TYPE + HTTP.CHARSET_PARAM + charsetObj.name());
}

From source file:com.tinspx.util.io.callbacks.SegmentingCallbackTest.java

private static char[] toChars(Charset charset, int len) {
    checkArgument(len >= 0);//from  w ww  . jav  a2 s  . c o  m
    if (charset == com.google.common.base.Charsets.US_ASCII) {
        return IOTest.getRandomAsciiChars(RANDOM, len);
    } else if (charset == com.google.common.base.Charsets.ISO_8859_1) {
        return IOTest.getRandomISO8859Chars(RANDOM, len);
    } else {
        return IOTest.getRandomChars(RANDOM, len);
    }
}

From source file:com.antsdb.saltedfish.server.mysql.packet.AuthPacket.java

@Override
public void read(MysqlServerHandler handler, ByteBuf in) {
    if (!checkResponseVer41(in)) {
        clientParam = BufferUtils.readInt(in);
        maxThreeBytes = BufferUtils.readLongInt(in);
        user = BufferUtils.readString(in);
        rawPwd = BufferUtils.readString(in);
        dbname = BufferUtils.readString(in);
    } else {//from   w  ww  .  j av  a 2  s. c  om
        clientParam = BufferUtils.readLong(in);
        maxThreeBytes = BufferUtils.readLong(in);
        in.readByte(); // charset
        in.skipBytes(23); // reserved for future
        user = BufferUtils.readString(in);
        if ((clientParam & CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA) != 0) {
            int passwordLength = in.readByte();
            byte[] bytes = new byte[passwordLength];
            in.readBytes(bytes);
            rawPwd = new String(bytes, Charsets.ISO_8859_1);
        } else {
            if ((clientParam & CLIENT_SECURE_CONNECTION) != 0) {
                int passwordLength = in.readByte();
                byte[] bytes = new byte[passwordLength];
                in.readBytes(bytes);
                rawPwd = new String(bytes, Charsets.ISO_8859_1);
            } else {
                rawPwd = BufferUtils.readString(in);
            }
        }
        if ((clientParam & MysqlServerHandler.CLIENT_CONNECT_WITH_DB) != 0) {
            dbname = BufferUtils.readString(in);
        }
        if ((clientParam & MysqlServerHandler.CLIENT_PLUGIN_AUTH) != 0) {
            BufferUtils.readString(in);
        }
    }
}

From source file:de.hanbei.httpserver.MockHttpServerTest.java

@Before
public void setUp() throws Exception {
    this.httpServer = new MockHttpServer(7001);
    this.httpServer.start();
    httpServer.addResponse(Method.GET, new URI("/test"), Response.ok().build());
    httpServer.addResponse(Method.GET, new URI("/test3"), Response.ok().content("TestContent").build());
    httpServer.addResponse(Method.GET, new URI("/test2"), Response.status(Status.NOT_FOUND).build());
    httpServer.addResponse(Method.GET, new URI("/test4"),
            Response.ok().content(new byte[] { 1, 2, 3, 4, 5 }).build());
    httpServer.addResponse(Method.GET, new URI("/testUtf8"), Response.ok()
            .content("Celo", Charsets.ISO_8859_1).type("text/plain; charset=iso-8859-1").build());

    httpServer.addRequestProcessor(Method.POST, URI.create("post"), new RequestProcessor() {
        @Override/*from  w  ww .  jav a 2  s.  c  o  m*/
        public Response process(Request request) {
            if (request.getContent().getContentAsString().equals("Test")) {
                return Response.ok().build();
            } else {
                return Response.status(Status.UNAUTHORIZED).build();
            }
        }
    });
    assertTrue(this.httpServer.isRunning());

    httpclient = new DefaultHttpClient(new ThreadSafeClientConnManager());
}

From source file:com.turn.ttorrent.client.io.PeerHandshakeMessage.java

@Override
public void fromWire(ByteBuf in) {
    int pstrlen = in.readUnsignedByte();
    if (pstrlen < 0 || in.readableBytes() < BASE_HANDSHAKE_LENGTH + pstrlen - 1)
        throw new IllegalArgumentException("Incorrect handshake message length (pstrlen=" + pstrlen + ") !");

    // Check the protocol identification string
    protocolName = new byte[pstrlen];
    in.readBytes(protocolName);// w ww  .ja v a  2s .  c  o  m
    if (!Arrays.equals(protocolName, BITTORRENT_PROTOCOL_IDENTIFIER))
        throw new IllegalArgumentException("Unknown protocol " + new String(protocolName, Charsets.ISO_8859_1));

    // Ignore reserved bytes
    in.readBytes(reserved);

    infoHash = new byte[20];
    in.readBytes(infoHash);
    peerId = new byte[20];
    in.readBytes(peerId);
}

From source file:magixcel.FileMan.java

public static void printInputFile() {
    try {// w  w w  . j a  v  a 2s .  c  o m

        InputStream is = new FileInputStream(INPUT_FILE_PATH);
        Reader isr = new InputStreamReader(is, Charsets.ISO_8859_1);
        BufferedReader buffReader = new BufferedReader(isr);

        // read lines from input file
        String line = buffReader.readLine();
        while (line != null && line.length() > 0) {
            System.out.println(line);
            LINES_FROM_INPUT_FILE.add(line);
            line = buffReader.readLine();

        }

        is.close();
        isr.close();
        buffReader.close();

        //            write lines to new file
        //            FileOutputStream fos = new FileOutputStream(OUTPUT_FILE_DIRECTORY + "testOutput.txt");
        //            OutputStreamWriter osw = new OutputStreamWriter(fos, Charsets.ISO_8859_1);
        //            BufferedWriter bw = new BufferedWriter(osw);
        //            for (String lineOut : LINES_FROM_FILE) {
        //                System.out.println("Writing line: " + lineOut);
        //                bw.write(lineOut);
        //
        //            }
        //            bw.close();
        //            fos.close();
        //            osw.close();
    } catch (FileNotFoundException ex) {
        //            todo bedre hndtering
        System.out.println("File not found... restart the application and supply valid file");
    } catch (IOException ex) {
        System.out.println(
                "Something went wrong parsing the file... restart the application and supply valid file");
    }

}

From source file:com.streamsets.pipeline.stage.origin.tcp.TestTCPServerSource.java

@Test
public void syslogRecords() {

    Charset charset = Charsets.ISO_8859_1;

    final TCPServerSourceConfig configBean = createConfigBean(charset);
    TCPServerSource source = new TCPServerSource(configBean);

    List<Stage.ConfigIssue> issues = new LinkedList<>();
    EmbeddedChannel ch = new EmbeddedChannel(
            source.buildByteBufToMessageDecoderChain(issues).toArray(new ChannelHandler[0]));

    ch.writeInbound(/*from  www. jav a  2  s.  c om*/
            Unpooled.copiedBuffer(SYSLOG_RECORD + configBean.nonTransparentFramingSeparatorCharStr, charset));

    assertSyslogRecord(ch);
    assertFalse(ch.finishAndReleaseAll());

    configBean.syslogFramingMode = SyslogFramingMode.OCTET_COUNTING;
    EmbeddedChannel ch2 = new EmbeddedChannel(
            source.buildByteBufToMessageDecoderChain(issues).toArray(new ChannelHandler[0]));

    ch2.writeInbound(Unpooled.copiedBuffer(SYSLOG_RECORD.length() + " " + SYSLOG_RECORD, charset));

    assertSyslogRecord(ch2);
    assertFalse(ch2.finishAndReleaseAll());
}

From source file:magixcel.FileMan.java

static void writeToFile() {
    FileOutputStream fos = null;//from www  . j  a v a 2  s  . c o  m
    OutputStreamWriter osw = null;
    BufferedWriter bw = null;
    String fileNameFull = OUTPUT_FILE_DIRECTORY + "output.txt";

    System.out.println("writing to: " + fileNameFull);

    try {
        fos = new FileOutputStream(fileNameFull);
        osw = new OutputStreamWriter(fos, Charsets.ISO_8859_1);
        bw = new BufferedWriter(osw);
        for (String lineOut : OutputFormat.getOutputLines()) {
            if (Globals.DEVELOPER_MODE == 1) {
                System.out.println("Writing line: " + lineOut);
            }
            bw.write(lineOut + System.lineSeparator());

        }
        System.out.println("DONE");

    } catch (FileNotFoundException ex) {
        Logger.getLogger(FileMan.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IOException ex) {
        Logger.getLogger(FileMan.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            bw.close();
            osw.close();
            fos.close();
        } catch (IOException ex) {
            Logger.getLogger(FileMan.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}