comparison src/org/tmatesoft/hg/internal/FNCacheFile.java @ 667:fba85bc1dfb8

Refactoring: move all encoding/decoding operations into single place, EncodingHelper
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 11 Jul 2013 17:54:08 +0200
parents ae2d439fbed3
children
comparison
equal deleted inserted replaced
666:27a3ddedd6cc 667:fba85bc1dfb8
22 import java.io.FileOutputStream; 22 import java.io.FileOutputStream;
23 import java.io.IOException; 23 import java.io.IOException;
24 import java.nio.ByteBuffer; 24 import java.nio.ByteBuffer;
25 import java.nio.CharBuffer; 25 import java.nio.CharBuffer;
26 import java.nio.channels.FileChannel; 26 import java.nio.channels.FileChannel;
27 import java.nio.charset.Charset;
28 import java.util.ArrayList; 27 import java.util.ArrayList;
29 import java.util.List; 28 import java.util.List;
30 29
31 import org.tmatesoft.hg.core.HgIOException; 30 import org.tmatesoft.hg.core.HgIOException;
32 import org.tmatesoft.hg.util.Path; 31 import org.tmatesoft.hg.util.Path;
81 if (addedDotI.isEmpty() && addedDotD.isEmpty()) { 80 if (addedDotI.isEmpty() && addedDotD.isEmpty()) {
82 return; 81 return;
83 } 82 }
84 File f = repo.getRepositoryFile(FNCache); 83 File f = repo.getRepositoryFile(FNCache);
85 f.getParentFile().mkdirs(); 84 f.getParentFile().mkdirs();
86 final Charset filenameEncoding = repo.getFilenameEncoding(); 85 final EncodingHelper fnEncoder = repo.buildFileNameEncodingHelper();
87 ArrayList<CharBuffer> added = new ArrayList<CharBuffer>(); 86 ArrayList<CharBuffer> added = new ArrayList<CharBuffer>();
88 for (Path p : addedDotI) { 87 for (Path p : addedDotI) {
89 added.add(CharBuffer.wrap(pathHelper.rewrite(p))); 88 added.add(CharBuffer.wrap(pathHelper.rewrite(p)));
90 } 89 }
91 for (Path p : addedDotD) { 90 for (Path p : addedDotD) {
103 try { 102 try {
104 fos = new FileOutputStream(f, true); 103 fos = new FileOutputStream(f, true);
105 FileChannel fncacheFile = fos.getChannel(); 104 FileChannel fncacheFile = fos.getChannel();
106 ByteBuffer lf = ByteBuffer.wrap(new byte[] { 0x0A }); 105 ByteBuffer lf = ByteBuffer.wrap(new byte[] { 0x0A });
107 for (CharBuffer b : added) { 106 for (CharBuffer b : added) {
108 fncacheFile.write(filenameEncoding.encode(b)); 107 fncacheFile.write(fnEncoder.toFNCache(b));
109 fncacheFile.write(lf); 108 fncacheFile.write(lf);
110 lf.rewind(); 109 lf.rewind();
111 } 110 }
112 fncacheFile.force(true); 111 fncacheFile.force(true);
113 tr.done(f); 112 tr.done(f);