Java XML String Transform createSource(final String message)

Here you can find the source of createSource(final String message)

Description

create Source

License

Open Source License

Declaration

public static Source createSource(final String message) throws IOException 

Method Source Code

//package com.java2s;
/**/*from  ww w  .  j a va2s.  c o m*/
 * 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;
    }
}

Related

  1. createElement(Node node, String name, String value, Map attributes)
  2. createFullReportLog(String sessionLogDir)
  3. createObject(String classname)
  4. createOrUpdateConnection(String fileName, String directory, String communityId, String serviceName, String serviceUrl, String defaultVersion, Logger log)
  5. createSettingsXml(Map props)
  6. createSource(String msg)
  7. createString(Element element)
  8. createXml(ArrayList nameList, ArrayList stringList, ArrayList stringArrayNameList, HashMap> stringArrayContentMap)
  9. createXmlError(String message, String details)