@Override
    protected void doRun() {
      File file;

      while ((file = filesToSave.poll()) != null || saveCount.get() < FILES_COUNT) {
        if (file != null) {
          byte data[] = file.generateData();
          dataStore.storeData(file.getSessionId(), file.getId(), data);

          if (saveCount.get() % READ_MODULO == 0) {
            filesToRead1.add(file);
          }
          saveCount.incrementAndGet();
          bytesWritten.addAndGet(data.length);
        }

        try {
          Thread.sleep(random.nextInt(SLEEP_MAX));
        } catch (InterruptedException e) {
          log.error(e.getMessage(), e);
        }
      }

      saveDone.set(true);
    }
  private FileMetaData getFileContentInfo(File file) {
    try {
      MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl();
      queryParams.add("redirect", "meta");
      ClientResponse resp =
          getRootApiWebResource()
              .path("files")
              .path(String.valueOf(file.getId()))
              .path("content")
              .queryParams(queryParams)
              .accept(MediaType.APPLICATION_OCTET_STREAM)
              .accept(MediaType.TEXT_HTML)
              .accept(MediaType.APPLICATION_XHTML_XML)
              .get(ClientResponse.class);

      String sResp = resp.getEntity(String.class);
      FileMetaData fileInfo =
          mapper.readValue(
              mapper.readValue(sResp, JsonNode.class).findPath(RESPONSE).toString(),
              FileMetaData.class);
      logger.info(fileInfo.toString());
      return fileInfo;
    } catch (BaseSpaceException bs) {
      throw bs;
    } catch (Throwable t) {
      throw new RuntimeException(t);
    }
  }
 public void resetBy(File another) {
   super.resetBy(another);
   setId(another.getId());
   setDir(another.getDir());
   setName(another.getName());
   setSize(another.getSize());
   setProductionId(another.getProductionId());
 }
  private InputStream getInputStreamInternal(File file, long start, long end, boolean refreshMeta) {
    try {
      FileMetaData fileInfo = fileToUriMap.get(file.getId());
      if (refreshMeta || (fileInfo == null || new Date().after(fileInfo.getExpires()))) {
        fileInfo = getFileContentInfo(file);
        fileToUriMap.put(file.getId(), fileInfo);
      }

      InputStream in =
          getClient()
              .resource(new URI(fileInfo.getHrefContent()))
              .accept(MediaType.APPLICATION_OCTET_STREAM)
              .accept(MediaType.TEXT_HTML)
              .accept(MediaType.APPLICATION_XHTML_XML)
              .header("Range", "bytes=" + start + "-" + end)
              .get(InputStream.class);
      return in;
    } catch (BaseSpaceException bs) {
      throw bs;
    } catch (Throwable t) {
      throw new RuntimeException(t);
    }
  }
  Element xmlExport(Element el) {

    for (User usr : getUsersSet()) {
      if (!usr.isRoot()) el.addContent(usr.xmlExport());
    }
    ArrayList<File> allfiles = getSlash().getAllFiles();

    /* Remove files that were created by users */
    for (File f : getHomeDirectory().getFilesSet()) {
      for (User usr : getUsersSet()) {
        if (f.getOwner().equals(usr)) allfiles.remove(f);
      }
    }
    Collections.reverse(allfiles);
    for (File file : allfiles) {
      if (file.getId() >= 3) el.addContent(file.xmlExport());
    }
    return el;
  }
    @Override
    protected void doRun() {
      File file;
      while ((file = filesToRead2.poll()) != null || !read1Done.get()) {
        if (file != null) {
          byte bytes[] = dataStore.getData(file.getSessionId(), file.getId());
          if (file.checkData(bytes) == false) {
            failures.incrementAndGet();
            log.error("Detected error number: " + failures.get());
          }
          read2Count.incrementAndGet();
          bytesRead.addAndGet(bytes.length);
        }

        try {
          Thread.sleep(random.nextInt(SLEEP_MAX));
        } catch (InterruptedException e) {
          log.error(e.getMessage(), e);
        }
      }

      read2Done.set(true);
    }
 @Override
 public URI getDownloadURI(File file) {
   WebResource resource =
       getRootApiWebResource().path("files").path(String.valueOf(file.getId())).path("content");
   return resource.getURI();
 }