LaneData ̗p

hLg̖ڎ

LaneData NX

Oni zlbg[Nł肳f[^ oni.net.LaneData ̔hNX ȂĂB ̃NX͒ۃ\bh getBytes() ’ۃNXłA ۂɂ͂hۃNXgƂɂȂB VXeɂ͊{̃f[^^T|[gۃNXpӂĂB

eۃNX͓悤ɗp”\łB ȉ4‚̃^Cṽ\bhT|[gĂB

Ƃ ObjectLaneData ͈ȉ̂悤ɂȂB

public ObjectLaneData(Object data)
public ObjectLaneData(LaneData laneData) throws IOException, ClassNotFoundException
public static Object toObject(LaneData laneData) throws IOException, ClassNotFoundException
public Object toObject()

Ǝ LaneData ɂ

LaneData ͊g”\łAVXe̓[U[RɎ LaneData płB Ǝ LaneData ꍇ́AgetBytes() \bh 邱ƂɂȂBƎ LaneData ͎ۂ̃f[^ێA oCgz getBytes() Ă΂ꂽƂɕϊs悤ɎB

Ƃ΁Aԍ(ID)ƖO(Name) EmployeeLaneData͈ȉ̂悤ɂȂB

import java.io.*;

public class EmployeeLaneData extends LaneData {
    private int id;
    private String name;

    public EmployeeLaneData(int anID, String aName) {
        id = anID;
        name = aName;
    }

    public int getID() { retuen id; }
    public int getName() { return name; }

    public EmployeeLaneData(LaneData laneData) throws IOException {
        ByteArrayInputStream buffer = new ByteArrayInputStream(laneData.getBytes());
        DataInputStream input = new DataInputStream(buffer);
        id = input.readInt();
        name = input.readUTF();
    }

    public byte[] getBytes() throws IOException {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        DataOutputStream output = new DataOutputStream(buffer);
        output.writeInt(id);
        output.writeUTF(name);
        return buffer.toByteArray();
    }
}

ϊ}邽߂ ByteArrayLaneData g

LaneData ̊eۃNX getBytes() \bh ϊsĂB̂߁AJԂLaneDataIuWFNg getBytes() \bhĂԂƌȂB ̂߉x getBytes() \bhĂԂ悤ȏꍇ́AByteArrayLaneData pƂ悢B‚܂ÃR[h:

LaneData data = new StringLaneData("test");
someProcess(data.getBytes());
otherProcess(data.getBytes());

ȉ̂悤ȃR[hɂƂ悢:

LaneData data = new StringLaneData("test");
data = new ByteArrayLaneData(data);
someProcess(data.getBytes());
otherProcess(data.getBytes());


Copyright © 2001-2002 CyberStep, Inc. All Rights Reserved.

Oni \tgEFA