Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/**
 * PETALS: PETALS Services Platform Copyright (C) 2009 EBM WebSourcing
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or any later version.
 * 
 * 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.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
 * 
 * Initial developer(s): EBM WebSourcing
 */

import java.io.ByteArrayInputStream;

import java.io.IOException;

import java.nio.charset.Charset;

import javax.xml.transform.Source;

import javax.xml.transform.stream.StreamSource;

public class Main {
    public static Source createSource(final String message) throws IOException {
        String charsetEncoding = Charset.defaultCharset().displayName();
        return createSource(message, charsetEncoding);
    }

    public static Source createSource(final String message, final String charFormat) throws IOException {
        StreamSource source = new StreamSource();
        byte[] msgByte = message.getBytes(charFormat);
        ByteArrayInputStream in = new ByteArrayInputStream(msgByte);
        source.setInputStream(in);
        return source;
    }
}