Package br.com.objectos.way.etc

Source Code of br.com.objectos.way.etc.ResourceCopyEval

/*
* ResourceCopyEval.java criado em 15/12/2013
*
* Propriedade de Objectos Fábrica de Software LTDA.
* Reprodução parcial ou total proibida.
*/
package br.com.objectos.way.etc;

import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

import com.github.mustachejava.Mustache;
import com.google.common.base.Charsets;
import com.google.common.io.CharStreams;
import com.google.common.io.Files;
import com.google.common.io.InputSupplier;

/**
* @author marcio.endo@objectos.com.br (Marcio Endo)
*/
class ResourceCopyEval extends ResourceCopy {

  public ResourceCopyEval(ResourceSet set, Resource resource) {
    super(set, resource);
  }

  @Override
  void copy(String resourceName, InputSupplier<InputStream> inputs, File file) throws IOException {
    InputSupplier<InputStreamReader> readers;
    readers = CharStreams.newReaderSupplier(inputs, Charsets.UTF_8);
    InputStreamReader reader = readers.getInput();

    Mustache mustache = set.compileMustache(reader, resourceName);
    BufferedWriter writer = Files.newWriter(file, Charsets.UTF_8);
    Object context = set.getContext();

    mustache.execute(writer, context).flush();
  }

}
TOP

Related Classes of br.com.objectos.way.etc.ResourceCopyEval

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.