Java Code Examples for java.io.IOException#fillInStackTrace()

The following examples show how to use java.io.IOException#fillInStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SortedOplogSetImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void destroy() throws IOException {
  if (logger.fineEnabled()) {
    logger.fine("Destroying soplog set");
  }

  long start = factory.getConfiguration().getStatistics().getDestroy().begin();
  try {
    unsetCurrent();
    clear();
    close();
    
    factory.getConfiguration().getStatistics().getDestroy().end(start);
    
  } catch (IOException e) {
    factory.getConfiguration().getStatistics().getDestroy().error(start);
    throw (IOException) e.fillInStackTrace();
  }
}
 
Example 2
Source File: SortedOplogSetImpl.java    From gemfirexd-oss with Apache License 2.0 6 votes vote down vote up
@Override
public void destroy() throws IOException {
  if (logger.fineEnabled()) {
    logger.fine("Destroying soplog set");
  }

  long start = factory.getConfiguration().getStatistics().getDestroy().begin();
  try {
    unsetCurrent();
    clear();
    close();
    
    factory.getConfiguration().getStatistics().getDestroy().end(start);
    
  } catch (IOException e) {
    factory.getConfiguration().getStatistics().getDestroy().error(start);
    throw (IOException) e.fillInStackTrace();
  }
}
 
Example 3
Source File: SortedOplogSetImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void clear() throws IOException {
  if (logger.fineEnabled()) {
    logger.fine("Clearing soplog set");
  }

  long start = factory.getConfiguration().getStatistics().getClear().begin();

  // acquire lock to ensure consistency with flushes
  rwlock.writeLock().lock();
  try {
    SortedBuffer<Integer> tmp = current.get();
    if (tmp != null) {
      tmp.clear();
    }

    flusher.abortAll();
    for (SortedBuffer<Integer> sb : unflushed) {
      sb.clear();
    }
    
    unflushed.clear();
    compactor.clear();

    releaseTestDelay();
    flusher.waitForCompletion();
    factory.getConfiguration().getStatistics().getClear().end(start);
    
  } catch (IOException e) {
    factory.getConfiguration().getStatistics().getClear().error(start);
    throw (IOException) e.fillInStackTrace();
    
  } finally {
    rwlock.writeLock().unlock();
  }
}
 
Example 4
Source File: SortedOplogSetImpl.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
@Override
public void clear() throws IOException {
  if (logger.fineEnabled()) {
    logger.fine("Clearing soplog set");
  }

  long start = factory.getConfiguration().getStatistics().getClear().begin();

  // acquire lock to ensure consistency with flushes
  rwlock.writeLock().lock();
  try {
    SortedBuffer<Integer> tmp = current.get();
    if (tmp != null) {
      tmp.clear();
    }

    flusher.abortAll();
    for (SortedBuffer<Integer> sb : unflushed) {
      sb.clear();
    }
    
    unflushed.clear();
    compactor.clear();

    releaseTestDelay();
    flusher.waitForCompletion();
    factory.getConfiguration().getStatistics().getClear().end(start);
    
  } catch (IOException e) {
    factory.getConfiguration().getStatistics().getClear().error(start);
    throw (IOException) e.fillInStackTrace();
    
  } finally {
    rwlock.writeLock().unlock();
  }
}
 
Example 5
Source File: ObjectSerializer.java    From bluima with Apache License 2.0 5 votes vote down vote up
public static byte[] toByteArray(Object obj) {
    byte[] bytes = null;
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        ObjectOutputStream oos = new ObjectOutputStream(bos);
        oos.writeObject(obj);
        oos.flush();
        oos.close();
        bos.close();
        bytes = bos.toByteArray();
    } catch (IOException ex) {
        ex.fillInStackTrace();
    }
    return bytes;
}
 
Example 6
Source File: InjectProcessor.java    From XModulable with Apache License 2.0 4 votes vote down vote up
private void generateCode(Map<String, List<Element>> targetInjectElements) throws ProcessException {
    if (targetInjectElements == null || targetInjectElements.isEmpty()) {
        return;
    }

    for (Map.Entry<String, List<Element>> entry : targetInjectElements.entrySet()) {
        String targetFullClzName = entry.getKey();
        List<Element> injectElements = entry.getValue();
        if (injectElements == null || injectElements.isEmpty()) {
            continue;
        }

        // 创建注入方法
        TypeElement target = mElementUtils.getTypeElement(targetFullClzName);
        ParameterSpec injectParameter = ParameterSpec.builder(ClassName.get(target), Constants.PARAMETER_OF_TARGET).build();
        MethodSpec.Builder injectMethod = MethodSpec.methodBuilder(Constants.METHOD_OF_INJECT)
                .addJavadoc("向{@code $N}注入组件\n@param $N",
                        Constants.PARAMETER_OF_TARGET,
                        Constants.PARAMETER_OF_TARGET)
                .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
                .addParameter(injectParameter)
                .returns(void.class);
        for (Element injectElement : injectElements) {
            injectMethod
                    .beginControlFlow("try")
                    .addStatement("$N.$N = ($T) $T.getInstance().getModule($S)",
                            Constants.PARAMETER_OF_TARGET,
                            injectElement.getSimpleName(),
                            injectElement.asType(),
                            mElementUtils.getTypeElement(Constants.XMODULABLE),
                            injectElement.getAnnotation(InjectXModule.class).name())
                    .nextControlFlow("catch ($T e)",
                            ClassName.get(mElementUtils.getTypeElement(Constants.UNKNOWN_MODULE_EXCEPTION)))
                    .addStatement("e.printStackTrace()")
                    .endControlFlow();
        }
        mLogger.info(String.format("创建方法:%s", Constants.METHOD_OF_INJECT));

        // 创建类
        String injectorClzName = new StringBuilder()
                .append(target.getSimpleName())
                .append(Constants.SEPARATOR_OF_CLASS_NAME)
                .append(Constants.CLASS_OF_INJECTOR)
                .toString();
        TypeSpec.Builder targetInjector = TypeSpec.classBuilder(injectorClzName)
                .addJavadoc(
                        new StringBuilder()
                                .append("组件注入器")
                                .append("\n")
                                .append("<ul><li>")
                                .append(Constants.WARNING_TIPS)
                                .append("</li></ul>")
                                .append("\n@author $N")
                                .toString(),
                        InjectProcessor.class.getSimpleName())
                .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
                .addMethod(injectMethod.build());
        mLogger.info(String.format("创建类:%s", injectorClzName));

        // 输出源文件
        try {
            String pkgName = mElementUtils.getPackageOf(injectElements.get(0)).getQualifiedName().toString();
            JavaFile.builder(pkgName, targetInjector.build())
                    .build()
                    .writeTo(mFiler);
            mLogger.info(String.format("输出源文件:%s", pkgName + "." + injectorClzName + ".java"));
        } catch (IOException e) {
            throw new ProcessException(e.fillInStackTrace());
        }
    }
}
 
Example 7
Source File: XModuleProcessor.java    From XModulable with Apache License 2.0 4 votes vote down vote up
/**
 * 生成源码,主要由三个步骤
 * <ol>
 * <li>创建方法</li>
 * <li>创建类</li>
 * <li>输出源文件</li>
 * </ol>
 *
 * @param moduleElements key:组件名;value:携带@XModule的Element
 */
private void generateCode(Map<String, Element> moduleElements) throws ProcessException {
    if (moduleElements == null || moduleElements.isEmpty()) {
        return;
    }

    /*
    1、创建方法
    public void loadInto(XModulableOptions options) {
           if (options == null) {
               return;
           }
           options.addModule(, );
     }
     */
    MethodSpec.Builder loadIntoMethod = MethodSpec.methodBuilder(Constants.METHOD_OF_LOAD_INTO)
            .addJavadoc("向$N添加组件", Constants.PARAMETER_OF_XMODULABLE_OPTIONS)
            .addAnnotation(Override.class)
            .addModifiers(Modifier.PUBLIC)
            .addParameter(ClassName.get(mElementUtils.getTypeElement(Constants.XMODULABLE_OPTIONS)), Constants.PARAMETER_OF_XMODULABLE_OPTIONS)
            .returns(void.class)
            .beginControlFlow("if ($N == null)", Constants.PARAMETER_OF_XMODULABLE_OPTIONS)
            .addStatement("return")
            .endControlFlow();
    for (Map.Entry<String, Element> entry : moduleElements.entrySet()) {
        String moduleName = entry.getKey();
        TypeName moduleTypeName = TypeName.get(entry.getValue().asType()); // 注解的宿主类型名
        loadIntoMethod.addStatement("$N.addModule($S, new $T())", Constants.PARAMETER_OF_XMODULABLE_OPTIONS, moduleName, moduleTypeName);
    }
    mLogger.info(String.format("创建方法:%s", Constants.METHOD_OF_LOAD_INTO));

    /*
    2、创建类
    public final class XModule$$Loader$$组件名 implements XModuleLoader
     */
    String className = new StringBuilder()
            .append(Constants.SDK_NAME)
            .append(Constants.SEPARATOR_OF_CLASS_NAME)
            .append(Constants.CLASS_OF_LOADER)
            .append(Constants.SEPARATOR_OF_CLASS_NAME)
            .append(mModuleName)
            .toString();
    TypeSpec.Builder componentLoader = TypeSpec.classBuilder(className)
            .addJavadoc(
                    new StringBuilder()
                            .append("$N组件加载器")
                            .append("\n")
                            .append("<ul><li>")
                            .append(Constants.WARNING_TIPS)
                            .append("</li></ul>")
                            .append("\n@author $N")
                            .toString(),
                    mModuleName,
                    XModuleProcessor.class.getSimpleName())
            .addSuperinterface(ClassName.get(mXModuleLoader))
            .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
            .addMethod(loadIntoMethod.build());
    mLogger.info(String.format("创建类:%s", className));

    /*
    3、输出源文件
    XModule$$Loader$$组件名.java
     */
    try {
        JavaFile.builder(Constants.PACKAGE_OF_GENERATE, componentLoader.build())
                .build().writeTo(mFiler);
        mLogger.info(String.format("输出源文件:%s", Constants.PACKAGE_OF_GENERATE + "." + className + ".java"));
    } catch (IOException e) {
        throw new ProcessException(e.fillInStackTrace());
    }
}
 
Example 8
Source File: TestForExceptions.java    From boon with Apache License 2.0 3 votes vote down vote up
public void methodThatThrowsException0() throws IOException {

       IOException ioe =  new IOException( "ROOT Bad stuff happens to good people" );
       ioe.fillInStackTrace();
       throw ioe;

    }