Changeset 5626


Ignore:
Timestamp:
01/31/04 19:04:44 (17 years ago)
Author:
piso
Message:

fileLength()

Location:
trunk/j/src/org/armedbear/lisp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/j/src/org/armedbear/lisp/FileStream.java

    r5620 r5626  
    33 *
    44 * Copyright (C) 2004 Peter Graves
    5  * $Id: FileStream.java,v 1.6 2004-01-31 13:43:55 piso Exp $
     5 * $Id: FileStream.java,v 1.7 2004-01-31 19:04:44 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    104104            return NIL;
    105105        }
     106    }
     107
     108    public LispObject fileLength() throws ConditionThrowable
     109    {
     110        String namestring = pathname.getNamestring();
     111        if (namestring == null)
     112            return signal(new SimpleError("Pathname has no namestring: " +
     113                                          pathname + '.'));
     114        File file = new File(namestring);
     115        long length = file.length(); // in 8-bit bytes
     116        if (isCharacterStream)
     117            return number(length);
     118        // "For a binary file, the length is measured in units of the
     119        // element type of the stream."
     120        int width = Fixnum.getValue(elementType.cadr());
     121        int bytesPerUnit = width / 8;
     122        return number(length / bytesPerUnit);
    106123    }
    107124
  • trunk/j/src/org/armedbear/lisp/Stream.java

    r5621 r5626  
    33 *
    44 * Copyright (C) 2003-2004 Peter Graves
    5  * $Id: Stream.java,v 1.15 2004-01-31 13:44:20 piso Exp $
     5 * $Id: Stream.java,v 1.16 2004-01-31 19:03:48 piso Exp $
    66 *
    77 * This program is free software; you can redistribute it and/or
     
    11341134    }
    11351135
     1136    public LispObject fileLength() throws ConditionThrowable
     1137    {
     1138        return signal(new TypeError("Stream is not associated with a file."));
     1139    }
     1140
    11361141    // Returns -1 at end of file.
    11371142    protected int _readChar() throws ConditionThrowable
Note: See TracChangeset for help on using the changeset viewer.