congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
FileStorage
Code IndexAdd Tabnine to your IDE (free)

How to use
FileStorage
in
org.lealone.storage.fs

Best Java code snippets using org.lealone.storage.fs.FileStorage (Showing top 20 results out of 315)

origin: lealone/Lealone

@Override
public FileStorage openFile(String name, String mode, boolean mustExist) {
  if (mustExist && !FileUtils.exists(name)) {
    throw DbException.get(ErrorCode.FILE_NOT_FOUND_1, name);
  }
  FileStorage fileStorage;
  if (cipher == null) {
    fileStorage = FileStorage.open(this, name, mode);
  } else {
    fileStorage = FileStorage.open(this, name, mode, cipher, fileEncryptionKey, 0);
  }
  fileStorage.setCheckedWriting(false);
  try {
    fileStorage.init();
  } catch (DbException e) {
    fileStorage.closeSilently();
    throw e;
  }
  return fileStorage;
}
origin: lealone/Lealone

private FileStorage getFileStorage(int chunkId) {
  String chunkFileName = btreeStoragePath + File.separator + chunkId + AOStorage.SUFFIX_AO_FILE;
  FileStorage fileStorage = new FileStorage();
  fileStorage.open(chunkFileName, map.config);
  return fileStorage;
}
origin: lealone/Lealone

byte[] salt;
byte[] magic = HEADER.getBytes();
if (length() < HEADER_LENGTH) {
  writeDirect(magic, 0, len);
  salt = generateSalt();
  writeDirect(salt, 0, len);
  initKey(salt);
  write(magic, 0, len);
  checkedWriting = true;
} else {
  seek(0);
  byte[] buff = new byte[len];
  readFullyDirect(buff, 0, len);
  if (!Arrays.equals(buff, magic)) {
    throw DbException.get(ErrorCode.FILE_VERSION_ERROR_1, name);
  readFullyDirect(salt, 0, len);
  initKey(salt);
  readFully(buff, 0, Constants.FILE_BLOCK_SIZE);
  if (!Arrays.equals(buff, magic)) {
    throw DbException.get(ErrorCode.FILE_ENCRYPTION_ERROR_1, name);
origin: lealone/Lealone

@Override
public void done() {
  file.seek(FileStorage.HEADER_LENGTH);
  file.autoDelete();
}
origin: lealone/Lealone

/**
 * Close the result list and delete the temporary file.
 */
public void close() {
  if (file != null) {
    file.autoDelete();
    file.closeAndDeleteSilently();
    file = null;
    rowBuff = null;
  }
}
origin: lealone/Lealone

@Override
public FileStorage openFile(String name, String openMode, boolean mustExist) {
  if (mustExist && !FileUtils.exists(name)) {
    throw DbException.get(ErrorCode.FILE_NOT_FOUND_1, name);
  }
  FileStorage fileStorage = FileStorage.open(this, name, openMode, dbSettings.cipher,
      dbSettings.filePasswordHash);
  try {
    fileStorage.init();
  } catch (DbException e) {
    fileStorage.closeSilently();
    throw e;
  }
  return fileStorage;
}
origin: lealone/Lealone

private void initStore() {
  Database db = session.getDatabase();
  byte[] key = null;
  if (cipher != null && password != null) {
    char[] pass = password.optimize(session).getValue(session).getString().toCharArray();
    key = SHA256.getKeyPasswordHash("script", pass);
  }
  String file = getFileName();
  fileStorage = FileStorage.open(db, file, "rw", cipher, key);
  fileStorage.setCheckedWriting(false);
  fileStorage.init();
}
origin: lealone/Lealone

RedoLogChunk(int id, Map<String, String> config) {
  this.id = id;
  this.config = config;
  String chunkFileName = getChunkFileName(config, id);
  fileStorage = new FileStorage();
  fileStorage.open(chunkFileName, config);
  queue = new LinkedTransferQueue<>();
  pos = fileStorage.size();
  if (pos > 0)
    read();
}
origin: lealone/Lealone

/**
 * Read a number of bytes without decrypting.
 *
 * @param b the target buffer
 * @param off the offset
 * @param len the number of bytes to read
 */
protected void readFullyDirect(byte[] b, int off, int len) {
  readFully(b, off, len);
}
origin: lealone/Lealone

fileStorage.openFile();
if (fileStorage.length() == fileStorage.getFilePointer()) {
  close();
  return;
fileStorage.readFully(page.getBytes(), 0, Constants.FILE_BLOCK_SIZE);
page.reset();
remainingInBuffer = page.getInt();
page.reset();
page.getInt();
fileStorage.readFully(page.getBytes(), Constants.FILE_BLOCK_SIZE, len);
page.reset();
page.getInt();
  fileStorage.closeFile();
origin: lealone/Lealone

/**
 * Open a non encrypted file store with the given settings.
 *
 * @param handler the data handler
 * @param name the file name
 * @param mode the access mode (r, rw, rws, rwd)
 * @return the created object
 */
public static FileStorage open(DataHandler handler, String name, String mode) {
  return open(handler, name, mode, null, null, 0);
}
origin: lealone/Lealone

private void writeAllRows() {
  if (file == null) {
    Database db = session.getDatabase();
    String fileName = db.createTempFile();
    file = db.openFile(fileName, "rw", false);
    file.setCheckedWriting(false);
    file.seek(FileStorage.HEADER_LENGTH);
    rowBuff = DataBuffer.create(db, Constants.DEFAULT_PAGE_SIZE);
    file.seek(FileStorage.HEADER_LENGTH);
  }
  DataBuffer buff = rowBuff;
  initBuffer(buff);
  for (int i = 0, size = list.size(); i < size; i++) {
    if (i > 0 && buff.length() > Constants.IO_BUFFER_SIZE) {
      flushBuffer(buff);
      initBuffer(buff);
    }
    Row r = list.get(i);
    writeRow(buff, r);
  }
  flushBuffer(buff);
  file.autoDelete();
  list.clear();
  memory = 0;
}
origin: lealone/Lealone

@Override
public void close() {
  if (fileStorage != null) {
    try {
      fileStorage.close();
      endOfFile = true;
    } finally {
      fileStorage = null;
    }
  }
}
origin: stackoverflow.com

 public static void main(String[] args){
  FileStorage fileStorage = new FileStorage();

  // User create a new file
  File file1 = new File();

  fileStorage.addNewFile(file1, "file1"); // name can also be file1.getName()

  [...]

  // Later you can access the file
  File storedFile = fileStorage.getStoredFile("file1");
}
origin: lealone/Lealone

/**
 * Close the file (ignoring exceptions) and delete the file.
 */
public void closeAndDeleteSilently() {
  if (file != null) {
    closeSilently();
    tempFileDeleter.deleteFile(autoDeleteReference, name);
    name = null;
  }
}
origin: lealone/Lealone

/**
 * Open an encrypted file store with the given settings.
 *
 * @param handler the data handler
 * @param name the file name
 * @param mode the access mode (r, rw, rws, rwd)
 * @param cipher the name of the cipher algorithm
 * @param key the encryption key
 * @param keyIterations the number of iterations the key should be hashed
 * @return the created object
 */
public static FileStorage open(DataHandler handler, String name, String mode, String cipher, byte[] key,
    int keyIterations) {
  FileStorage store;
  if (cipher == null) {
    store = new FileStorage(handler, name, mode);
  } else {
    store = new SecureFileStorage(handler, name, mode, cipher, key, keyIterations);
  }
  return store;
}
origin: lealone/Lealone

ResultDiskBuffer(ServerSession session, SortOrder sort, int columnCount) {
  this.parent = null;
  this.sort = sort;
  this.columnCount = columnCount;
  Database db = session.getDatabase();
  rowBuff = DataBuffer.create(db, Constants.DEFAULT_PAGE_SIZE);
  String fileName = db.createTempFile();
  file = db.openFile(fileName, "rw", false);
  file.setCheckedWriting(false);
  file.seek(FileStorage.HEADER_LENGTH);
  if (sort != null) {
    tapes = Utils.newSmallArrayList();
    mainTape = null;
  } else {
    tapes = null;
    mainTape = new ResultDiskTape();
    mainTape.pos = FileStorage.HEADER_LENGTH;
  }
  this.maxBufferSize = db.getSettings().largeResultBufferSize;
}
origin: lealone/Lealone

private void removeUnusedChunks(TreeSet<Long> removedPages) {
  int size = removedPages.size();
  for (BTreeChunk c : findUnusedChunks(removedPages)) {
    c.fileStorage.close();
    c.fileStorage.delete();
    chunks.remove(c.id);
    chunkIds.clear(c.id);
    removedPages.removeAll(c.pagePositions);
  }
  if (size > removedPages.size()) {
    writeChunkMetaData(lastChunk.id, removedPages);
  }
}
origin: lealone/Lealone

long start = file.getFilePointer();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int bufferLen = 0;
      byte[] data = buffer.toByteArray();
      buffer.reset();
      file.write(data, 0, data.length);
      bufferLen = 0;
    file.write(buff.getBytes(), 0, len);
  file.write(data, 0, data.length);
  tape.end = file.getFilePointer();
  tapes.add(tape);
} else {
  mainTape.end = file.getFilePointer();
origin: lealone/Lealone

/**
 * Create a CLOB in a temporary file.
 */
private ValueLob(DataHandler handler, Reader in, long remaining) throws IOException {
  this.type = Value.CLOB;
  this.handler = handler;
  this.small = null;
  this.lobId = 0;
  this.hmac = null;
  this.fileName = createTempLobFileName(handler);
  this.tempFile = this.handler.openFile(fileName, "rw", false);
  this.tempFile.autoDelete();
  FileStorageOutputStream out = new FileStorageOutputStream(tempFile, null, null);
  long tmpPrecision = 0;
  try {
    char[] buff = new char[Constants.IO_BUFFER_SIZE];
    while (true) {
      int len = getBufferSize(this.handler, false, remaining);
      len = IOUtils.readFully(in, buff, len);
      if (len == 0) {
        break;
      }
    }
  } finally {
    out.close();
  }
  this.precision = tmpPrecision;
}
org.lealone.storage.fsFileStorage

Javadoc

This class is an abstraction of a random access file. Each file contains a magic header, and reading / writing is done in blocks. See also SecureFileStorage

Most used methods

  • open
    Open an encrypted file store with the given settings.
  • <init>
    Create a new file using the given settings.
  • closeSilently
    Close the file without throwing any exceptions. Exceptions are simply ignored.
  • readFully
    Read a number of bytes.
  • close
    Close this file.
  • init
    Initialize the file. This method will write or check the file header if required.
  • setCheckedWriting
  • autoDelete
    Automatically delete the file once it is no longer in use.
  • getFilePointer
    Get the current location of the file pointer.
  • seek
    Go to the specified file location.
  • sync
    Flush all changes.
  • write
    Write a number of bytes.
  • sync,
  • write,
  • writeFully,
  • addNewFile,
  • checkPowerOff,
  • checkWritingAllowed,
  • closeAndDeleteSilently,
  • closeFile,
  • closeFileSilently,
  • delete

Popular in Java

  • Creating JSON documents from java classes using gson
  • runOnUiThread (Activity)
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • compareTo (BigDecimal)
  • SocketTimeoutException (java.net)
    This exception is thrown when a timeout expired on a socket read or accept operation.
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • Runner (org.openjdk.jmh.runner)
  • Top 17 PhpStorm Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now