Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package com.splout.db.common;
 
 /*
  * #%L
  * Splout SQL Server
  * %%
  * Copyright (C) 2012 Datasalt Systems S.L.
  * %%
  * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 * #L%
 */
import  org.apache.thrift.TBase;
import  org.apache.thrift.TException;
import  org.apache.thrift.protocol.TBinaryProtocol;
import  org.apache.thrift.transport.TIOStreamTransport;

A simple class for reading Thrift objects (of a single type) from a file.

Author(s):
Joel Meyer - simplified & modified by us
public class ThriftReader {

File containing the objects.
	protected final File file;

For reading the file.
For reading the binary thrift objects.
	private TBinaryProtocol binaryIn;

Constructor.

Throws:
FileNotFoundException
	public ThriftReader(File filethrows FileNotFoundException {
		this. = file;
		open();
	}

Opens the file for reading. Must be called before read().
	private void open() throws FileNotFoundException {
		 = new TBinaryProtocol(new TIOStreamTransport());
	}

Checks if another objects is available by attempting to read another byte from the stream.
	public boolean hasNext() throws IOException {
		int val = .read();
		return val != -1;
	}

Reads the next object from the file.
	@SuppressWarnings("rawtypes")
	public <T extends TBase> T read(T tthrows IOException {
		try {
			t.read();
catch(TException e) {
			throw new IOException(e);
		}
		return (T) t;
	}

Close the file.
	public ThriftReader close() throws IOException {
		return this;
	}
New to GrepCode? Check out our FAQ X