?? serialutilitiestests.java
字號:
);
ObjectInputStream in = new ObjectInputStream(bais);
l2 = (Line2D) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(l1, l2));
}
/**
* Serialize a <code>Line2D.Double</code> instance and check that it can be
* deserialized correctly.
*/
public void testLine2DDoubleSerialization() {
Line2D l1 = new Line2D.Double(1.0, 2.0, 3.0, 4.0);
Line2D l2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(l1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
l2 = (Line2D) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(l1, l2));
}
/**
* Serialize a <code>Rectangle2D.Float</code> instance, and check that it
* can be deserialized correctly.
*/
public void testRectangle2DFloatSerialization() {
Rectangle2D r1 = new Rectangle2D.Float(1.0f, 2.0f, 3.0f, 4.0f);
Rectangle2D r2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(r1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
r2 = (Rectangle2D) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(r1, r2));
}
/**
* Serialize a <code>Rectangle2D.Double</code> instance and check that it
* can be deserialized correctly.
*/
public void testRectangle2DDoubleSerialization() {
Rectangle2D r1 = new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0);
Rectangle2D r2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(r1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
r2 = (Rectangle2D) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(r1, r2));
}
/**
* Serialize an <code>Arc2D.Float</code> instance and check that it
* can be deserialized correctly.
*/
public void testArc2DFloatSerialization() {
Arc2D a1 = new Arc2D.Float(
1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, Arc2D.PIE
);
Arc2D a2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(a1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
a2 = (Arc2D) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(a1, a2));
}
/**
* Serialize an <code>Arc2D.Double</code> instance and check that it
* can be deserialized correctly.
*/
public void testArc2DDoubleSerialization() {
Arc2D a1 = new Arc2D.Double(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, Arc2D.PIE);
Arc2D a2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(a1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
a2 = (Arc2D) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(a1, a2));
}
/**
* Some checks for the serialization of a GeneralPath instance.
*/
public void testGeneralPathSerialization() {
GeneralPath g1 = new GeneralPath();
g1.moveTo(1.0f, 2.0f);
g1.lineTo(3.0f, 4.0f);
g1.curveTo(5.0f, 6.0f, 7.0f, 8.0f, 9.0f, 10.0f);
g1.quadTo(1.0f, 2.0f, 3.0f, 4.0f);
g1.closePath();
GeneralPath g2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeShape(g1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
g2 = (GeneralPath) SerialUtilities.readShape(in);
in.close();
}
catch (Exception e) {
System.out.println(e.toString());
}
assertTrue(ShapeUtilities.equal(g1, g2));
}
/**
* Tests the serialization of an {@link AttributedString}.
*/
public void testAttributedStringSerialization1() {
AttributedString s1 = new AttributedString("");
AttributedString s2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeAttributedString(s1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
s2 = SerialUtilities.readAttributedString(in);
in.close();
}
catch (Exception e) {
e.printStackTrace();
}
assertTrue(AttributedStringUtilities.equal(s1, s2));
}
/**
* Tests the serialization of an {@link AttributedString}.
*/
public void testAttributedStringSerialization2() {
AttributedString s1 = new AttributedString("ABC");
AttributedString s2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeAttributedString(s1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
s2 = SerialUtilities.readAttributedString(in);
in.close();
}
catch (Exception e) {
e.printStackTrace();
}
assertTrue(AttributedStringUtilities.equal(s1, s2));
}
/**
* Tests the serialization of an {@link AttributedString}.
*/
public void testAttributedStringSerialization3() {
AttributedString s1 = new AttributedString("ABC");
s1.addAttribute(TextAttribute.LANGUAGE, "English");
AttributedString s2 = null;
try {
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(buffer);
SerialUtilities.writeAttributedString(s1, out);
out.close();
ByteArrayInputStream bais = new ByteArrayInputStream(
buffer.toByteArray()
);
ObjectInputStream in = new ObjectInputStream(bais);
s2 = SerialUtilities.readAttributedString(in);
in.close();
}
catch (Exception e) {
e.printStackTrace();
}
assertTrue(AttributedStringUtilities.equal(s1, s2));
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -