Package java.io

Examples of java.io.RandomAccessFile$RepositionLock


        f.setReadOnly();
        assertTrue(!f.canWrite());
        f.delete();

        f = File.createTempFile("test", "temp");
        RandomAccessFile r = new RandomAccessFile(f, "rw");
        r.write(1);
        f.setReadOnly();
        r.close();
        assertTrue(!f.canWrite());
        f.delete();

        deleteDb("readonly");
        Connection conn = getConnection("readonly");
View Full Code Here


        BTreePersistentIndexedCache<String, Integer> cache = new BTreePersistentIndexedCache<String, Integer>(backingCache, serializer);

        assertNull(cache.get("key_1"));
        cache.put("key_1", 99);

        RandomAccessFile file = new RandomAccessFile(testFile, "rw");
        file.setLength(file.length() - 10);

        cache.reset();

        assertNull(cache.get("key_1"));
        cache.verify();
View Full Code Here

            this.mode = MapMode.READ_ONLY;
        } else {
            this.mode = MapMode.READ_WRITE;
        }
        this.name = fileName;
        file = new RandomAccessFile(fileName, mode);
        reMap();
    }
View Full Code Here

        transformers = new int[1];
        transformers[0] = XmlTransformers._HTML;
       
        File file = getFile();
        try {
            RandomAccessFile raf = new RandomAccessFile(file, "r");
            long length = raf.length();
           
            while (raf.getFilePointer() < length) {
                String line = raf.readLine();
                if (line.toLowerCase().indexOf("xmlns:fo=\"http://www.w3.org/1999/xsl/format\"") > -1) {
                    transformers = new int[2];
                    transformers[0] = XmlTransformers._PDF;
                    transformers[1] = XmlTransformers._RTF;
                }
            }
           
            raf.close();
        } catch (IOException e) {
            logger.error("Could not determine if PDF / RTF is supported for file " + file , e);
        }
    }
View Full Code Here

        throw( new IOException( "destroyed" ));
      }
     
      if ( raf == null ){
           
        raf = new RandomAccessFile( source_file, "r" );
      }
     
      raf_count++;
     
      return( raf );
View Full Code Here

    new AEThread2( "TranscodePipe:c", true )
    {
      public void
      run()
      {
        RandomAccessFile  raf = null;
       
        try{
          raf = reserveRAF();

          long  pos  = position;
         
          long  rem = length;
         
          while( !destroyed && rem > 0){
                                 
            int  limit;

            if ( paused ){
             
              Thread.sleep(250);
             
              limit = 1;
             
            }else{
                         
              if ( max_bytes_per_sec > 0 ){
               
                limit = bytes_available;
               
                if ( limit <= 0 ){
                 
                  Thread.sleep( 25 );
                 
                  continue;
                }
               
                limit = Math.min( BUFFER_SIZE, limit );
               
              }else{
               
                limit = BUFFER_SIZE;
              }
             
              limit = (int)Math.min( rem, limit );
            }
           
            int  read_length  = 0;
           
            int    buffer_start   = 0;
            byte[]   buffer      = null;
           
            synchronized( TranscodePipe.this ){
           
              int  c_num = 0;
             
              Iterator<bufferCache> it = buffer_cache.iterator();
             
              while( it.hasNext()){
               
                bufferCache b = it.next();
               
                long  rel_offset = pos - b.offset;
               
                if ( rel_offset >= 0 ){
                 
                  byte[]   data = b.data;
                 
                  long avail = data.length - rel_offset;
                 
                  if ( avail > 0 ){
                   
                    read_length = (int)Math.min( avail, limit );
                   
                    buffer       = data;
                    buffer_start   = (int)rel_offset;
                   
                    //System.out.println( "using cache entry: o_offset=" + pos + ",r_offset=" + rel_offset+",len=" + read_length );
                   
                    if ( c_num > 0 ){
                   
                      it.remove();
                   
                      buffer_cache.addFirst( b );
                    }
                   
                    break;
                  }
                }
               
                c_num++;
              }
             
              if ( buffer == null ){
             
                buffer = new byte[ limit ];

                raf.seek( pos );
             
                read_length =  raf.read( buffer );
               
                if ( read_length != limit ){
                 
                  Debug.out( "eh?");
                 
                  throw( new IOException( "Inconsistent" ));
                }
               
                bufferCache b = new bufferCache( pos, buffer );
               
                // System.out.println( "adding to cache: o_offset=" + pos + ", size=" + limit );
               
                buffer_cache.addFirst( b );
               
                buffer_cache_size += limit;
               
                while( buffer_cache_size > BUFFER_CACHE_SIZE ){
                 
                  b = buffer_cache.removeLast();
                 
                  buffer_cache_size -= b.data.length;
                }
              }
            }
             
            if ( read_length <= 0 ){
               
              break;
            }
             
            rem -= read_length;
            pos += read_length;
           
            if ( max_bytes_per_sec > 0 ){
           
              bytes_available -= read_length;
            }
           
            os.write( buffer, buffer_start, read_length );   
           
            write_speed.addValue( read_length );
          }
         
          os.flush();
         
        }catch( Throwable e ){
       
          if ( raf != null ){
           
            try{
              synchronized( TranscodePipe.this ){

                raf.seek( 0 );
             
                raf.read( new byte[1] );
              }
            }catch( Throwable f ){
             
              reportError( e );
            }
View Full Code Here

    this.r = read;
    this.w = write;
    String mode = "";
    if(this.r) { mode += "r"; }
    if(this.w) { mode += "w"; }
    this.delegate = new RandomAccessFile(file, mode);
  }
View Full Code Here

     * @throws DiskCacheException if any exceptioins occur.
     */
    public CacheFileAdapter(final File file) {
        this.filepath = file.getAbsolutePath();
        try {
            raf = new RandomAccessFile(filepath, "rw");
        } catch (FileNotFoundException e) {
            throw new IllegalStateException(
                "The disk cache could not be initialized.");
        }
    }
View Full Code Here

      } catch (InterruptedException e1) {
        //interrupted.
      }
        }
        try {
            raf = new RandomAccessFile(filepath, "rw");
        } catch (FileNotFoundException e) {
            throw new IllegalStateException(e.getMessage());
        }
    }
View Full Code Here

        open(new File(fileName), mode);
    }

    private void open(File file, String mode) throws ChaiDBException {
        try {
            this.file = new RandomAccessFile(file, mode);
        } catch (FileNotFoundException fnfe) {
            try {
                String dir = file.getAbsolutePath();
                dir = dir.substring(0, dir.lastIndexOf(File.separator));
                new File(dir).mkdirs();
                this.file = new RandomAccessFile(file, "rws");
            } catch (Exception e) {
                String details = "Open for file " + file.getName() + " failed. " + e.toString() + ".";
                throw new ChaiDBException(0, details);
            }
        } catch (IOException ioe) {
View Full Code Here

TOP

Related Classes of java.io.RandomAccessFile$RepositionLock

Copyright © 2018 www.massapicom. 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.