java.util.logging.Handler.setEncoding()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(6.5k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中java.util.logging.Handler.setEncoding()方法的一些代码示例,展示了Handler.setEncoding()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Handler.setEncoding()方法的具体详情如下:
包路径:java.util.logging.Handler
类名称:Handler
方法名:setEncoding

Handler.setEncoding介绍

[英]Sets the character encoding used by this handler, null indicates a default encoding.
[中]设置此处理程序使用的字符编码,null表示默认编码。

代码示例

代码示例来源:origin: jenkinsci/jenkins

@Override
public void setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException {
  super.setEncoding(encoding);
  Handler t = resolve();
  if(t!=null)
    t.setEncoding(encoding);
}

代码示例来源:origin: robovm/robovm

/**
 * Sets the character encoding used by this handler. A {@code null} value
 * indicates that the default encoding should be used.
 *
 * @throws UnsupportedEncodingException if {@code charsetName} is not supported.
 */
@Override
public void setEncoding(String charsetName) throws UnsupportedEncodingException {
  // Flush any existing data first.
  this.flush();
  super.setEncoding(charsetName);
  // renew writer only if the writer exists
  if (this.writer != null) {
    if (getEncoding() == null) {
      this.writer = new OutputStreamWriter(this.os);
    } else {
      try {
        this.writer = new OutputStreamWriter(this.os, getEncoding());
      } catch (UnsupportedEncodingException e) {
        /*
         * Should not happen because it's checked in
         * super.initProperties().
         */
        throw new AssertionError(e);
      }
    }
  }
}

代码示例来源:origin: alibaba/Sentinel

protected static Handler makeLogger(String logName, Logger heliumRecordLog) {
    CspFormatter formatter = new CspFormatter();
    String fileName = LogBase.getLogBaseDir() + logName;
    if (isLogNameUsePid()) {
      fileName += ".pid" + PidUtil.getPid();
    }
    Handler handler = null;
    try {
      handler = new DateFileLogHandler(fileName + ".%d", 1024 * 1024 * 200, 4, true);
      handler.setFormatter(formatter);
      handler.setEncoding(LOG_CHARSET);
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (handler != null) {
      LoggerUtils.disableOtherHandlers(heliumRecordLog, handler);
    }
    heliumRecordLog.setLevel(Level.ALL);
    return handler;
  }
}

代码示例来源:origin: org.ow2.monolog/monolog-wrapper-javalog

/**
 * Set the character encoding used by this Handler.
 */
public void setEncoding(String encoding)
    throws SecurityException, UnsupportedEncodingException {
  handler.setEncoding(encoding);
}

代码示例来源:origin: dworkin/reddwarf

/**
 * {@inheritDoc}
 */
public void setEncoding(String encoding) 
throws java.io.UnsupportedEncodingException {
handler.setEncoding(encoding);
}

代码示例来源:origin: de.unkrig/de-unkrig-commons

@Override public void
setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException {
  if (this.delegate != null) this.delegate.setEncoding(encoding);
}

代码示例来源:origin: org.reddwarfserver.server/sgs-server

/**
 * {@inheritDoc}
 */
public void setEncoding(String encoding) 
throws java.io.UnsupportedEncodingException {
handler.setEncoding(encoding);
}

代码示例来源:origin: com.mycila/mycila-log

public void setEncoding(T handler, String encoding) throws SecurityException, UnsupportedEncodingException {
  handler.setEncoding(encoding);
}

代码示例来源:origin: com.projectdarkstar.server/sgs-server

/**
 * {@inheritDoc}
 */
public void setEncoding(String encoding) 
throws java.io.UnsupportedEncodingException {
handler.setEncoding(encoding);
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

@Override
public void setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException {
  super.setEncoding(encoding);
  Handler t = resolve();
  if(t!=null)
    t.setEncoding(encoding);
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

@Override
public void setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException {
  super.setEncoding(encoding);
  Handler t = resolve();
  if (t != null) {
    t.setEncoding(encoding);
  }
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

@Override
public void setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException {
  super.setEncoding(encoding);
  Handler t = resolve();
  if(t!=null)
    t.setEncoding(encoding);
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

@Override
public void setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException {
  super.setEncoding(encoding);
  Handler t = resolve();
  if(t!=null)
    t.setEncoding(encoding);
}

代码示例来源:origin: hudson/hudson-2.x

@Override
public void setEncoding(String encoding) throws SecurityException, UnsupportedEncodingException {
  super.setEncoding(encoding);
  Handler t = resolve();
  if(t!=null)
    t.setEncoding(encoding);
}

代码示例来源:origin: org.jboss.logmanager/jboss-logmanager

@Override
public void setEncoding(final String encoding) throws SecurityException, UnsupportedEncodingException {
  checkAccess(this);
  super.setEncoding(encoding);
}

代码示例来源:origin: de.unkrig.commons/commons-util

@Override public void
setEncoding(@Nullable String encoding) throws SecurityException, UnsupportedEncodingException {
  if (this.delegate != null) this.delegate.setEncoding(encoding);
}

代码示例来源:origin: org.jboss.logmanager/jboss-logmanager

public void applyPostCreate(final Void param) {
  try {
    configuration.getHandlerRefs().get(getName()).setEncoding(encoding);
  } catch (UnsupportedEncodingException e) {
    throw new IllegalArgumentException(String.format("The encoding value '%s' is invalid.", encoding), e);
  }
}

代码示例来源:origin: com.samskivert/samskivert

public void init ()
{
  try {
    if (!Boolean.getBoolean("com.samskivert.util.JDK14Logger.noFormatter")) {
      OneLineLogFormatter.configureDefaultHandler();
    }
    boolean reportedUTF8Missing = false;
    for (Handler handler : java.util.logging.Logger.getLogger("").getHandlers()) {
      try {
        handler.setEncoding("UTF-8");
      } catch (UnsupportedEncodingException e) {
        // JVMs are required to support UTF-8 so this shouldn't happen, but if it does,
        // tell somebody that things are really fucked
        if (!reportedUTF8Missing) {
          reportedUTF8Missing = true;
          System.err.println("Unable to find UTF-8 encoding. " +
                    "This JVM ain't right: " + e.getMessage());
        }
      }
    }
  } catch (SecurityException se) {
    // running in sandbox; no custom logging; no problem!
  }
}

代码示例来源:origin: javax.mail/com.springsource.javax.mail

private void initEncoding(LogManager manager, String p) {
  assert Thread.holdsLock(this);
  try {
    super.setEncoding(manager.getProperty(p.concat(".encoding")));
  } catch (final SecurityException SE) {
    throw SE; //Avoid catch all.
  } catch (final UnsupportedEncodingException UEE) {
    reportError(UEE.getMessage(), UEE, ErrorManager.OPEN_FAILURE);
  } catch (final RuntimeException RE) {
    reportError(RE.getMessage(), RE, ErrorManager.OPEN_FAILURE);
  }
}

代码示例来源:origin: com.jtransc/jtransc-rt

@Override
public void setEncoding(String charsetName) throws UnsupportedEncodingException {
  // Flush any existing data first.
  this.flush();
  super.setEncoding(charsetName);
  // renew writer only if the writer exists
  if (this.writer != null) {
    if (getEncoding() == null) {
      this.writer = new OutputStreamWriter(this.os);
    } else {
      try {
        this.writer = new OutputStreamWriter(this.os, getEncoding());
      } catch (UnsupportedEncodingException e) {
        throw new AssertionError(e);
      }
    }
  }
}

相关文章