1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
/*************************************************
*
* = PACKAGE
* JACE.Connection
*
* = FILENAME
* Blob.java
*
*@author Prashant Jain
*
*************************************************/
package JACE.Connection;
import java.io.*;
import java.net.*;
import JACE.SOCK_SAP.*;
import JACE.ASX.*;
import JACE.OS.*;
public class Blob
{
public int open (String filename, String hostname , int port)
{
this.filename_ = filename;
this.hostname_ = hostname;
this.port_ = port;
return 0;
}
public MessageBlock read (int length, int offset)
{
// Check if we have a valid length and a valid offset
if (length < 0 || offset < 0)
{
ACE.ERROR ("Blob::read(): Negative length or offset");
return null;
}
// Create a Blob Reader
BlobReader blobReader = new BlobReader (length, offset, this.filename_, this.hostname_, this.port_);
// Receive data
MessageBlock mb = blobReader.receiveData ();
if (blobReader.bytesRead () != length)
return null;
else
return mb;
}
public int write (MessageBlock mb, int length, int offset)
{
// Check if we have a valid length and a valid offset
if (length < 0 || offset < 0)
ACE.ERROR ("Blob::write(): Negative length or offset");
// Create a Blob Writer
BlobWriter blobWriter = new BlobWriter (mb, length, offset, this.filename_);
try
{
// Connect to the server
this.connector_.open (this.hostname_, this.port_);
this.connector_.connect (blobWriter);
}
catch (UnknownHostException e)
{
ACE.ERROR (e);
}
catch (InstantiationException e)
{
ACE.ERROR (e);
}
catch (IllegalAccessException e)
{
ACE.ERROR (e);
}
catch (IOException e)
{
ACE.ERROR (e);
}
return blobWriter.bytesWritten ();
}
public int close ()
{
return 0;
}
String filename_;
String hostname_;
int port_;
Connector connector_ = new Connector ();
}
|