コード例 #1
0
  @Test
  public void testOverrideFileProperty() throws Exception {
    sm.register(SOURCE, testFile);
    Source source = sm.getSource(SOURCE);
    String fileProp = "testFileProp";
    associateFile(source, fileProp);

    File file = source.createFileProperty(fileProp);
    FileOutputStream fis = new FileOutputStream(file);
    fis.write("newcontent".getBytes());
    fis.close();

    source.deleteProperty(fileProp);
    File dir = sm.getSourceInfoDirectory();
    File[] content =
        dir.listFiles(
            new FilenameFilter() {

              @Override
              public boolean accept(File dir, String name) {
                return !name.startsWith(".");
              }
            });
    assertEquals(2, content.length);
    String[] res = new String[] {content[0].getName(), content[1].getName()};
    Arrays.sort(res);
    String[] comp = new String[] {"directory.xml", "spatial_ref_sys_extended.gdms"};
    assertArrayEquals(res, comp);
  }
コード例 #2
0
  private String associateFile(Source source, String propertyName) throws Exception {
    if (source.hasProperty(propertyName)) {
      source.deleteProperty(propertyName);
    }
    File stats = source.createFileProperty(propertyName);
    DataSource ds = dsf.getDataSource(source.getName());
    ds.open();
    long rc = ds.getRowCount();
    ds.close();

    FileOutputStream fis = new FileOutputStream(stats);
    String rcStr = Long.toString(rc);
    fis.write(rcStr.getBytes());
    fis.close();

    return rcStr;
  }