Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2007 Exadel, Inc. and Red Hat, Inc.
 * Distributed under license by Red Hat, Inc. All rights reserved.
 * This program is made available under the terms of the
 * Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Exadel, Inc. and Red Hat, Inc. - initial API and implementation
 ******************************************************************************/

public class Main {
    static final String ENCODING = "encoding=\"";
    static final String UTF8 = "UTF-8";

    public static String getEncoding(String body) {
        int i = body.indexOf(ENCODING);
        if (i < 0) {
            return UTF8;
        }
        i = i + ENCODING.length();
        int j = body.indexOf('"', i);
        if (j < 0) {
            return UTF8;
        }
        return body.substring(i, j);

    }
}