-
Notifications
You must be signed in to change notification settings - Fork 60
Expand file tree
/
Copy pathcStringIO.java
More file actions
68 lines (55 loc) · 1.86 KB
/
Copy pathcStringIO.java
File metadata and controls
68 lines (55 loc) · 1.86 KB
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
/*
* Copyright 1998 Finn Bock.
*
* This program contains material copyrighted by:
* Copyright (c) 1991-1995 by Stichting Mathematisch Centrum, Amsterdam,
* The Netherlands.
*/
// cStringIO with StringBuilder semantics - don't use without using external
// synchronization. Java does provide other alternatives.
package org.python.modules;
import org.python.core.PyArray;
import org.python.core.PyType;
import org.python.modules._io.PyStringIO;
/**
* This module implements a file-like class, StringIO, that reads and
* writes a string buffer (also known as memory files).
* See the description on file objects for operations.
* @author Finn Bock, bckfnn@pipmail.dknet.dk
* @version cStringIO.java,v 1.10 1999/05/20 18:03:20 fb Exp
*/
public class cStringIO {
public static PyType InputType = PyType.fromClass(PyStringIO.class);
public static PyType OutputType = PyType.fromClass(PyStringIO.class);
public static PyStringIO StringIO() {
return new PyStringIO();
}
/**
* Create a StringIO object, initialized by the value.
* @param buffer The initial value.
* @return a new StringIO object.
*/
public static PyStringIO StringIO(String buffer) {
return new PyStringIO(buffer);
}
/**
* Create a StringIO object, initialized by an array's byte stream.
* @param array The initial value, from an array.
* @return a new StringIO object.
*/
public static PyStringIO StringIO(PyArray array) {
return new PyStringIO(array);
}
private static String[] strings = new String[256];
static String getString(char ch) {
if (ch > 255) {
return new String(new char[] { ch });
}
String s = strings[ch];
if (s == null) {
s = new String(new char[] { ch });
strings[ch] = s;
}
return s;
}
}