1 28 package net.sf.jasperreports.engine.util; 29 30 import java.io.IOException ; 31 import java.nio.ByteBuffer ; 32 import java.nio.channels.FileChannel ; 33 34 import net.sf.jasperreports.engine.JRRuntimeException; 35 36 37 45 public class JRConcurrentSwapFile extends JRSwapFile 46 { 47 48 private final FileChannel fileChannel; 49 50 59 public JRConcurrentSwapFile(String directory, int blockSize, int minGrowCount) 60 { 61 super(directory, blockSize, minGrowCount); 62 63 fileChannel = file.getChannel(); 64 } 65 66 protected void write(byte[] data, int dataSize, int dataOffset, long fileOffset) throws IOException 67 { 68 fileChannel.write(ByteBuffer.wrap(data, dataOffset, dataSize), fileOffset); 69 } 70 71 protected void read(byte[] data, int dataOffset, int dataLength, long fileOffset) throws IOException 72 { 73 ByteBuffer buffer = ByteBuffer.wrap(data, dataOffset, dataLength); 74 int read, totalRead = 0; 75 do 76 { 77 read = fileChannel.read(buffer, fileOffset + totalRead); 78 if (read < 0) 79 { 80 throw new JRRuntimeException("Unable to read sufficient data from the swap file"); 81 } 82 totalRead += read; 83 } 84 while (totalRead < dataLength); 85 } 86 87 } 88 | Popular Tags |