Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CRLFDetectInputStream.java')
-rw-r--r--bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CRLFDetectInputStream.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CRLFDetectInputStream.java b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CRLFDetectInputStream.java
new file mode 100644
index 000000000..ccbd50c89
--- /dev/null
+++ b/bundles/org.eclipse.team.cvs.core/src/org/eclipse/team/internal/ccvs/core/client/CRLFDetectInputStream.java
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2003 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.team.internal.ccvs.core.client;
+
+import java.io.FilterInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.team.internal.ccvs.core.CVSProviderPlugin;
+
+/**
+ * Stream which detects CRLF in text file contents recieved from the server
+ */
+public class CRLFDetectInputStream extends FilterInputStream {
+
+ private boolean previousCR;
+ private String filename;
+
+ protected CRLFDetectInputStream(InputStream in, String filename) {
+ super(in);
+ this.filename = filename;
+ }
+
+ /**
+ * Wraps the underlying stream's method.
+ * Translates CR/LF sequences to LFs transparently.
+ * @throws InterruptedIOException if the operation was interrupted before all of the
+ * bytes specified have been skipped, bytesTransferred will be zero
+ * @throws IOException if an i/o error occurs
+ */
+ public int read() throws IOException {
+ int next = in.read();
+ if (next != -1) {
+ testForCRLF((byte)next);
+ }
+ return next;
+ }
+
+ /**
+ * Wraps the underlying stream's method.
+ * Translates CR/LF sequences to LFs transparently.
+ * @throws InterruptedIOException if the operation was interrupted before all of the
+ * bytes specified have been skipped, bytesTransferred may be non-zero
+ * @throws IOException if an i/o error occurs
+ */
+ public int read(byte[] buffer, int off, int len) throws IOException {
+ int count = super.read(buffer, off, len);
+ for (int i = off; i < count; i++) {
+ testForCRLF(buffer[i]);
+ }
+ return count;
+ }
+
+ /**
+ * Test the byte to see if a CRLF sequence was read
+ */
+ private void testForCRLF(byte next) {
+ if (previousCR && next == '\n') {
+ CVSProviderPlugin.log(IStatus.WARNING, "Server file " + filename + " contains invalid line endings for a text file (CR/LF instead of just LF) or is a binary file that is not properly marked as such.", null);
+ }
+ previousCR = (next == '\r');
+ }
+}

Back to the top