📄 phsio.java
字号:
package sms.PHS;
/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.io.*;
import java.net.Socket;
// Referenced classes of package net.smsfan.smg.api.phs20:
// CSemaphore, PHSException, PHSClient
public class PHSIO
extends CSemaphore {
private PHSClient client;
private boolean disconnected;
private InputStream is;
private OutputStream os;
private Socket m_socket;
public PHSIO(Socket socket, PHSClient client) throws IOException,
PHSException {
super("PHSIO");
disconnected = false;
this.client = client;
m_socket = null;
is = null;
os = null;
if (socket == null) {
throw new PHSException(
"null client socket !===================PHSIS.java 36");
}
m_socket = socket;
is = socket.getInputStream();
if (is == null) {
throw new PHSException(
"null inputstream !===================PHSIS.java 41");
}
os = socket.getOutputStream();
if (os == null) {
throw new PHSException(
"null outputstream !===================PHSIS.java 45");
}
else {
return;
}
}
public void close() throws Exception {
disconnected = true;
use();
if (m_socket == null) {
finished();
return;
}
Socket socket1;
socket1 = m_socket;
m_socket = null;
finished();
//break MISSING_BLOCK_LABEL_58;
//Exception e;
//e;
socket1 = m_socket;
m_socket = null;
finished();
if (is != null) {
is.close();
}
is = null;
//break MISSING_BLOCK_LABEL_85;
//Exception e2;
//e2;
if (os != null) {
os.close();
}
os = null;
//break MISSING_BLOCK_LABEL_112;
//e2;
try {
if (socket1 != null) {
socket1.close();
socket1 = null;
return;
}
}
catch (Exception e4) {
socket1 = null;
}
fireSocketDisconnect();
return;
}
protected void finalize() {
try {
close();
}
catch (Exception e) {
}
}
private void fireSocketDisconnect() {
disconnected = true;
if (client != null) {
client.fireDisconnected();
}
}
public boolean isDisconnected() {
return disconnected;
}
public byte[] read(int i) throws IOException, PHSException {
if (disconnected) {
throw new PHSException(
"Sokcet is disconnected!=================>PHSIO.java 119");
}
if (is == null) {
disconnected = true;
fireSocketDisconnect();
throw new PHSException("read : null is !");
}
if (i <= 0) {
throw new PHSException("read : invalid length !");
}
byte abyte0[] = new byte[i];
int j = 0;
do {
int k = is.read(abyte0, j, i - j);
//System.out.println("============PHSPacket.java 137======is.read~NO. is " +
// k);
if (k == -1) {
throw new PHSException("read : unexpected end !");
}
j += k;
}
while (j < i);
return abyte0;
}
public byte read() throws IOException, PHSException {
if (disconnected) {
throw new PHSException("Sokcet is disconnected!");
}
if (is == null) {
disconnected = true;
fireSocketDisconnect();
throw new PHSException("read : null is !");
}
int i = is.read();
if (i == -1) {
throw new PHSException("read : unexpected end !");
}
else {
return (byte) i;
}
}
public void write(byte abyte0[]) throws IOException, PHSException {
if (disconnected) {
throw new PHSException("Sokcet is disconnected!");
}
if (os == null) {
disconnected = true;
fireSocketDisconnect();
throw new PHSException("write : null os !");
}
if (abyte0 == null || abyte0.length <= 0) {
throw new PHSException("write : null os !");
}
try {
use();
os.write(abyte0);
}
catch (InterruptedException ex) {
finished();
}
catch (IOException ex) {
disconnected = true;
fireSocketDisconnect();
throw new IOException("ISMG Connection closed (remotely)");
}
finished();
return;
}
public void write(byte byte0) throws IOException, PHSException {
if (disconnected) {
throw new PHSException("Sokcet is disconnected!");
}
if (os == null) {
disconnected = true;
fireSocketDisconnect();
throw new PHSException("write : null os !");
}
try {
use();
os.write(byte0);
}
catch (InterruptedException ex) {
}
catch (Exception ex) {
disconnected = true;
fireSocketDisconnect();
throw new IOException("ISMG Connection closed (remotely)");
}
finished();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -