Java Code Examples for java.nio.BufferOverflowException#getLocalizedMessage()

The following examples show how to use java.nio.BufferOverflowException#getLocalizedMessage() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: OneShotServerImpl.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
/**
 * Note that this method does the access / request exception processing here rather
 * than passing things up the stack; we may introduce an extended version of this
 * method to take the map array as an output parameter in later releases.
 */
protected InputStream execStreamCmd(String cmdName, String[] cmdArgs, Map<String, Object> inMap, String inString, boolean ignoreCallbacks)
					throws ConnectionException, RequestException, AccessException {
	RpcPacketDispatcher dispatcher = null;
	RpcConnection rpcConnection = null;
	if (cmdName == null) {
		throw new NullPointerError(
				"Null command name passed to execStreamCmd");
	}
	
	if (!this.connected) {
		throw new ConnectionNotConnectedException(
				"Not currently connected to a Perforce server");
	}
	
	try {	
		int cmdCallBackKey = this.nextCmdCallBackKey.incrementAndGet();
		long startTime = System.currentTimeMillis();
		dispatcher = new RpcPacketDispatcher(props, this);
		rpcConnection = new RpcStreamConnection(serverHost, serverPort,
				props, this.serverStats, this.charset, null, this.socketPool,
				this.secure, this.rsh);
		ProtocolCommand protocolSpecs = new ProtocolCommand();
		if (inMap != null && ClientLineEnding.CONVERT_TEXT) {
			ClientLineEnding.convertMap(inMap);
		}
		ExternalEnv env = setupCmd(dispatcher, rpcConnection, protocolSpecs,
										cmdName.toLowerCase(Locale.ENGLISH),cmdArgs, inMap, ignoreCallbacks, cmdCallBackKey, true);
		CommandEnv cmdEnv = new CommandEnv(
										this,
										new RpcCmdSpec(
												cmdName.toLowerCase(Locale.ENGLISH),
												cmdArgs,
												getAuthTicket(),
												inMap,
												inString,
												env),
										rpcConnection,
										protocolSpecs,
										this.serverProtocolMap,
										this.progressCallback,
										cmdCallBackKey,
										writeInPlace(cmdName),
										this.isNonCheckedSyncs());
		cmdEnv.setDontWriteTicket(isDontWriteTicket(cmdName.toLowerCase(Locale.ENGLISH), cmdArgs));
		cmdEnv.setFieldRule(getRpcPacketFieldRule(inMap, CmdSpec.getValidP4JCmdSpec(cmdName)));
		cmdEnv.setStreamCmd(true);

		List<Map<String, Object>> retMapList = dispatcher.dispatch(cmdEnv);
		
		long endTime = System.currentTimeMillis();
		
		if (!ignoreCallbacks && (this.commandCallback != null)) {
			this.processCmdCallbacks(cmdCallBackKey, endTime - startTime, retMapList);
		}

		if ((retMapList != null) && (retMapList.size() != 0)) {
			for (Map<String, Object> map : retMapList) {
				ResultMapParser.handleErrorStr(map);
				ResultMapParser.handleWarningStr(map);
			}
		}

		RpcOutputStream outStream = (RpcOutputStream) cmdEnv.getStateMap().get(
				RpcServer.RPC_TMP_OUTFILE_STREAM_KEY);
		
		if (outStream != null) {
			outStream.close();
			TempFileInputStream inStream
							= new TempFileInputStream(outStream.getFile());
			return inStream;
		}
		
		return null;
		
	} catch (BufferOverflowException exc) {
		Log.error("RPC Buffer overflow: " + exc.getLocalizedMessage());
		Log.exception(exc);
		throw new P4JavaError("RPC Buffer overflow: " + exc.getLocalizedMessage());
	} catch (ConnectionNotConnectedException cnce) {
		this.connected = false;
		this.status = ServerStatus.ERROR;
		throw cnce;
	} catch (IOException ioexc) {
		Log.error("RPC I/O error: " + ioexc.getLocalizedMessage());
		Log.exception(ioexc);
		throw new RequestException(
				"I/O error encountered in stream command: "
				+ ioexc.getLocalizedMessage(), ioexc);
	} finally {
		if (rpcConnection != null) {
			rpcConnection.disconnect(dispatcher);
		}
	}
}
 
Example 2
Source File: OneShotServerImpl.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
/**
 * Note that this method does the access / request exception processing here rather
 * than passing things up the stack; we may introduce an extended version of this
 * method to take the map array as an output parameter in later releases.
 */
protected InputStream execStreamCmd(String cmdName, String[] cmdArgs, Map<String, Object> inMap, String inString, boolean ignoreCallbacks)
					throws ConnectionException, RequestException, AccessException {
	RpcPacketDispatcher dispatcher = null;
	RpcConnection rpcConnection = null;
	if (cmdName == null) {
		throw new NullPointerError(
				"Null command name passed to execStreamCmd");
	}
	
	if (!this.connected) {
		throw new ConnectionNotConnectedException(
				"Not currently connected to a Perforce server");
	}
	
	try {	
		int cmdCallBackKey = this.nextCmdCallBackKey.incrementAndGet();
		long startTime = System.currentTimeMillis();
		dispatcher = new RpcPacketDispatcher(props, this);
		rpcConnection = new RpcStreamConnection(serverHost, serverPort,
				props, this.serverStats, this.p4Charset, null, this.socketPool,
				this.secure, this.rsh);
		ProtocolCommand protocolSpecs = new ProtocolCommand();
		if (inMap != null && ClientLineEnding.CONVERT_TEXT) {
			ClientLineEnding.convertMap(inMap);
		}
		ExternalEnv env = setupCmd(dispatcher, rpcConnection, protocolSpecs,
										cmdName.toLowerCase(Locale.ENGLISH),cmdArgs, inMap, ignoreCallbacks, cmdCallBackKey, true);
		CommandEnv cmdEnv = new CommandEnv(
										this,
										new RpcCmdSpec(
												cmdName.toLowerCase(Locale.ENGLISH),
												cmdArgs,
												getAuthTicket(),
												inMap,
												inString,
												env),
										rpcConnection,
										protocolSpecs,
										this.serverProtocolMap,
										this.progressCallback,
										cmdCallBackKey,
										writeInPlace(cmdName),
										this.isNonCheckedSyncs());
		cmdEnv.setDontWriteTicket(isDontWriteTicket(cmdName.toLowerCase(Locale.ENGLISH), cmdArgs));
		cmdEnv.setFieldRule(getRpcPacketFieldRule(inMap, CmdSpec.getValidP4JCmdSpec(cmdName)));
		cmdEnv.setStreamCmd(true);

		List<Map<String, Object>> retMapList = dispatcher.dispatch(cmdEnv);
		
		long endTime = System.currentTimeMillis();
		
		if (!ignoreCallbacks && (this.commandCallback != null)) {
			this.processCmdCallbacks(cmdCallBackKey, endTime - startTime, retMapList);
		}

		if ((retMapList != null) && (retMapList.size() != 0)) {
			for (Map<String, Object> map : retMapList) {
				// p4ic4idea: use IServerMessage
				IServerMessage msg = ResultMapParser.toServerMessage(map);
				ResultMapParser.handleErrors(msg);
				ResultMapParser.handleWarnings(msg);
			}
		}

		RpcOutputStream outStream = (RpcOutputStream) cmdEnv.getStateMap().get(
				RpcServer.RPC_TMP_OUTFILE_STREAM_KEY);
		
		if (outStream != null) {
			outStream.close();
			TempFileInputStream inStream
							= new TempFileInputStream(outStream.getFile());
			return inStream;
		}
		
		return null;
		
	} catch (BufferOverflowException exc) {
		Log.error("RPC Buffer overflow: " + exc.getLocalizedMessage());
		Log.exception(exc);
		throw new P4JavaError("RPC Buffer overflow: " + exc.getLocalizedMessage());
	} catch (ConnectionNotConnectedException cnce) {
		this.connected = false;
		this.status = ServerStatus.ERROR;
		throw cnce;
	} catch (IOException ioexc) {
		Log.error("RPC I/O error: " + ioexc.getLocalizedMessage());
		Log.exception(ioexc);
		throw new RequestException(
				"I/O error encountered in stream command: "
				+ ioexc.getLocalizedMessage(), ioexc);
	} finally {
		if (rpcConnection != null) {
			rpcConnection.disconnect(dispatcher);
		}
	}
}
 
Example 3
Source File: OneShotServerImpl.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
/**
 * Note that this method does the access / request exception processing here rather
 * than passing things up the stack; we may introduce an extended version of this
 * method to take the map array as an output parameter in later releases.
 */
protected InputStream execStreamCmd(String cmdName, String[] cmdArgs, Map<String, Object> inMap, String inString, boolean ignoreCallbacks)
					throws ConnectionException, RequestException, AccessException {
	RpcPacketDispatcher dispatcher = null;
	RpcConnection rpcConnection = null;
	if (cmdName == null) {
		throw new NullPointerError(
				"Null command name passed to execStreamCmd");
	}
	
	if (!this.connected) {
		throw new ConnectionNotConnectedException(
				"Not currently connected to a Perforce server");
	}
	
	try {	
		int cmdCallBackKey = this.nextCmdCallBackKey.incrementAndGet();
		long startTime = System.currentTimeMillis();
		dispatcher = new RpcPacketDispatcher(props, this);
		rpcConnection = new RpcStreamConnection(serverHost, serverPort,
				props, this.serverStats, this.p4Charset, null, this.socketPool,
				this.secure, this.rsh);
		ProtocolCommand protocolSpecs = new ProtocolCommand();
		if (inMap != null && ClientLineEnding.CONVERT_TEXT) {
			ClientLineEnding.convertMap(inMap);
		}
		ExternalEnv env = setupCmd(dispatcher, rpcConnection, protocolSpecs,
										cmdName.toLowerCase(Locale.ENGLISH),cmdArgs, inMap, ignoreCallbacks, cmdCallBackKey, true);
		CommandEnv cmdEnv = new CommandEnv(
										this,
										new RpcCmdSpec(
												cmdName.toLowerCase(Locale.ENGLISH),
												cmdArgs,
												getAuthTicket(),
												inMap,
												inString,
												env),
										rpcConnection,
										protocolSpecs,
										this.serverProtocolMap,
										this.progressCallback,
										cmdCallBackKey,
										writeInPlace(cmdName),
										this.isNonCheckedSyncs());
		cmdEnv.setDontWriteTicket(isDontWriteTicket(cmdName.toLowerCase(Locale.ENGLISH), cmdArgs));
		cmdEnv.setFieldRule(getRpcPacketFieldRule(inMap, CmdSpec.getValidP4JCmdSpec(cmdName)));
		cmdEnv.setStreamCmd(true);

		List<Map<String, Object>> retMapList = dispatcher.dispatch(cmdEnv);
		
		long endTime = System.currentTimeMillis();
		
		if (!ignoreCallbacks && (this.commandCallback != null)) {
			this.processCmdCallbacks(cmdCallBackKey, endTime - startTime, retMapList);
		}

		if ((retMapList != null) && (retMapList.size() != 0)) {
			for (Map<String, Object> map : retMapList) {
				ResultMapParser.handleErrorStr(map);
				ResultMapParser.handleWarningStr(map);
			}
		}

		RpcOutputStream outStream = (RpcOutputStream) cmdEnv.getStateMap().get(
				RpcServer.RPC_TMP_OUTFILE_STREAM_KEY);
		
		if (outStream != null) {
			outStream.close();
			TempFileInputStream inStream
							= new TempFileInputStream(outStream.getFile());
			return inStream;
		}
		
		return null;
		
	} catch (BufferOverflowException exc) {
		Log.error("RPC Buffer overflow: " + exc.getLocalizedMessage());
		Log.exception(exc);
		throw new P4JavaError("RPC Buffer overflow: " + exc.getLocalizedMessage());
	} catch (ConnectionNotConnectedException cnce) {
		this.connected = false;
		this.status = ServerStatus.ERROR;
		throw cnce;
	} catch (IOException ioexc) {
		Log.error("RPC I/O error: " + ioexc.getLocalizedMessage());
		Log.exception(ioexc);
		throw new RequestException(
				"I/O error encountered in stream command: "
				+ ioexc.getLocalizedMessage(), ioexc);
	} finally {
		if (rpcConnection != null) {
			rpcConnection.disconnect(dispatcher);
		}
	}
}