Java String Encode encodeTextValue(char[] characters, int offset, int length, Writer writer)

Here you can find the source of encodeTextValue(char[] characters, int offset, int length, Writer writer)

Description

encode Text Value

License

Open Source License

Declaration

public static void encodeTextValue(char[] characters, int offset, int length, Writer writer)
            throws IOException 

Method Source Code

//package com.java2s;
/*//from w w w  . j  ava2 s .  c  o m
 Milyn - Copyright (C) 2006 - 2010
    
 This library is free software; you can redistribute it and/or
 modify it under the terms of the GNU Lesser General Public
 License (version 2.1) as published by the Free Software
 Foundation.
    
 This library is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    
 See the GNU Lesser General Public License for more details:
 http://www.gnu.org/licenses/lgpl.txt
 */

import java.io.IOException;

import java.io.Writer;

public class Main {
    public static final char[] LT = new char[] { '&', 'l', 't', ';' };
    public static final char[] GT = new char[] { '&', 'g', 't', ';' };
    public static final char[] AMP = new char[] { '&', 'a', 'm', 'p', ';' };

    public static void encodeTextValue(char[] characters, int offset, int length, Writer writer)
            throws IOException {
        for (int i = offset; i < offset + length; i++) {
            char c = characters[i];
            switch (c) {
            case '<':
                writer.write(LT, 0, LT.length);
                break;
            case '>':
                writer.write(GT, 0, GT.length);
                break;
            case '&':
                writer.write(AMP, 0, AMP.length);
                break;
            default:
                writer.write(c);
            }
        }
    }
}

Related

  1. encodeString(String value)
  2. encodeStringByUTF8(String str)
  3. encodeText(String str)
  4. encodeText(String str, String fromEnc, String toEnc)
  5. encodeTexts(String s)
  6. encodeThoroughly(String s)
  7. encodeToFlex(Object o)
  8. encodeToForm(Map msg)
  9. encodeToString(String s)