Mercurial > jhg
comparison src/org/tmatesoft/hg/repo/HgDataFile.java @ 619:868b2ffdcd5c
Close FIS, not FileChannel, to clear both references to FileDescriptor right away
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> | 
|---|---|
| date | Fri, 17 May 2013 22:04:23 +0200 | 
| parents | e1b29756f901 | 
| children | 99ad1e3a4e4d | 
   comparison
  equal
  deleted
  inserted
  replaced
| 618:7c0d2ce340b8 | 619:868b2ffdcd5c | 
|---|---|
| 18 | 18 | 
| 19 import static org.tmatesoft.hg.core.HgIterateDirection.OldToNew; | 19 import static org.tmatesoft.hg.core.HgIterateDirection.OldToNew; | 
| 20 import static org.tmatesoft.hg.repo.HgInternals.wrongRevisionIndex; | 20 import static org.tmatesoft.hg.repo.HgInternals.wrongRevisionIndex; | 
| 21 import static org.tmatesoft.hg.repo.HgRepository.*; | 21 import static org.tmatesoft.hg.repo.HgRepository.*; | 
| 22 import static org.tmatesoft.hg.util.LogFacility.Severity.Info; | 22 import static org.tmatesoft.hg.util.LogFacility.Severity.Info; | 
| 23 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; | |
| 24 | 23 | 
| 25 import java.io.File; | 24 import java.io.File; | 
| 26 import java.io.FileInputStream; | 25 import java.io.FileInputStream; | 
| 27 import java.io.IOException; | 26 import java.io.IOException; | 
| 28 import java.nio.ByteBuffer; | 27 import java.nio.ByteBuffer; | 
| 35 import org.tmatesoft.hg.core.Nodeid; | 34 import org.tmatesoft.hg.core.Nodeid; | 
| 36 import org.tmatesoft.hg.internal.BlameHelper; | 35 import org.tmatesoft.hg.internal.BlameHelper; | 
| 37 import org.tmatesoft.hg.internal.DataAccess; | 36 import org.tmatesoft.hg.internal.DataAccess; | 
| 38 import org.tmatesoft.hg.internal.FileHistory; | 37 import org.tmatesoft.hg.internal.FileHistory; | 
| 39 import org.tmatesoft.hg.internal.FileRevisionHistoryChunk; | 38 import org.tmatesoft.hg.internal.FileRevisionHistoryChunk; | 
| 39 import org.tmatesoft.hg.internal.FileUtils; | |
| 40 import org.tmatesoft.hg.internal.FilterByteChannel; | 40 import org.tmatesoft.hg.internal.FilterByteChannel; | 
| 41 import org.tmatesoft.hg.internal.FilterDataAccess; | 41 import org.tmatesoft.hg.internal.FilterDataAccess; | 
| 42 import org.tmatesoft.hg.internal.Internals; | 42 import org.tmatesoft.hg.internal.Internals; | 
| 43 import org.tmatesoft.hg.internal.Metadata; | 43 import org.tmatesoft.hg.internal.Metadata; | 
| 44 import org.tmatesoft.hg.internal.RevlogStream; | 44 import org.tmatesoft.hg.internal.RevlogStream; | 
| 45 import org.tmatesoft.hg.repo.HgBlameInspector; | |
| 46 import org.tmatesoft.hg.util.ByteChannel; | 45 import org.tmatesoft.hg.util.ByteChannel; | 
| 47 import org.tmatesoft.hg.util.CancelSupport; | 46 import org.tmatesoft.hg.util.CancelSupport; | 
| 48 import org.tmatesoft.hg.util.CancelledException; | 47 import org.tmatesoft.hg.util.CancelledException; | 
| 49 import org.tmatesoft.hg.util.LogFacility; | 48 import org.tmatesoft.hg.util.LogFacility; | 
| 50 import org.tmatesoft.hg.util.Pair; | 49 import org.tmatesoft.hg.util.Pair; | 
| 166 final ProgressSupport progress = ProgressSupport.Factory.get(sink); | 165 final ProgressSupport progress = ProgressSupport.Factory.get(sink); | 
| 167 final long flength = f.length(); | 166 final long flength = f.length(); | 
| 168 final int bsize = (int) Math.min(flength, 32*1024); | 167 final int bsize = (int) Math.min(flength, 32*1024); | 
| 169 progress.start((int) (flength > Integer.MAX_VALUE ? flength >>> 15 /*32 kb buf size*/ : flength)); | 168 progress.start((int) (flength > Integer.MAX_VALUE ? flength >>> 15 /*32 kb buf size*/ : flength)); | 
| 170 ByteBuffer buf = ByteBuffer.allocate(bsize); | 169 ByteBuffer buf = ByteBuffer.allocate(bsize); | 
| 171 FileChannel fc = null; | 170 FileInputStream fis = null; | 
| 172 try { | 171 try { | 
| 173 fc = new FileInputStream(f).getChannel(); | 172 fis = new FileInputStream(f); | 
| 173 FileChannel fc = fis.getChannel(); | |
| 174 while (fc.read(buf) != -1) { | 174 while (fc.read(buf) != -1) { | 
| 175 cs.checkCancelled(); | 175 cs.checkCancelled(); | 
| 176 buf.flip(); | 176 buf.flip(); | 
| 177 int consumed = sink.write(buf); | 177 int consumed = sink.write(buf); | 
| 178 progress.worked(flength > Integer.MAX_VALUE ? 1 : consumed); | 178 progress.worked(flength > Integer.MAX_VALUE ? 1 : consumed); | 
| 180 } | 180 } | 
| 181 } catch (IOException ex) { | 181 } catch (IOException ex) { | 
| 182 throw new HgInvalidFileException("Working copy read failed", ex, f); | 182 throw new HgInvalidFileException("Working copy read failed", ex, f); | 
| 183 } finally { | 183 } finally { | 
| 184 progress.done(); | 184 progress.done(); | 
| 185 if (fc != null) { | 185 if (fis != null) { | 
| 186 try { | 186 new FileUtils(getRepo().getSessionContext().getLog()).closeQuietly(fis); | 
| 187 fc.close(); | |
| 188 } catch (IOException ex) { | |
| 189 getRepo().getSessionContext().getLog().dump(getClass(), Warn, ex, null); | |
| 190 } | |
| 191 } | 187 } | 
| 192 } | 188 } | 
| 193 } else { | 189 } else { | 
| 194 Nodeid fileRev = getWorkingCopyRevision(); | 190 Nodeid fileRev = getWorkingCopyRevision(); | 
| 195 if (fileRev == null) { | 191 if (fileRev == null) { | 
