All Downloads are FREE. Search and download functionalities are using the official Maven repository.

opennlp.tools.util.ObjectStream Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreemnets.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package opennlp.tools.util;

import java.io.IOException;
import java.io.ObjectStreamException;

/**
 * Reads Objects from a stream.
 * 

* Design Decision:
* This interface provides a means for iterating over the * objects in a stream, it does not implement {@link java.util.Iterator} or * {@link Iterable} because: *

    *
  • {@link java.util.Iterator#next()} and * {@link java.util.Iterator#hasNext()} are declared as throwing no checked * exceptions. Thus the {@link IOException}s thrown by {@link #read()} would * have to be wrapped in {@link RuntimeException}s, and the compiler would be * unable to force users of this code to catch such exceptions.
  • *
  • Implementing {@link Iterable} would mean either silently calling * {@link #reset()} to guarantee that all items were always seen on each * iteration, or documenting that the Iterable only iterates over the remaining * elements of the ObjectStream. In either case, users not reading the * documentation carefully might run into unexpected behavior.
  • *
* * @see ObjectStreamException */ public interface ObjectStream { /** * Returns the next object. Calling this method repeatedly until it returns * null will return each object from the underlying source exactly once. * * @return the next object or null to signal that the stream is exhausted */ T read() throws IOException; /** * Repositions the stream at the beginning and the previously seen object sequence * will be repeated exactly. This method can be used to re-read * the stream if multiple passes over the objects are required. * * The implementation of this method is optional. */ void reset() throws IOException, UnsupportedOperationException; /** * Closes the ObjectStream and releases all allocated * resources. After close was called its not allowed to call * read or reset. * * @throws IOException */ void close() throws IOException; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy