List of usage examples for java.io EOFException EOFException
public EOFException(String s)
EOFException
with the specified detail message. From source file:org.apache.hadoop.util.IOUtils.java
/** * Similar to readFully(). Skips bytes in a loop. * @param in The InputStream to skip bytes from * @param len number of bytes to skip./* www . j a v a2s . c o m*/ * @throws IOException if it could not skip requested number of bytes * for any reason (including EOF) */ public static void skipFully(InputStream in, long len) throws IOException { long amt = len; while (amt > 0) { long ret = in.skip(amt); if (ret == 0) { // skip may return 0 even if we're not at EOF. Luckily, we can // use the read() method to figure out if we're at the end. int b = in.read(); if (b == -1) { throw new EOFException( "Premature EOF from inputStream after " + "skipping " + (len - amt) + " byte(s)."); } ret = 1; } amt -= ret; } }
From source file:org.apache.hadoop.hive.serde2.teradata.TeradataBinaryDataInputStream.java
/** * Read CHAR(N)./*from w w w .j av a 2 s . c om*/ * The representation of char in Teradata binary format is * the byte number to read is based on the [charLength] * [bytePerChar] <- totalLength, * bytePerChar is decided by the charset: LATAIN charset is 2 bytes per char and UNICODE charset is 3 bytes per char. * the null char will use space to pad. * * @param totalLength the total length * @return the string * @throws IOException the io exception */ public String readChar(int totalLength) throws IOException { byte[] charContent = new byte[totalLength]; int numOfBytesRead = in.read(charContent); if (charContent.length != 0 && numOfBytesRead != totalLength) { throw new EOFException( format("Fail to read the varchar. Expect %d bytes, get %d bytes", totalLength, numOfBytesRead)); } return new String(charContent, "UTF8"); }
From source file:org.apache.hadoop.fs.CopyFilesBase.java
protected static boolean checkFiles(FileSystem fs, String topdir, MyFile[] files, boolean existingOnly) throws IOException { Path root = new Path(topdir); for (int idx = 0; idx < files.length; idx++) { Path fPath = new Path(root, files[idx].getName()); try {/*from w w w.j a va2s . c om*/ byte[] toCompare = new byte[files[idx].getSize()]; Random rb = new Random(files[idx].getSeed()); rb.nextBytes(toCompare); if (!checkContentOfFile(fs, fPath, toCompare)) { return false; } } catch (FileNotFoundException fnfe) { if (!existingOnly) { throw fnfe; } } catch (EOFException eofe) { throw (EOFException) new EOFException("Cannot read file" + fPath); } } return true; }
From source file:com.buaa.cfs.utils.IOUtils.java
/** * Similar to readFully(). Skips bytes in a loop. * * @param in The InputStream to skip bytes from * @param len number of bytes to skip./*from www .j a v a 2 s. c om*/ * * @throws IOException if it could not skip requested number of bytes for any reason (including EOF) */ public static void skipFully(InputStream in, long len) throws IOException { long amt = len; while (amt > 0) { long ret = in.skip(amt); if (ret == 0) { // skip may return 0 even if we're not at EOF. Luckily, we can // use the read() method to figure out if we're at the end. int b = in.read(); if (b == -1) { throw new EOFException( "Premature EOF from inputStream after " + "skipping " + (len - amt) + " byte(s)."); } ret = 1; } amt -= ret; } }
From source file:org.anarres.lzo.LzoInputStream.java
protected int readInt(boolean start_of_frame) throws IOException { int b1 = in.read(); if (b1 == -1) { if (start_of_frame) return -1; else/*from w ww . j ava 2 s . c o m*/ throw new EOFException("EOF before reading 4-byte integer."); } int b2 = in.read(); int b3 = in.read(); int b4 = in.read(); if ((b1 | b2 | b3 | b4) < 0) throw new EOFException("EOF while reading 4-byte integer."); return ((b1 << 24) + (b2 << 16) + (b3 << 8) + b4); }
From source file:org.apache.hadoop.registry.client.binding.JsonSerDeser.java
/** * Load from a Hadoop filesystem/*from w ww .j av a 2 s . c o m*/ * @param fs filesystem * @param path path * @return a loaded CD * @throws IOException IO problems * @throws EOFException if not enough bytes were read in * @throws JsonParseException parse problems * @throws JsonMappingException O/J mapping problems */ public T load(FileSystem fs, Path path) throws IOException, JsonParseException, JsonMappingException { FileStatus status = fs.getFileStatus(path); long len = status.getLen(); byte[] b = new byte[(int) len]; FSDataInputStream dataInputStream = fs.open(path); int count = dataInputStream.read(b); if (count != len) { throw new EOFException(path.toString() + ": read finished prematurely"); } return fromBytes(path.toString(), b); }
From source file:org.apache.hadoop.fs.s3a.S3AInputStream.java
@Override public synchronized void seek(long targetPos) throws IOException { checkNotClosed();//from w w w.j av a2 s .co m // Do not allow negative seek if (targetPos < 0) { throw new EOFException(FSExceptionMessages.NEGATIVE_SEEK + " " + targetPos); } if (this.contentLength <= 0) { return; } // Lazy seek nextReadPos = targetPos; }
From source file:io.horizondb.io.files.TruncatedSeekableFileDataInput.java
/** * Checks that the specified amount of bytes is readable. * /*from w w w .j a v a2s . c om*/ * @param numberOfBytesToRead the number of bytes to read * @throws IOException if an I/O problem occurs or if the bytes are not readable. */ private void checkReadable(int numberOfBytesToRead) throws IOException { long readableBytes = readableBytes(); if (numberOfBytesToRead > readableBytes) { throw new EOFException("Expected to be able to read " + numberOfBytesToRead + " bytes, but only " + readableBytes + " bytes are readable."); } }
From source file:com.oneops.cms.crypto.CmsCryptoDES.java
private KeyParameter getSecretKeyFromFile() throws IOException, GeneralSecurityException { BufferedInputStream keystream = new BufferedInputStream(new FileInputStream(secretKeyFile)); int len = keystream.available(); if (len < MIN_DES_FILE_LENGTH) { keystream.close();/* w w w .j a v a 2 s.c o m*/ throw new EOFException(">>>> Bad DES file length = " + len); } byte[] keyhex = new byte[len]; keystream.read(keyhex, 0, len); keystream.close(); return new KeyParameter(Hex.decode(keyhex)); }
From source file:strat.mining.stratum.proxy.network.StratumConnection.java
/** * Start reading lines from the connection. *///from w ww . java2 s . c o m public void startReading() { readThread = new Thread() { public void run() { if (socket != null && socket.isConnected() && !socket.isClosed()) { LOGGER.debug("Start reading on connection {}.", getConnectionName()); try { BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); String line = reader.readLine(); while (line != null && !Thread.currentThread().isInterrupted()) { onLineRead(line); line = reader.readLine(); } throw new EOFException("Connection closed."); } catch (Exception e) { if (throwDisconnectError) { onDisconnectWithError(e); } } finally { close(); } } } }; readThread.setName(getConnectionName() + "-Thread"); readThread.setDaemon(true); readThread.start(); }