Ejemplo n.º 1
0
 public static String readAsString(File file) {
   AssertionUtil.assertNotNull(file);
   InputStream inputStream = null;
   try {
     inputStream = new FileInputStream(file);
     return readAsString(inputStream);
   } catch (FileNotFoundException e) {
     throw new GenException(Message.YUIGEN9001, e, e);
   } finally {
     IOUtil.close(inputStream);
   }
 }
Ejemplo n.º 2
0
 public static String readAsString(InputStream inputStream) {
   AssertionUtil.assertNotNull(inputStream);
   BufferedReader reader =
       new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8")));
   StringBuilder buf = new StringBuilder(200);
   try {
     CharBuffer c = CharBuffer.allocate(BUF_SIZE);
     while (reader.read(c) > -1) {
       c.flip();
       buf.append(c);
       c.clear();
     }
   } catch (IOException e) {
     throw new GenException(Message.YUIGEN9001, e, e);
   } finally {
     IOUtil.close(reader);
   }
   return buf.toString();
 }
Ejemplo n.º 3
0
 /**
  * 生成します。
  *
  * @param context コンテキスト
  */
 public void generate(GenerationContext context) {
   boolean exists = exists(context.getFile());
   if (!context.isOverwrite() && exists) {
     Logger.info(Message.YUIGEN0004.getMessage(context.getFile().getPath()));
     return;
   }
   File dir = context.getFile().getParentFile();
   if (dir != null) {
     mkdirs(dir);
   }
   Writer writer = openWriter(context);
   try {
     Template template = getTemplate(context.getTemplateName());
     process(template, context.getModel(), writer);
   } finally {
     IOUtil.close(writer);
   }
   if (exists) {
     Logger.info(Message.YUIGEN0003.getMessage(context.getFile().getPath()));
   } else {
     Logger.info(Message.YUIGEN0002.getMessage(context.getFile().getPath()));
   }
 }