Package org.apache.wicket.core.util.resource

Examples of org.apache.wicket.core.util.resource.UrlResourceStream


      try
      {
        final URL url = servletContext.getResource(path + pathname);
        if (url != null)
        {
          resourceStream = new UrlResourceStream(url);
        }
      }
      catch (Exception ex)
      {
        // ignore, file couldn't be found
View Full Code Here


   *            the url
   * @return the imported contents
   */
  private final String importUrl(URL url)
  {
    return ResourceUtil.readString(new UrlResourceStream(url), getCharset());
  }
View Full Code Here

   */
  @Test
  public void lastModifiedForResourceInJar() throws IOException {
    String anyClassInJarFile = "/java/lang/String.class";
    URL url = getClass().getResource(anyClassInJarFile);
    UrlResourceStream stream = new UrlResourceStream(url);
    Bytes length = stream.length();
    stream.lastModifiedTime();
    assertEquals(stream.length(), length);
    stream.close();
  }
View Full Code Here

    final AtomicInteger connectCounter = new AtomicInteger(0);
    final AtomicInteger streamCounter = new AtomicInteger(0);
    URL url = new URL(null, "test://anything", new CountingURLStreamHandler(realURL,
        connectCounter, streamCounter));

    UrlResourceStream countingStream = new UrlResourceStream(url);

    // assert the call is not made yet
    assertEquals(0, connectCounter.get());
    assertEquals(0, streamCounter.get());

    // assert the connection is loaded lazily
    countingStream.length();
    assertEquals(1, connectCounter.get());
    assertEquals(0, streamCounter.get());

    // assert the following calls do not make new connections
    countingStream.getInputStream();
    assertEquals(1, connectCounter.get());
    assertEquals(1, streamCounter.get());
    countingStream.getContentType();
    assertEquals(1, connectCounter.get());
    assertEquals(1, streamCounter.get());
    countingStream.getInputStream();
    assertEquals(1, connectCounter.get());
    assertEquals(2, streamCounter.get());
    countingStream.close();

    assertEquals(1, connectCounter.get());
    assertEquals(2, streamCounter.get());

    // assert the connection is re-opened (again lazily) second time,
    // but stream is not re-opened yet
    countingStream.length();

    assertEquals(2, connectCounter.get());
    assertEquals(2, streamCounter.get());

    // assert stream is re-opened on next getInputStream call
    countingStream.getInputStream();
    assertEquals(2, connectCounter.get());
    assertEquals(3, streamCounter.get());
  }
View Full Code Here

  @Test
  public void urlResource() throws Exception
  {
    IResourceStreamLocator resourceStreamLocator = mock(IResourceStreamLocator.class);

    UrlResourceStream urs = new UrlResourceStream(new URL("file:///"));

    when(resourceStreamLocator.locate(String.class, "path")).thenReturn(urs);

    CachingResourceStreamLocator cachingLocator = new CachingResourceStreamLocator(
      resourceStreamLocator);
View Full Code Here

   *            the url
   * @return the imported contents
   */
  private final String importUrl(URL url)
  {
    return ResourceUtil.readString(new UrlResourceStream(url), getCharset());
  }
View Full Code Here

      url = classLoader.getResource("META-INF/resources/" + path);
    }

    if (url != null)
    {
      return new UrlResourceStream(url);
    }
    return null;
  }
View Full Code Here

      url = classLoader.getResource("META-INF/resources/" + path);
    }

    if (url != null)
    {
      return new UrlResourceStream(url);
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of org.apache.wicket.core.util.resource.UrlResourceStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.