cdm/src/main/java/ucar/nc2/ft/point/remote/PointStream.java
public static int write(OutputStream out, PointFeatureIterator pointFeatIter, String name, String timeUnitString,
          String altUnits) throws IOException {
    int numWritten = 0;

    while (pointFeatIter.hasNext()) {
      try {
        PointFeature pointFeat = pointFeatIter.next();

        if (numWritten == 0) {
          PointStreamProto.PointFeatureCollection protoPfc =
                  PointStream.encodePointFeatureCollection(name, timeUnitString, altUnits, pointFeat);
          byte[] data = protoPfc.toByteArray();

          PointStream.writeMagic(out, MessageType.PointFeatureCollection);
          NcStream.writeVInt(out, data.length);
          out.write(data);
        }

        PointStreamProto.PointFeature protoPointFeat = PointStream.encodePointFeature(pointFeat);
        byte[] data = protoPointFeat.toByteArray();

        PointStream.writeMagic(out, MessageType.PointFeature);
        NcStream.writeVInt(out, data.length);
        out.write(data);

        ++numWritten;
      } catch (Throwable t) {
        NcStreamProto.Error protoError =
                NcStream.encodeErrorMessage(t.getMessage() != null ? t.getMessage() : t.getClass().getName());
        byte[] data = protoError.toByteArray();

        PointStream.writeMagic(out, PointStream.MessageType.Error);
        NcStream.writeVInt(out, data.length);
        out.write(data);

        throw new IOException(t);
      }
    }

    PointStream.writeMagic(out, PointStream.MessageType.End);

    return numWritten;
  }
public static int write(OutputStream out, PointFeatureIterator pointFeatIter, String name, String timeUnitString,
          String altUnits) throws IOException {
    int numWritten = 0;

    while (pointFeatIter.hasNext()) {
      try {
        PointFeature pointFeat = pointFeatIter.next();

        if (numWritten == 0) {
          PointStreamProto.PointFeatureCollection protoPfc =
                  PointStream.encodePointFeatureCollection(name, timeUnitString, altUnits, pointFeat);
          byte[] data = protoPfc.toByteArray();

          PointStream.writeMagic(out, MessageType.PointFeatureCollection);
          NcStream.writeVInt(out, data.length);
          out.write(data);
        }

        PointStreamProto.PointFeature protoPointFeat = PointStream.encodePointFeature(pointFeat);
        byte[] data = protoPointFeat.toByteArray();

        PointStream.writeMagic(out, MessageType.PointFeature);
        NcStream.writeVInt(out, data.length);
        out.write(data);

        ++numWritten;
      } catch (Throwable t) {
        NcStreamProto.Error protoError =
                NcStream.encodeErrorMessage(t.getMessage() != null ? t.getMessage() : t.getClass().getName());
        byte[] data = protoError.toByteArray();

        PointStream.writeMagic(out, PointStream.MessageType.Error);
        NcStream.writeVInt(out, data.length);
        out.write(data);

        throw new IOException(t);
      }
    }

    PointStream.writeMagic(out, PointStream.MessageType.End);

    return numWritten;
  }
Caller must iter.finish() and out.close().