Java Reference
In-Depth Information
return
return
1
;
}
/* Java's DataStreams etc. are defined to be in network byte order */
java_offset
=
htonl
(
OFFSET
);
iif
(
write
(
fd
,
&
java_offset
,
sizeof
sizeof
java_offset
)
<
0
) {
perror
(
"write"
);
return
return
1
;
}
iif
(
lseek
(
fd
,
OFFSET
,
SEEK_SET
)
<
0
) {
perror
(
"seek"
);
return
return
1
;
}
iif
(
write
(
fd
,
MESSAGE
,
strlen
(
MESSAGE
))
!=
strlen
(
MESSAGE
)) {
perror
(
"write2"
);
return
return
1
;
}
iif
(
close
(
fd
)
<
0
) {
perror
(
"close!?"
);
return
return
1
;
}
return
return
0
;
}
The implementation for object stream serialization is shown here:
public
public class
class
SerialDemoObjectStream
SerialDemoObjectStream
extends
extends
SerialDemoAbstractBase
{
protected
protected static
static final
final
String FILENAME
=
"serial.dat"
;
public
public static
static
void
void
main
(
String
[]
s
)
throws
throws
Exception
{
new
new
SerialDemoObjectStream
().
save
();
// in parent class; calls write
new
new
SerialDemoObjectStream
().
dump
();
// here
}
/** Does the actual serialization */
public
public
void
void
write
(
Object theGraph
)
throws
throws
IOException
{
// Save the data to disk.
ObjectOutputStream os
=
new
new
ObjectOutputStream
(
new
new
BufferedOutputStream
(
new
new
FileOutputStream
(
FILENAME
)));