code: public static MultiLineString createSegments(Geometry geom) throws SQLException {
          if (geom != null) {
              List<LineString> result;
              if (geom.getDimension() > 0) {
                  result = new LinkedList<LineString>();
                  createSegments(geom, result);
                  return GEOMETRY_FACTORY.createMultiLineString(
                          result.toArray(new LineString[0]));
              } else {
                  return GEOMETRY_FACTORY.createMultiLineString(null);
              }
          }
          return null;
      }
docs: Converts a geometry into a set of distinct segments stored in a
  MultiLineString.
  
  @param geom Geometry
  @return A MultiLineString of the geometry's distinct segments
  @throws SQLException