Sina.iRoid
شنبه 10 آبان 1393, 09:58 صبح
سلام.
من کد زیر و اصلا متوجه نمیشم.
در مورد متد مارک اینطور خوندم که برای علامت گذاری موقعیت فعلی Stream به کار میره. اما در کد زیر متوجه true و false کردن و گذاشتن مقادیری مثه 32 نمیشم. ممنون میشم اگر یه توضیح کوچیکی در این مورد بدین.
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
public class BufferedInputStreamDemo {
String str = "This is a © copyright symbol "
+ "but this is © not.\n";
byte[] buf = str.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(buf);
BufferedInputStream bufIn = new BufferedInputStream(in);
int c;
boolean marked = false;
//Constructor
public BufferedInputStreamDemo() throws IOException {
while ((c = bufIn.read()) != -1) {
switch (c) {
case '&':
if (!marked) {
bufIn.mark(32);
marked = true;
} else {
marked = false;
}
break;
case ';':
if (marked) {
marked = false;
System.out.print("(c)");
} else {
System.out.print((char) c);
}
break;
case ' ':
if (marked) {
marked = false;
bufIn.reset();
System.out.print("&");
} else {
System.out.print((char) c);
}
break;
default:
if (!marked) {
System.out.print((char) c);
}
break;
}
}
}
}
import java.io.IOException;
public class DriverClass {
public static void main(String[] args) throws IOException {
new BufferedInputStreamDemo();
}
}
ممنون.
من کد زیر و اصلا متوجه نمیشم.
در مورد متد مارک اینطور خوندم که برای علامت گذاری موقعیت فعلی Stream به کار میره. اما در کد زیر متوجه true و false کردن و گذاشتن مقادیری مثه 32 نمیشم. ممنون میشم اگر یه توضیح کوچیکی در این مورد بدین.
import java.io.BufferedInputStream;
import java.io.ByteArrayInputStream;
import java.io.IOException;
public class BufferedInputStreamDemo {
String str = "This is a © copyright symbol "
+ "but this is © not.\n";
byte[] buf = str.getBytes();
ByteArrayInputStream in = new ByteArrayInputStream(buf);
BufferedInputStream bufIn = new BufferedInputStream(in);
int c;
boolean marked = false;
//Constructor
public BufferedInputStreamDemo() throws IOException {
while ((c = bufIn.read()) != -1) {
switch (c) {
case '&':
if (!marked) {
bufIn.mark(32);
marked = true;
} else {
marked = false;
}
break;
case ';':
if (marked) {
marked = false;
System.out.print("(c)");
} else {
System.out.print((char) c);
}
break;
case ' ':
if (marked) {
marked = false;
bufIn.reset();
System.out.print("&");
} else {
System.out.print((char) c);
}
break;
default:
if (!marked) {
System.out.print((char) c);
}
break;
}
}
}
}
import java.io.IOException;
public class DriverClass {
public static void main(String[] args) throws IOException {
new BufferedInputStreamDemo();
}
}
ممنون.