public boolean ready() { try { return current < end || input.ready(); } catch (IOException e) { throw new OIOException("Error in ready", e); } }
private void read(final int iIndex) { try { // JUMP CHARACTERS for (long i = end; i < iIndex - 1; ++i) input.read(); start = iIndex; final int byteRead = input.read(buffer); end = start + byteRead; current = start; } catch (IOException e) { throw new OIOException("Error in read", e); } }
public void clearInput() throws IOException { if (in == null) return; final StringBuilder dirtyBuffer = new StringBuilder(MAX_LENGTH_DEBUG); int i = 0; while (in.available() > 0) { char c = (char) in.read(); ++i; if (dirtyBuffer.length() < MAX_LENGTH_DEBUG) dirtyBuffer.append(c); } updateMetricReceivedBytes(i); final String message = "Received unread response from " + socket.getRemoteSocketAddress() + " probably corrupted data from the network connection. Cleared dirty data in the buffer (" + i + " bytes): [" + dirtyBuffer + (i > dirtyBuffer.length() ? "..." : "") + "]"; OLogManager.instance().error(this, message, null); throw new OIOException(message); }
rootException = new OIOException(iMessage, iPrevious);
/** * ALWAYS ADD THE HEADER SIZE BECAUSE ON THIS TYPE IS ALWAYS NEEDED */ private long checkRegions(final long iOffset, final long iLength) { acquireReadLock(); try { if (iOffset < 0 || iOffset + iLength > size) { throw new OIOException( "You cannot access outside the file size (" + size + " bytes). You have requested portion " + iOffset + "-" + (iOffset + iLength) + " bytes. File: " + this); } return iOffset + HEADER_SIZE; } finally { releaseReadLock(); } }
public OChannelBinary writeBytes(final byte[] iContent, final int iLength) throws IOException { if (debug) OLogManager.instance() .info(this, "%s - Writing bytes (4+%d=%d bytes): %s", socket.getRemoteSocketAddress(), iLength, iLength + 4, Arrays.toString(iContent)); if (iContent == null) { out.writeInt(-1); updateMetricTransmittedBytes(OBinaryProtocol.SIZE_INT); } else { if (iLength > maxChunkSize) { throw OException.wrapException(new OIOException( "Impossible to write a chunk of length:" + iLength + " max allowed chunk length:" + maxChunkSize + " see NETWORK_BINARY_MAX_CONTENT_LENGTH settings "), null); } out.writeInt(iLength); out.write(iContent, 0, iLength); updateMetricTransmittedBytes(OBinaryProtocol.SIZE_INT + iLength); } return this; }
public byte[] readBytes() throws IOException { if (debug) OLogManager.instance() .info(this, "%s - Reading chunk of bytes. Reading chunk length as int (4 bytes)...", socket.getRemoteSocketAddress()); final int len = in.readInt(); if (len > maxChunkSize) { throw OException.wrapException(new OIOException( "Impossible to read a chunk of length:" + len + " max allowed chunk length:" + maxChunkSize + " see NETWORK_BINARY_MAX_CONTENT_LENGTH settings "), null); } updateMetricReceivedBytes(OBinaryProtocol.SIZE_INT + len); if (debug) OLogManager.instance().info(this, "%s - Read chunk length: %d", socket.getRemoteSocketAddress(), len); if (len < 0) return null; if (debug) OLogManager.instance().info(this, "%s - Reading %d bytes...", socket.getRemoteSocketAddress(), len); // REUSE STATIC BUFFER? final byte[] tmp = new byte[len]; in.readFully(tmp); if (debug) OLogManager.instance().info(this, "%s - Read %d bytes: %s", socket.getRemoteSocketAddress(), len, new String(tmp)); return tmp; }
/** * Opens the file. */ /* * (non-Javadoc) * * @see com.orientechnologies.orient.core.storage.fs.OFileAAA#open() */ public void open() { acquireWriteLock(); try { if (!Files.exists(osFile)) { throw new FileNotFoundException("File: " + osFile); } acquireExclusiveAccess(); openChannel(); init(); OLogManager.instance().debug(this, "Checking file integrity of " + osFile.getFileName() + "..."); if (version < CURRENT_VERSION) { setVersion(CURRENT_VERSION); version = CURRENT_VERSION; } initAllocationMode(); } catch (final IOException e) { throw OException.wrapException(new OIOException("Error during file open"), e); } finally { releaseWriteLock(); } }
reopenFile(attempts, ioe); } catch (final IOException e) { throw OException.wrapException(new OIOException("Error during file close"), e);