java.net.URLConnection.setContentHandlerFactory()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(18.1k)|赞(0)|评价(0)|浏览(256)

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

URLConnection.setContentHandlerFactory介绍

[英]Sets the internally used content handler factory. The content factory can only be set once during the lifetime of the application.
[中]设置内部使用的内容处理程序工厂。在应用程序的生命周期内,只能设置一次内容工厂。

代码示例

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

public Void run() {
    try {
      URL.setURLStreamHandlerFactory(ModularURLStreamHandlerFactory.INSTANCE);
    } catch (Throwable t) {
      // todo log a warning or something
    }
    try {
      URLConnection.setContentHandlerFactory(ModularContentHandlerFactory.INSTANCE);
    } catch (Throwable t) {
      // todo log a warning or something
    }
    return null;
  }
});

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

@Override
  public Void run() {
    try {
      URL.setURLStreamHandlerFactory(ModularURLStreamHandlerFactory.INSTANCE);
    } catch (Throwable t) {
      // todo log a warning or something
    }
    try {
      URLConnection.setContentHandlerFactory(ModularContentHandlerFactory.INSTANCE);
    } catch (Throwable t) {
      // todo log a warning or something
    }
    return null;
  }
});

代码示例来源:origin: org.eclipse/osgi

private static void forceContentHandlerFactory(ContentHandlerFactoryImpl chf) throws Exception {
  Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false);
  if (factoryField == null)
    throw new Exception("Could not find ContentHandlerFactory field"); //$NON-NLS-1$
  synchronized (URLConnection.class) {
    java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null);
    // doing a null check here just in case, but it would be really strange if it was null, 
    // because we failed to set the factory normally!!
    if (factory != null) {
      try {
        factory.getClass().getMethod("isMultiplexing", (Class[]) null); //$NON-NLS-1$
        Method register = factory.getClass().getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$
        register.invoke(factory, new Object[] {chf});
      } catch (NoSuchMethodException e) {
        // current factory does not support multiplexing, ok we'll wrap it
        chf.setParentFactory(factory);
        factory = chf;
      }
    }
    // null out the field so that we can successfully call setContentHandlerFactory			
    factoryField.set(null, null);
    // always attempt to clear the handlers cache
    // This allows an optomization for the single framework use-case
    resetContentHandlers();
    URLConnection.setContentHandlerFactory(factory);
  }
}

代码示例来源:origin: org.eclipse.tycho/org.eclipse.osgi

private static void forceContentHandlerFactory(ContentHandlerFactoryImpl chf) throws Exception {
  Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false);
  if (factoryField == null)
    throw new Exception("Could not find ContentHandlerFactory field"); //$NON-NLS-1$
  synchronized (URLConnection.class) {
    java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null);
    // doing a null check here just in case, but it would be really strange if it was null, 
    // because we failed to set the factory normally!!
    if (factory != null) {
      try {
        factory.getClass().getMethod("isMultiplexing", (Class[]) null); //$NON-NLS-1$
        Method register = factory.getClass().getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$
        register.invoke(factory, new Object[] {chf});
      } catch (NoSuchMethodException e) {
        // current factory does not support multiplexing, ok we'll wrap it
        chf.setParentFactory(factory);
        factory = chf;
      }
    }
    // null out the field so that we can successfully call setContentHandlerFactory			
    factoryField.set(null, null);
    // always attempt to clear the handlers cache
    // This allows an optomization for the single framework use-case
    resetContentHandlers();
    URLConnection.setContentHandlerFactory(factory);
  }
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.osgi

private static void forceContentHandlerFactory(ContentHandlerFactoryImpl chf) throws Exception {
  Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false);
  if (factoryField == null)
    throw new Exception("Could not find ContentHandlerFactory field"); //$NON-NLS-1$
  synchronized (URLConnection.class) {
    java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null);
    // doing a null check here just in case, but it would be really strange if it was null, 
    // because we failed to set the factory normally!!
    if (factory != null) {
      try {
        factory.getClass().getMethod("isMultiplexing", (Class[]) null); //$NON-NLS-1$
        Method register = factory.getClass().getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$
        register.invoke(factory, new Object[] {chf});
      } catch (NoSuchMethodException e) {
        // current factory does not support multiplexing, ok we'll wrap it
        chf.setParentFactory(factory);
        factory = chf;
      }
    }
    // null out the field so that we can successfully call setContentHandlerFactory			
    factoryField.set(null, null);
    // always attempt to clear the handlers cache
    // This allows an optomization for the single framework use-case
    resetContentHandlers();
    URLConnection.setContentHandlerFactory(factory);
  }
}

代码示例来源:origin: org.eclipse/org.eclipse.osgi

private static void forceContentHandlerFactory(ContentHandlerFactory chf) throws Exception {
  Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false);
  if (factoryField == null)
    throw new Exception("Could not find ContentHandlerFactory field"); //$NON-NLS-1$
  synchronized (URLConnection.class) {
    java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null);
    // doing a null check here just in case, but it would be really strange if it was null, 
    // because we failed to set the factory normally!!
    if (factory != null) {
      try {
        factory.getClass().getMethod("isMultiplexing", (Class[]) null); //$NON-NLS-1$
        Method register = factory.getClass().getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$
        register.invoke(factory, new Object[] {chf});
      } catch (NoSuchMethodException e) {
        // current factory does not support multiplexing, ok we'll wrap it
        chf.setParentFactory(factory);
        factory = chf;
      }
    }
    // null out the field so that we can successfully call setContentHandlerFactory			
    factoryField.set(null, null);
    // always attempt to clear the handlers cache
    // This allows an optomization for the single framework use-case
    resetContentHandlers();
    URLConnection.setContentHandlerFactory(factory);
  }
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.osgi

private static void forceContentHandlerFactory(ContentHandlerFactoryImpl chf) throws Exception {
  Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false);
  if (factoryField == null)
    throw new Exception("Could not find ContentHandlerFactory field"); //$NON-NLS-1$
  synchronized (URLConnection.class) {
    java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null);
    // doing a null check here just in case, but it would be really strange if it was null, 
    // because we failed to set the factory normally!!
    if (factory != null) {
      try {
        factory.getClass().getMethod("isMultiplexing", (Class[]) null); //$NON-NLS-1$
        Method register = factory.getClass().getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$
        register.invoke(factory, new Object[] {chf});
      } catch (NoSuchMethodException e) {
        // current factory does not support multiplexing, ok we'll wrap it
        chf.setParentFactory(factory);
        factory = chf;
      }
    }
    // null out the field so that we can successfully call setContentHandlerFactory			
    factoryField.set(null, null);
    // always attempt to clear the handlers cache
    // This allows an optomization for the single framework use-case
    resetContentHandlers();
    URLConnection.setContentHandlerFactory(factory);
  }
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.osgi

private static void forceContentHandlerFactory(ContentHandlerFactoryImpl chf) throws Exception {
  Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false);
  if (factoryField == null)
    throw new Exception("Could not find ContentHandlerFactory field"); //$NON-NLS-1$
  synchronized (URLConnection.class) {
    java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null);
    // doing a null check here just in case, but it would be really strange if it was null, 
    // because we failed to set the factory normally!!
    if (factory != null) {
      try {
        factory.getClass().getMethod("isMultiplexing", (Class[]) null); //$NON-NLS-1$
        Method register = factory.getClass().getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$
        register.invoke(factory, new Object[] {chf});
      } catch (NoSuchMethodException e) {
        // current factory does not support multiplexing, ok we'll wrap it
        chf.setParentFactory(factory);
        factory = chf;
      }
    }
    // null out the field so that we can successfully call setContentHandlerFactory			
    factoryField.set(null, null);
    // always attempt to clear the handlers cache
    // This allows an optomization for the single framework use-case
    resetContentHandlers();
    URLConnection.setContentHandlerFactory(factory);
  }
}

代码示例来源:origin: com.github.veithen.cosmos/cosmos-equinox

private static void forceContentHandlerFactory(ContentHandlerFactoryImpl chf) throws Exception {
  Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false);
  if (factoryField == null)
    throw new Exception("Could not find ContentHandlerFactory field"); //$NON-NLS-1$
  synchronized (URLConnection.class) {
    java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null);
    // doing a null check here just in case, but it would be really strange if it was null, 
    // because we failed to set the factory normally!!
    if (factory != null) {
      try {
        factory.getClass().getMethod("isMultiplexing", (Class[]) null); //$NON-NLS-1$
        Method register = factory.getClass().getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$
        register.invoke(factory, new Object[] {chf});
      } catch (NoSuchMethodException e) {
        // current factory does not support multiplexing, ok we'll wrap it
        chf.setParentFactory(factory);
        factory = chf;
      }
    }
    // null out the field so that we can successfully call setContentHandlerFactory			
    factoryField.set(null, null);
    // always attempt to clear the handlers cache
    // This allows an optomization for the single framework use-case
    resetContentHandlers();
    URLConnection.setContentHandlerFactory(factory);
  }
}

代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.osgi

private static void forceContentHandlerFactory(ContentHandlerFactory chf) throws Exception {
  Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false);
  if (factoryField == null)
    throw new Exception("Could not find ContentHandlerFactory field"); //$NON-NLS-1$
  synchronized (URLConnection.class) {
    java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null);
    // doing a null check here just in case, but it would be really strange if it was null, 
    // because we failed to set the factory normally!!
    if (factory != null) {
      try {
        factory.getClass().getMethod("isMultiplexing", (Class[]) null); //$NON-NLS-1$
        Method register = factory.getClass().getMethod("register", new Class[] {Object.class}); //$NON-NLS-1$
        register.invoke(factory, new Object[] {chf});
      } catch (NoSuchMethodException e) {
        // current factory does not support multiplexing, ok we'll wrap it
        chf.setParentFactory(factory);
        factory = chf;
      }
    }
    // null out the field so that we can successfully call setContentHandlerFactory			
    factoryField.set(null, null);
    // always attempt to clear the handlers cache
    // This allows an optomization for the single framework use-case
    resetContentHandlers();
    URLConnection.setContentHandlerFactory(factory);
  }
}

代码示例来源:origin: org.eclipse/osgi

private void uninstallContentHandlerFactory() {
  try {
    Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false);
    if (factoryField == null)
      return; // oh well, we tried.
    synchronized (URLConnection.class) {
      java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null);
      if (factory == contentHandlerFactory) {
        factory = (java.net.ContentHandlerFactory) contentHandlerFactory.designateSuccessor();
      } else {
        Method unregister = factory.getClass().getMethod("unregister", new Class[] {Object.class}); //$NON-NLS-1$
        unregister.invoke(factory, new Object[] {contentHandlerFactory});
      }
      // null out the field so that we can successfully call setContentHandlerFactory									
      factoryField.set(null, null);
      // always attempt to clear the handlers cache
      // This allows an optomization for the single framework use-case
      // Note that the call to setContentHandlerFactory below may clear this cache
      // but we want to be sure to clear it here just incase the parent is null.
      // In this case the call below would not occur.
      // Also it appears most java libraries actually do not clear the cache
      // when setContentHandlerFactory is called, go figure!!
      resetContentHandlers();
      if (factory != null)
        URLConnection.setContentHandlerFactory(factory);
    }
  } catch (Exception e) {
    // ignore and continue closing the framework
  }
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.osgi

private void uninstallContentHandlerFactory() {
  try {
    Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false);
    if (factoryField == null)
      return; // oh well, we tried.
    synchronized (URLConnection.class) {
      java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null);
      if (factory == contentHandlerFactory) {
        factory = (java.net.ContentHandlerFactory) contentHandlerFactory.designateSuccessor();
      } else {
        Method unregister = factory.getClass().getMethod("unregister", new Class[] {Object.class}); //$NON-NLS-1$
        unregister.invoke(factory, new Object[] {contentHandlerFactory});
      }
      // null out the field so that we can successfully call setContentHandlerFactory									
      factoryField.set(null, null);
      // always attempt to clear the handlers cache
      // This allows an optomization for the single framework use-case
      // Note that the call to setContentHandlerFactory below may clear this cache
      // but we want to be sure to clear it here just incase the parent is null.
      // In this case the call below would not occur.
      // Also it appears most java libraries actually do not clear the cache
      // when setContentHandlerFactory is called, go figure!!
      resetContentHandlers();
      if (factory != null)
        URLConnection.setContentHandlerFactory(factory);
    }
  } catch (Exception e) {
    // ignore and continue closing the framework
  }
}

代码示例来源:origin: org.eclipse.platform/org.eclipse.osgi

private void installContentHandlerFactory(BundleContext context) {
  ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container);
  try {
    // first try the standard way
    URLConnection.setContentHandlerFactory(chf);
  } catch (Error err) {
    // ok we failed now use more drastic means to set the factory
    try {
      forceContentHandlerFactory(chf);
    } catch (Exception ex) {
      // this is unexpected, log the exception and throw the original error
      container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex);
      throw err;
    }
  }
  contentHandlerFactory = chf;
}

代码示例来源:origin: com.github.veithen.cosmos/cosmos-equinox

private void installContentHandlerFactory(BundleContext context) {
  ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container);
  try {
    // first try the standard way
    URLConnection.setContentHandlerFactory(chf);
  } catch (Error err) {
    // ok we failed now use more drastic means to set the factory
    try {
      forceContentHandlerFactory(chf);
    } catch (Exception ex) {
      // this is unexpected, log the exception and throw the original error
      container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex);
      throw err;
    }
  }
  contentHandlerFactory = chf;
}

代码示例来源:origin: org.eclipse.tycho/org.eclipse.osgi

private void installContentHandlerFactory(BundleContext context) {
  ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container);
  try {
    // first try the standard way
    URLConnection.setContentHandlerFactory(chf);
  } catch (Error err) {
    // ok we failed now use more drastic means to set the factory
    try {
      forceContentHandlerFactory(chf);
    } catch (Exception ex) {
      // this is unexpected, log the exception and throw the original error
      container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex);
      throw err;
    }
  }
  contentHandlerFactory = chf;
}

代码示例来源:origin: org.eclipse/osgi

private void installContentHandlerFactory(BundleContext context) {
  ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container);
  try {
    // first try the standard way
    URLConnection.setContentHandlerFactory(chf);
  } catch (Error err) {
    // ok we failed now use more drastic means to set the factory
    try {
      forceContentHandlerFactory(chf);
    } catch (Exception ex) {
      // this is unexpected, log the exception and throw the original error
      container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex);
      throw err;
    }
  }
  contentHandlerFactory = chf;
}

代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.osgi

private void installContentHandlerFactory(BundleContext context) {
  ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container);
  try {
    // first try the standard way
    URLConnection.setContentHandlerFactory(chf);
  } catch (Error err) {
    // ok we failed now use more drastic means to set the factory
    try {
      forceContentHandlerFactory(chf);
    } catch (Exception ex) {
      // this is unexpected, log the exception and throw the original error
      container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex);
      throw err;
    }
  }
  contentHandlerFactory = chf;
}

代码示例来源:origin: at.bestsolution.efxclipse.eclipse/org.eclipse.osgi

private void installContentHandlerFactory(BundleContext context) {
  ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container);
  try {
    // first try the standard way
    URLConnection.setContentHandlerFactory(chf);
  } catch (Error err) {
    // ok we failed now use more drastic means to set the factory
    try {
      forceContentHandlerFactory(chf);
    } catch (Exception ex) {
      // this is unexpected, log the exception and throw the original error
      container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex);
      throw err;
    }
  }
  contentHandlerFactory = chf;
}

代码示例来源:origin: org.eclipse/org.eclipse.osgi

private void installContentHandlerFactory(BundleContext context, FrameworkAdaptor frameworkAdaptor) {
  ContentHandlerFactory chf = new ContentHandlerFactory(context, frameworkAdaptor);
  try {
    // first try the standard way
    URLConnection.setContentHandlerFactory(chf);
  } catch (Error err) {
    // ok we failed now use more drastic means to set the factory
    try {
      forceContentHandlerFactory(chf);
    } catch (Exception ex) {
      // this is unexpected, log the exception and throw the original error
      adaptor.getFrameworkLog().log(new FrameworkEvent(FrameworkEvent.ERROR, context.getBundle(), ex));
      throw err;
    }
  }
  contentHandlerFactory = chf;
}

代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.osgi

private void installContentHandlerFactory(BundleContext context, FrameworkAdaptor frameworkAdaptor) {
  ContentHandlerFactory chf = new ContentHandlerFactory(context, frameworkAdaptor);
  try {
    // first try the standard way
    URLConnection.setContentHandlerFactory(chf);
  } catch (Error err) {
    // ok we failed now use more drastic means to set the factory
    try {
      forceContentHandlerFactory(chf);
    } catch (Exception ex) {
      // this is unexpected, log the exception and throw the original error
      adaptor.getFrameworkLog().log(new FrameworkEvent(FrameworkEvent.ERROR, context.getBundle(), ex));
      throw err;
    }
  }
  contentHandlerFactory = chf;
}

相关文章

URLConnection类方法