import java.io.*; class ConArc { // Copyleft Harvey Greenberg, UW hgreen@u.washington.edu Feb 5 14:59:45 1997 // Error handling is neither complete nor elegant // This class is equivalent to a record in an ARC/INFO AAT (arc attribute table) // Its usefulness is limited by the fact the the item list, which contains // more than the default items, is hardwired. See Arccheck for examples of // loading an array of class. // Caveats: // Error handling is neither complete nor elegant // This assumes a specific item list for the arcs being checked. // This was compiled and checked under JDK Beta3 under Solaris. // these variables match 10 items, 42 bytes in Seattle contour files // This includes an 8-byte length, i.e. it assumes double precision. int fnode; int tnode; int lpoly; int rpoly; double length; int idno; int id; String type; byte source; // a char is hard to read, because readChar reads 16 bits. int elev; byte filler; // INFO pads the record with a null ConArc readArc(DataInputStream s) throws IOException { int nread; byte bytebuff[] = new byte[4]; fnode = s.readInt(); tnode = s.readInt(); lpoly = s.readInt(); rpoly = s.readInt(); length = s.readDouble(); idno = s.readInt(); id = s.readInt(); nread = s.read(bytebuff,0,4); type = new String(bytebuff); source = s.readByte(); nread = s.read(bytebuff,0,4); // INFO I is ASCII numerals elev = 0; // It's simplest to convert to an int through arithmetic for (int i = 0; i < 4; i++){ if(bytebuff[i] != 32) // blank elev = elev * 10 + (bytebuff[i] - 48); } filler = s.readByte(); return this; } void writeArc(DataOutputStream t) throws IOException { byte bytebuff[] = new byte[4]; int tmp; t.writeInt(fnode); t.writeInt(tnode); t.writeInt(lpoly); t.writeInt(rpoly); t.writeDouble(length); t.writeInt(idno); t.writeInt(id); bytebuff = type.getBytes(); t.write(bytebuff,0,4); t.writeByte(source); tmp = elev; for (int i = 3; i >= 0; i--){ if (tmp == 0 && i != 3) bytebuff[i] = 32; else bytebuff[i] = (byte)((tmp % 10) + 48); tmp = (int)(tmp / 10); } t.write(bytebuff,0,4); t.writeByte(filler); } }