private void writeImplementation(SimpleFeature f) throws IOException { writer.next(); writer.writeFeatureID(f.getID()); for (int i = 0; i < f.getAttributeCount(); i++) { if (f.getAttribute(i) == null) writer.write(i, "<null>"); else writer.write(i, f.getAttribute(i)); } }
public void close() throws IOException { if (writer == null) { throw new IOException("writer already closed"); } // write out remaining contents from reader // if applicable while (reader.hasNext()) { reader.next(); // advance writer.next(); writer.echoLine(reader.line); // echo unchanged } writer.close(); reader.close(); writer = null; reader = null; read.delete(); if (write.exists() && !write.renameTo(read)) { FileChannel out = new FileOutputStream(read).getChannel(); FileChannel in = new FileInputStream(write).getChannel(); try { long len = in.size(); long copied = out.transferFrom(in, 0, in.size()); if (len != copied) { throw new IOException("unable to complete write"); } } finally { in.close(); out.close(); } } read = null; write = null; store = null; }