1 11 package org.eclipse.team.internal.ccvs.core.client; 12 13 import java.io.*; 14 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.osgi.util.NLS; 18 import org.eclipse.team.internal.ccvs.core.*; 19 20 23 public class CRLFDetectInputStream extends FilterInputStream { 24 25 private boolean previousCR; 26 private String filename; 27 private boolean reported = false; 28 29 protected CRLFDetectInputStream(InputStream in, ICVSStorage file) { 30 super(in); 31 try { 32 this.filename = getFileName(file); 33 } catch (CVSException e) { 34 this.filename = file.getName(); 35 } 36 } 37 38 private String getFileName(ICVSStorage storage) throws CVSException { 39 String fileName; 40 if (storage instanceof ICVSFile) { 41 ICVSFile file = (ICVSFile)storage; 42 fileName = file.getRepositoryRelativePath(); 43 if (fileName == null) { 44 IResource resource = file.getIResource(); 45 if (resource == null) { 46 fileName = file.getName(); 47 } else { 48 fileName = file.getIResource().getFullPath().toString(); 50 } 51 } 52 } else { 53 fileName = storage.getName(); 54 } 55 return fileName; 56 } 57 58 65 public int read() throws IOException { 66 int next = in.read(); 67 if (next != -1) { 68 testForCRLF((byte)next); 69 } 70 return next; 71 } 72 73 80 public int read(byte[] buffer, int off, int len) throws IOException { 81 int count = super.read(buffer, off, len); 82 for (int i = off; i < count; i++) { 83 testForCRLF(buffer[i]); 84 } 85 return count; 86 } 87 88 91 private void testForCRLF(byte next) { 92 if (reported) return; 93 if (previousCR && next == '\n') { 94 CVSProviderPlugin.log(IStatus.WARNING, NLS.bind(CVSMessages.CRLFDetectInputStream_0, new String [] { filename }), null); 95 reported = true; 96 } 97 previousCR = (next == '\r'); 98 } 99 } 100 | Popular Tags |