All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.hajdbc.state.sync.DownloadCommand Maven / Gradle / Ivy

There is a newer version: 3.6.61
Show newest version
package net.sf.hajdbc.state.sync;

import net.sf.hajdbc.logging.Level;
import net.sf.hajdbc.logging.Logger;
import net.sf.hajdbc.logging.LoggerFactory;
import net.sf.hajdbc.state.distributed.StateCommandContext;
import net.sf.hajdbc.util.MD5;

import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.security.MessageDigest;

public class DownloadCommand implements SyncCommand {
  static final Logger logger = LoggerFactory.getLogger(DownloadCommand.class);
  public static final int BLOCK_SIZE = 256 * 1024;

  private String path;
  private long offset;

  private int blockSize = BLOCK_SIZE;

  public String getPath() {
    return path;
  }

  public void setPath(String path) {
    this.path = path;
  }

  public long getOffset() {
    return offset;
  }

  public void setOffset(long offset) {
    this.offset = offset;
  }

  public int getBlockSize() {
    return blockSize;
  }

  public void setBlockSize(int blockSize) {
    this.blockSize = blockSize;
  }

  @Override
  public Block execute(StateCommandContext context) {
    Block block = new Block();
    File file = new File(path);
    MessageDigest md = MD5.newInstance();
    if(file.exists()&&offset0){
          md.update(buffer, 0, len);
          block.setMd5(MD5.md5DigestToString(md.digest()));
        }
      } catch (IOException e) {
        logger.log(Level.WARN,e);
      }
    }
    return block;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy