Package juzu.impl.common

Examples of juzu.impl.common.Resource


    //
    URLConnection conn = file.url.openConnection();
    long lastModified = conn.getLastModified();
    byte[] bytes = Tools.bytes(conn.getInputStream());
    return new Timestamped<Resource>(lastModified, new Resource(bytes, Charset.defaultCharset()));
  }
View Full Code Here


    FileObject resource = owner.application.resolveResource(path);
    if (resource != null) {
      try {
        byte[] bytes = Tools.bytes(resource.openInputStream());
        long lastModified = resource.getLastModified();
        return new Timestamped<Resource>(lastModified, new Resource(bytes, Charset.defaultCharset()));
      }
      catch (Exception e) {
        env.info("Could not get resource content " + path.getCanonical(), e);
      }
    }
View Full Code Here

  public Timestamped<Resource> getResource(String file) throws IOException {
    URL url = getURL(file);
    URLConnection conn = url.openConnection();
    long lastModified = conn.getLastModified();
    byte[] bytes = Tools.bytes(conn.getInputStream());
    return new Timestamped<Resource>(lastModified, new Resource(bytes, Charset.defaultCharset()));
  }
View Full Code Here

        ByteArrayOutputStream resource = new ByteArrayOutputStream();
        byte[] buffer = new byte[256];
        for (int l = in.read(buffer);l != -1;l = in.read(buffer)) {
          resource.write(buffer, 0, l);
        }
        return new Timestamped<Resource>(lastModified, new Resource(resource.toByteArray(), Charset.defaultCharset()));
      }
      finally {
        Tools.safeClose(in);
      }
    }
View Full Code Here

      ByteArrayOutputStream resource = new ByteArrayOutputStream();
      byte[] buffer = new byte[256];
      for (int l = in.read(buffer);l != -1;l = in.read(buffer)) {
        resource.write(buffer, 0, l);
      }
      return new Timestamped<Resource>(file.lastModified(), new Resource(resource.toByteArray(), encoding));
    }
    finally {
      Tools.safeClose(in);
    }
  }
View Full Code Here

    snapshot = snapshot.scan();
    assertEquals(Collections.<String, Change>emptyMap(), snapshot.getChanges());

    //
    String[] bar = fs.makePath(foo, "bar.txt");
    fs.updateResource(bar, new Resource(""));
    waitForOneMillis();
    snapshot = snapshot.scan();
    assertEquals(Collections.singletonMap("/foo/bar.txt", Change.ADD), snapshot.getChanges());
    waitForOneMillis();
    snapshot = snapshot.scan();
    assertEquals(Collections.<String, Change>emptyMap(), snapshot.getChanges());

    //
    fs.updateResource(bar, new Resource("value"));
    waitForOneMillis();
    snapshot = snapshot.scan();
    assertEquals(Collections.singletonMap("/foo/bar.txt", Change.UPDATE), snapshot.getChanges());

    //
View Full Code Here

    //
    Snapshot<String[]> snapshot = scanner.take();
    assertEquals(Collections.<String, Change>emptyMap(), snapshot.getChanges());
    String[] foo = fs.makePath(fs.getRoot(), ".foo");
    fs.updateResource(foo, new Resource(""));
    waitForOneMillis();
    snapshot = snapshot.scan();
    assertEquals(Collections.<String, Change>emptyMap(), snapshot.getChanges());
  }
View Full Code Here

  @Test
  public void testLastModified() throws IOException {
    RAMFileSystem fs = new RAMFileSystem();
    String[] fooTxt = fs.makePath(fs.getRoot(), "foo.txt");
    fs.updateResource(fooTxt, new Resource("abc"));
    long now = waitForOneMillis();
    assertTrue(fs.getLastModified(fooTxt) < now);
    waitForOneMillis();
    fs.updateResource(fooTxt, new Resource("def"));
    assertTrue(now < fs.getLastModified(fooTxt));
  }
View Full Code Here

    //
    Snapshot<String[]> snapshot = scanner.take();
    assertEquals(Collections.<String, Change>emptyMap(), snapshot.getChanges());
    String[] bar = fs.makePath(fs.makePath(fs.getRoot(), ".foo"), "bar.txt");
    fs.updateResource(bar, new Resource(""));
    waitForOneMillis();
    snapshot = snapshot.scan();
    assertEquals(Collections.<String, Change>emptyMap(), snapshot.getChanges());
  }
View Full Code Here

        fs.createDir(path);
      } else {
        path = fs.getRoot();
      }
      path = fs.makePath(path, atoms[atoms.length - 1] + "." + ext);
      fs.updateResource(path, new Resource(content));
      return new FileResource<I>(fs, path);
    }
    catch (IOException e) {
      throw AbstractTestCase.failure(e);
    }
View Full Code Here

TOP

Related Classes of juzu.impl.common.Resource

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.