comparison src/org/tmatesoft/hg/internal/NewlineFilter.java @ 423:9c9c442b5f2e

Major refactoring of exception handling. Low-level API uses RuntimeExceptions, while checked are left for higher level
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Fri, 23 Mar 2012 22:51:18 +0100
parents 91d75e1bac9f
children 909306e412e2
comparison
equal deleted inserted replaced
422:5d1cc7366d04 423:9c9c442b5f2e
26 import java.io.IOException; 26 import java.io.IOException;
27 import java.nio.ByteBuffer; 27 import java.nio.ByteBuffer;
28 import java.util.ArrayList; 28 import java.util.ArrayList;
29 import java.util.Map; 29 import java.util.Map;
30 30
31 import org.tmatesoft.hg.core.HgBadStateException;
32 import org.tmatesoft.hg.repo.HgInternals; 31 import org.tmatesoft.hg.repo.HgInternals;
32 import org.tmatesoft.hg.repo.HgInvalidStateException;
33 import org.tmatesoft.hg.repo.HgRepository; 33 import org.tmatesoft.hg.repo.HgRepository;
34 import org.tmatesoft.hg.util.Adaptable; 34 import org.tmatesoft.hg.util.Adaptable;
35 import org.tmatesoft.hg.util.Path; 35 import org.tmatesoft.hg.util.Path;
36 36
37 /** 37 /**
65 processInconsistent = !onlyConsistent; 65 processInconsistent = !onlyConsistent;
66 } 66 }
67 67
68 public ByteBuffer filter(ByteBuffer src) { 68 public ByteBuffer filter(ByteBuffer src) {
69 if (!processInconsistent && !previewDone) { 69 if (!processInconsistent && !previewDone) {
70 throw new HgBadStateException("This filter requires preview operation prior to actual filtering when eol.only-consistent is true"); 70 throw new HgInvalidStateException("This filter requires preview operation prior to actual filtering when eol.only-consistent is true");
71 } 71 }
72 if (!processInconsistent && foundLoneLF && foundCRLF) { 72 if (!processInconsistent && foundLoneLF && foundCRLF) {
73 // do not process inconsistent newlines 73 // do not process inconsistent newlines
74 return src; 74 return src;
75 } 75 }
268 private void fail(ByteBuffer b, int pos) { 268 private void fail(ByteBuffer b, int pos) {
269 StringBuilder sb = new StringBuilder(); 269 StringBuilder sb = new StringBuilder();
270 for (int i = max(pos-10, 0), x = min(pos + 10, b.limit()); i < x; i++) { 270 for (int i = max(pos-10, 0), x = min(pos + 10, b.limit()); i < x; i++) {
271 sb.append(String.format("%02x ", b.get(i))); 271 sb.append(String.format("%02x ", b.get(i)));
272 } 272 }
273 throw new HgBadStateException(String.format("Inconsistent newline characters in the stream %s (char 0x%x, local index:%d)", sb.toString(), b.get(pos), pos)); 273 // TODO post-1.0 need HgBadDataException (not InvalidState but smth closer to data stream error)
274 // but don't want to add class for the single use now
275 throw new HgInvalidStateException(String.format("Inconsistent newline characters in the stream %s (char 0x%x, local index:%d)", sb.toString(), b.get(pos), pos));
274 } 276 }
275 277
276 private static int indexOf(byte ch, ByteBuffer b, int from) { 278 private static int indexOf(byte ch, ByteBuffer b, int from) {
277 return indexOf(ch, b, from, b.limit()); 279 return indexOf(ch, b, from, b.limit());
278 } 280 }