001 /*
002 * LAPIS lightweight structured text processing system
003 *
004 * Copyright (C) 1998-2002 Carnegie Mellon University,
005 * Copyright (C) 2003 Massachusetts Institute of Technology.
006 * All rights reserved.
007 *
008 * This library is free software; you can redistribute it
009 * and/or modify it under the terms of the GNU General
010 * Public License as published by the Free Software
011 * Foundation, version 2.
012 *
013 * LAPIS homepage: http://graphics.lcs.mit.edu/lapis/
014 */
015
016 package lapisx.io;
017
018 import java.io.*;
019
020 public abstract class Line {
021
022 public static String readLine (InputStream in, int max) throws IOException {
023 StringBuffer buf = new StringBuffer ();
024 int i;
025 int c = 0;
026 for (i = 0; i < max && (c = in.read ()) != -1 && c != '\n'; ++i)
027 buf.append ((char) c);
028
029 if (i == 0 && c == -1)
030 return null; // EOF
031
032 String line = buf.toString ();
033 return line;
034 }
035
036 public static void writeLine (OutputStream out, String line) throws IOException {
037 for (int i = 0, n = line.length (); i < n; ++i)
038 out.write (line.charAt(i));
039 out.write ('\n');
040 }
041 }