zoukankan      html  css  js  c++  java
  • 如何写代码

    1.方法嵌套实现方法的重载:

    public class EventBuilder {
    
      /**
       * Instantiate an Event instance based on the provided body and headers.
       * If <code>headers</code> is <code>null</code>, then it is ignored.
       * @param body
       * @param headers
       * @return
       */
      public static Event withBody(byte[] body, Map<String, String> headers) {
        Event event = new SimpleEvent();
    
        if(body == null) {
          body = new byte[0];
        }
        event.setBody(body);
    
        if (headers != null) {
          event.setHeaders(new HashMap<String, String>(headers));
        }
    
        return event;
      }
    
      public static Event withBody(byte[] body) {
        return withBody(body, null);
      }
    
      public static Event withBody(String body, Charset charset,
          Map<String, String> headers) {
    
        return withBody(body.getBytes(charset), headers);
      }
    
      public static Event withBody(String body, Charset charset) {
        return withBody(body, charset, null);
      }
    
    }
    

    2.序列器这种适合作为成员变量存在在读写类中,并不适合根据序列器定义不同读写类。

       这样reader、writer这种类的基本信息不至于反复定义,序列器只需要做序列文本的工作就可以了。

    public class ReliableSpoolingFileEventReader implements ReliableEventReader {
    
      private static final Logger logger = LoggerFactory
          .getLogger(ReliableSpoolingFileEventReader.class);
    
      static final String metaFileName = ".flumespool-main.meta";
    
      private final File spoolDirectory;
      private final String completedSuffix;
      private final String deserializerType;
      private final Context deserializerContext;
      private final Pattern ignorePattern;
      private final File metaFile;
      private final boolean annotateFileName;
      private final boolean annotateBaseName;
      private final String fileNameHeader;
      private final String baseNameHeader;
      private final String deletePolicy;
      private final Charset inputCharset;
      private final DecodeErrorPolicy decodeErrorPolicy;
      private final ConsumeOrder consumeOrder; 
      private EventDeserializer des = currentFile.get().getDeserializer();
    }

    3.

  • 相关阅读:
    开源工作流 Bonita BPM (JAVA)
    java怎么样判断一个进程是否已近结束
    struts2 Annotation 实现文件下载功能 文件名中文乱码问题
    struts2中s:radio标签的使用 Map
    Win7下声音由小逐渐变大
    JSTL EL 详解
    CHM格式 打开后不显示内容的解决办法
    jquery radio 判断是否被选中的例子
    火狐的funmoods都已经清除了,config里怎么还有他它的项目
    由MyEclipse内存不足谈谈JVM内存
  • 原文地址:https://www.cnblogs.com/chaiwentao/p/5865070.html
Copyright © 2011-2022 走看看