|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2003 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.tasklist.usertasks.ics.parser; import java.io.FilterReader; import java.io.Reader; /** * Special reader for ICS files that removes "\r\n\t" and "\r\n " sequences. * * @author Tim Lebedkov */ public class IcsReader extends FilterReader { private int[] buffer = new int[3]; private int bufferSize = 0; public IcsReader(Reader in) { super(in); } public int read(char[] cbuf, int off, int len) throws java.io.IOException { if (len == 0) return 0; for (int i = 0; i < len; i++) { int c = read(); if (c == -1) { if (i == 0) return -1; else return i; } cbuf[off + i] = (char) c; } return len; } public int read() throws java.io.IOException { if (bufferSize > 0) { bufferSize--; return buffer[bufferSize]; } int c1 = super.read(); if (c1 != '\r') return c1; int c2 = super.read(); if (c2 != '\n') { bufferSize = 1; buffer[0] = c2; return c1; } int c3 = super.read(); if (c3 != '\t' && c3 != ' ') { bufferSize = 2; buffer[0] = c3; buffer[1] = c2; return c1; } return super.read(); } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.