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

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

本文整理了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

  1. public Void run() {
  2. try {
  3. URL.setURLStreamHandlerFactory(ModularURLStreamHandlerFactory.INSTANCE);
  4. } catch (Throwable t) {
  5. // todo log a warning or something
  6. }
  7. try {
  8. URLConnection.setContentHandlerFactory(ModularContentHandlerFactory.INSTANCE);
  9. } catch (Throwable t) {
  10. // todo log a warning or something
  11. }
  12. return null;
  13. }
  14. });

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

  1. @Override
  2. public Void run() {
  3. try {
  4. URL.setURLStreamHandlerFactory(ModularURLStreamHandlerFactory.INSTANCE);
  5. } catch (Throwable t) {
  6. // todo log a warning or something
  7. }
  8. try {
  9. URLConnection.setContentHandlerFactory(ModularContentHandlerFactory.INSTANCE);
  10. } catch (Throwable t) {
  11. // todo log a warning or something
  12. }
  13. return null;
  14. }
  15. });

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  1. private void uninstallContentHandlerFactory() {
  2. try {
  3. Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false);
  4. if (factoryField == null)
  5. return; // oh well, we tried.
  6. synchronized (URLConnection.class) {
  7. java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null);
  8. if (factory == contentHandlerFactory) {
  9. factory = (java.net.ContentHandlerFactory) contentHandlerFactory.designateSuccessor();
  10. } else {
  11. Method unregister = factory.getClass().getMethod("unregister", new Class[] {Object.class}); //$NON-NLS-1$
  12. unregister.invoke(factory, new Object[] {contentHandlerFactory});
  13. }
  14. // null out the field so that we can successfully call setContentHandlerFactory
  15. factoryField.set(null, null);
  16. // always attempt to clear the handlers cache
  17. // This allows an optomization for the single framework use-case
  18. // Note that the call to setContentHandlerFactory below may clear this cache
  19. // but we want to be sure to clear it here just incase the parent is null.
  20. // In this case the call below would not occur.
  21. // Also it appears most java libraries actually do not clear the cache
  22. // when setContentHandlerFactory is called, go figure!!
  23. resetContentHandlers();
  24. if (factory != null)
  25. URLConnection.setContentHandlerFactory(factory);
  26. }
  27. } catch (Exception e) {
  28. // ignore and continue closing the framework
  29. }
  30. }

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

  1. private void uninstallContentHandlerFactory() {
  2. try {
  3. Field factoryField = getField(URLConnection.class, java.net.ContentHandlerFactory.class, false);
  4. if (factoryField == null)
  5. return; // oh well, we tried.
  6. synchronized (URLConnection.class) {
  7. java.net.ContentHandlerFactory factory = (java.net.ContentHandlerFactory) factoryField.get(null);
  8. if (factory == contentHandlerFactory) {
  9. factory = (java.net.ContentHandlerFactory) contentHandlerFactory.designateSuccessor();
  10. } else {
  11. Method unregister = factory.getClass().getMethod("unregister", new Class[] {Object.class}); //$NON-NLS-1$
  12. unregister.invoke(factory, new Object[] {contentHandlerFactory});
  13. }
  14. // null out the field so that we can successfully call setContentHandlerFactory
  15. factoryField.set(null, null);
  16. // always attempt to clear the handlers cache
  17. // This allows an optomization for the single framework use-case
  18. // Note that the call to setContentHandlerFactory below may clear this cache
  19. // but we want to be sure to clear it here just incase the parent is null.
  20. // In this case the call below would not occur.
  21. // Also it appears most java libraries actually do not clear the cache
  22. // when setContentHandlerFactory is called, go figure!!
  23. resetContentHandlers();
  24. if (factory != null)
  25. URLConnection.setContentHandlerFactory(factory);
  26. }
  27. } catch (Exception e) {
  28. // ignore and continue closing the framework
  29. }
  30. }

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

  1. private void installContentHandlerFactory(BundleContext context) {
  2. ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container);
  3. try {
  4. // first try the standard way
  5. URLConnection.setContentHandlerFactory(chf);
  6. } catch (Error err) {
  7. // ok we failed now use more drastic means to set the factory
  8. try {
  9. forceContentHandlerFactory(chf);
  10. } catch (Exception ex) {
  11. // this is unexpected, log the exception and throw the original error
  12. container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex);
  13. throw err;
  14. }
  15. }
  16. contentHandlerFactory = chf;
  17. }

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

  1. private void installContentHandlerFactory(BundleContext context) {
  2. ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container);
  3. try {
  4. // first try the standard way
  5. URLConnection.setContentHandlerFactory(chf);
  6. } catch (Error err) {
  7. // ok we failed now use more drastic means to set the factory
  8. try {
  9. forceContentHandlerFactory(chf);
  10. } catch (Exception ex) {
  11. // this is unexpected, log the exception and throw the original error
  12. container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex);
  13. throw err;
  14. }
  15. }
  16. contentHandlerFactory = chf;
  17. }

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

  1. private void installContentHandlerFactory(BundleContext context) {
  2. ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container);
  3. try {
  4. // first try the standard way
  5. URLConnection.setContentHandlerFactory(chf);
  6. } catch (Error err) {
  7. // ok we failed now use more drastic means to set the factory
  8. try {
  9. forceContentHandlerFactory(chf);
  10. } catch (Exception ex) {
  11. // this is unexpected, log the exception and throw the original error
  12. container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex);
  13. throw err;
  14. }
  15. }
  16. contentHandlerFactory = chf;
  17. }

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

  1. private void installContentHandlerFactory(BundleContext context) {
  2. ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container);
  3. try {
  4. // first try the standard way
  5. URLConnection.setContentHandlerFactory(chf);
  6. } catch (Error err) {
  7. // ok we failed now use more drastic means to set the factory
  8. try {
  9. forceContentHandlerFactory(chf);
  10. } catch (Exception ex) {
  11. // this is unexpected, log the exception and throw the original error
  12. container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex);
  13. throw err;
  14. }
  15. }
  16. contentHandlerFactory = chf;
  17. }

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

  1. private void installContentHandlerFactory(BundleContext context) {
  2. ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container);
  3. try {
  4. // first try the standard way
  5. URLConnection.setContentHandlerFactory(chf);
  6. } catch (Error err) {
  7. // ok we failed now use more drastic means to set the factory
  8. try {
  9. forceContentHandlerFactory(chf);
  10. } catch (Exception ex) {
  11. // this is unexpected, log the exception and throw the original error
  12. container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex);
  13. throw err;
  14. }
  15. }
  16. contentHandlerFactory = chf;
  17. }

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

  1. private void installContentHandlerFactory(BundleContext context) {
  2. ContentHandlerFactoryImpl chf = new ContentHandlerFactoryImpl(context, container);
  3. try {
  4. // first try the standard way
  5. URLConnection.setContentHandlerFactory(chf);
  6. } catch (Error err) {
  7. // ok we failed now use more drastic means to set the factory
  8. try {
  9. forceContentHandlerFactory(chf);
  10. } catch (Exception ex) {
  11. // this is unexpected, log the exception and throw the original error
  12. container.getLogServices().log(EquinoxContainer.NAME, FrameworkLogEntry.ERROR, ex.getMessage(), ex);
  13. throw err;
  14. }
  15. }
  16. contentHandlerFactory = chf;
  17. }

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

  1. private void installContentHandlerFactory(BundleContext context, FrameworkAdaptor frameworkAdaptor) {
  2. ContentHandlerFactory chf = new ContentHandlerFactory(context, frameworkAdaptor);
  3. try {
  4. // first try the standard way
  5. URLConnection.setContentHandlerFactory(chf);
  6. } catch (Error err) {
  7. // ok we failed now use more drastic means to set the factory
  8. try {
  9. forceContentHandlerFactory(chf);
  10. } catch (Exception ex) {
  11. // this is unexpected, log the exception and throw the original error
  12. adaptor.getFrameworkLog().log(new FrameworkEvent(FrameworkEvent.ERROR, context.getBundle(), ex));
  13. throw err;
  14. }
  15. }
  16. contentHandlerFactory = chf;
  17. }

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

  1. private void installContentHandlerFactory(BundleContext context, FrameworkAdaptor frameworkAdaptor) {
  2. ContentHandlerFactory chf = new ContentHandlerFactory(context, frameworkAdaptor);
  3. try {
  4. // first try the standard way
  5. URLConnection.setContentHandlerFactory(chf);
  6. } catch (Error err) {
  7. // ok we failed now use more drastic means to set the factory
  8. try {
  9. forceContentHandlerFactory(chf);
  10. } catch (Exception ex) {
  11. // this is unexpected, log the exception and throw the original error
  12. adaptor.getFrameworkLog().log(new FrameworkEvent(FrameworkEvent.ERROR, context.getBundle(), ex));
  13. throw err;
  14. }
  15. }
  16. contentHandlerFactory = chf;
  17. }

相关文章

URLConnection类方法