Package java.nio.channels

Examples of java.nio.channels.FileChannel.lock()


            FileLock lock = null;
            try {
                FileInputStream istream = new FileInputStream(file);
                in = new BufferedInputStream(istream);
                FileChannel channel = istream.getChannel();
                lock = channel.lock(0L, Long.MAX_VALUE, true);
                Document doc = builder.parse(in);
                NodeList entries = XPathAPI.selectNodeList(doc
                        .getDocumentElement(), "entry"); //$NON-NLS-1$
                int length = entries.getLength();
                for (int i = 0; i < length; i++) {
View Full Code Here


        FileLock lock = null;
        try {
            FileOutputStream ostream = new FileOutputStream(file);
            out = new BufferedWriter(new OutputStreamWriter(ostream, "UTF-8")); //$NON-NLS-1$
            FileChannel channel = ostream.getChannel();
            lock = channel.lock();
            out.write(HEADER);
            out.newLine();
            out.write(FILE_PREFS);
            out.newLine();
            if (prefs.size() == 0) {
View Full Code Here

    private void lockAppCache() throws IOException {
        final Path lockFile = appCache.resolve(LOCK_FILE_NAME);
        verbose("Locking " + lockFile);
        final FileChannel c = FileChannel.open(lockFile, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
        this.appCacheLock = c.lock();
    }

    private void unlockAppCache() throws IOException {
        if (appCacheLock != null) {
            verbose("Unocking " + appCache.resolve(LOCK_FILE_NAME));
View Full Code Here

    if (fileChannel == null) {
      return;
    }
    FileLock fileLock = null;
    try {
      fileLock = fileChannel.lock();
      long position = fileChannel.position();
      long size = fileChannel.size();
      if (size != position) {
        fileChannel.position(size);
      }
View Full Code Here

        FileUtils.touch(file);
      }

      raFile = new RandomAccessFile(file, "rw");
      FileChannel fChannel = raFile.getChannel();
      fLock = fChannel.lock();

      T current = getProperty(key);
      T update = updater.update(current);
      setProperty(key, update);
    }
View Full Code Here

//      fin = new FileInputStream(file);
//      FileChannel fChannel = fin.getChannel();
      raFile = new RandomAccessFile(file, "rw");
      FileChannel fChannel = raFile.getChannel();
      fLock = fChannel.lock();

      T current = getProperty(key);
      if (comparator.compare(current, expected) == 0)
      {
//        fout = new FileOutputStream(file);
View Full Code Here

    Lock lock = writeLock(row);
    try {
      File file = getFile(row, true);
      RandomAccessFile raf = new RandomAccessFile(file, "rw");
      FileChannel channel = raf.getChannel();
      FileLock fileLock = channel.lock();
      try {
        Schema schema = value.getSchema();
        String hash = hashCache.get(schema);
        if (hash == null) {
          String doc = schema.toString();
View Full Code Here

      File file = getFile(row, true);
      if (version != 0 && !file.exists()) return false;
      if (version == 0 && file.exists()) return false;
      RandomAccessFile raf = new RandomAccessFile(file, "rw");
      FileChannel channel = raf.getChannel();
      FileLock fileLock = channel.lock();
      try {
        Schema schema = value.getSchema();
        if (file.exists()) {
          raf.seek(HASH_LENGTH);
          byte[] bytes = new byte[8];
View Full Code Here

    Lock writeLock = writeLock(row);
    try {
      File file = getFile(row, false);
      RandomAccessFile raf = new RandomAccessFile(file, "rw");
      FileChannel channel = raf.getChannel();
      FileLock fileLock = channel.lock();
      try {
        file.delete();
      } finally {
        fileLock.release();
        channel.close();
View Full Code Here

    Lock writeLock = writeLock(row);
    try {
      File file = getFile(row, true);
      FileInputStream fis = new FileInputStream(file);
      FileChannel channel = fis.getChannel();
      FileLock fileLock = channel.lock();
      try {
        Row<T, K> tStringRow = _get(row);
        if (tStringRow == null) return null;
        T mutate = tMutator.mutate(tStringRow.value);
        if (mutate != null) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.