package caida.otter;
import java.awt.*;
import java.io.*;
import java.net.*;
import java.util.Date;
/*****************************************************************************
* File: IOHandler.java Name: IOHandler
* Goal: This should handle the IO for otter. Including loading/saving
* locally (only in stand alone) and remotely (both). In two
* different formats.
*
* Modified:Jaeyeon Jung (2/13/98)
* To load lat/long/city and stores them at DisplayObject object
*
* Animation Stuff
* Should be able to down load multi files and compress then into a
* single list. Where each node and link has array of the values
* for each file.
* The first file is the base all other files are mapped on to it.
*
* The possible format for each line. The char should start each
* line.
*
t number
# (total number of nodes)
# Must be at the beginning of the file.
# number - the number of nodes that will be in the file (int)
T number
# (total number of links)
# Must be at the beginning of the file.# number - the number of links that will used (int)
n node_index x y name
N node_index lat long name? node_index name
# (node)
# node_index - unique node identifier (int)
# site_index - identifier node's site (int)
# x - the x location on map (positive int)
# y - the y location on map (positive int)
# lat - latitude (float)
# long - longitude (float)
# name - name of the node (string no spaces)
g group_index key num_enters description
# (group_gory)
# group_index - unique ValuesGroup identifier (int)
# num_enters - number of entries (int)
# description - description of ValuesGroup (string up to \\n)
#
# key - This is a single character which signals the type
# of data that this group will contain (char)
# d - group contains floats
# s - group contains strings
f group_index string'string2'string3'....
# (fields of each ValuesGroup)
# group_index - identifier for the ValuesGroup which has
# these fields (int)
# string1 - field header for the sub Menu
v node_index group_index value1'value2'value3 ...
V link_index group_index value1'value2'value3 ...
# (values for the ValuesGroup)
# node_index - identifier for the node (int)
# link_index - identifier for the link (int)
# group_index - identifier for the ValuesGroup which holds
# these values (int)
# value1 - values for each column (float)
l linkidx n_idx1 n_idx2
L linkidx n_idx1 n_idx2
# (link)
# l - unidirectional";
# L - bidirectional";
# linkidx - the index of this link into an array
# nidx1 - the index of the node that is the client
# nidx2 - the index of the node that is the server
p pathidx num_nodes n_idx1 n_idx2 n_idx3 ...
P pathidx num_nodes n_idx1 n_idx2 n_idx3 ...
# (path)
# p - unidirectional
# P - bidirectional
# pathidx - the index of this path
# num_nodes - the number of nodes in the paths
# n_idx* - the index of the nodes on this path
******************************************************************************
******************************************************************************
By accessing this software, IOHANDLER, you are duly informed of and
agree to be bound by the conditions described below in this notice:
This software product, IOHANDLER, is developed by Bradley Huffaker, and
copyrighted(C) 1998 by the University of California, San Diego (UCSD),
with all rights reserved. UCSD administers the NSF grant to CAIDA,
number NCR-9711092, under which this code was developed.
There is no charge for IOHANDLER software. You can redistribute it and/or
modify it under the terms of the GNU General Public License, v. 2 dated
June 1991 which is incorporated by reference herein. IOHANDLER is
distributed WITHOUT ANY WARRANTY, IMPLIED OR EXPRESS, OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE or that the use of
it will not infringe on any third party's intellectual property
rights.
You should have received a copy of the GNU GPL along with the IOHANDLER
program. Copies can also be obtained from
http://www.gnu.org/copyleft/gpl.html or by writing to
University of California, San Diego
SDSC/CAIDA
9500 Gilman Dr., MS-0505
La Jolla, CA 92093 - 0505 USA
Or contact INFO@CAIDA.ORG
*****************************************************************************/
public class IOHandler extends Thread
{
// The type of formats
final char TOTAL_NODES = 't';
final char TOTAL_LINKS = 'T';
final char FIELD = 'f';
final char SIZE = 's';
final char NODE_KNOWN = 'n';
final char NODE_GEO = 'N';
final char NODE_UNKNOWN = '?';
final char NODE_ROOT = 'r';
final char LINK_ONE = 'l';
final char LINK_TWO = 'L';
final char PATH_ONE = 'p';
final char PATH_TWO = 'P';
final char DATE = 'd';
final char REQUEST_NODE = 'r';
final char REQUEST_LINK = 'R';
final char GROUP = 'g';
final char GROUP_DOUBLE = 'd';
final char GROUP_STRING = 's';
final char FIELDS = 'f';
final char VALUE_NODE = 'v';
final char VALUE_LINK = 'V';
final char VALUE_PATH = 'u';
// Holds the two kinds of formats
// doubleing : the is not x,y for the nodes
// fixed : the nodes have a fixed x,y
// static final public int FLOATING = 0;
//protected int format = FLOATING;
// The location of where to store the file
// Local : On the local file system
// remote: On so file system across the web
// will need to either talk to ftp or have a cgi script
// for saving remotely
static final public int LOCAL = 0;
static final public int REMOTE = 1;
protected int type = LOCAL;
// The file loaded has any formating on the nodes?
// NONE : There is no default way to arrage
// FIXED: Each node has a fixed x/y location
// GEO : Some Nodes have a geo graphical potition
static final public int NONE = 0;
static final public int GEO = 1;
static final public int FIXED = 2;
protected int file_format = NONE;
//jjung Map image
Image image;
// These are the default sizes
int node_size = 5;
int link_size = 1;
// The nodes,links, and the main list
Node[] nodes;
int num_nodes = 0;
Link[] links;
int num_links= 0;
Path[] paths = new Path[100];
int num_paths= 0;
DList list = new DList();
// The date of file if given.
Date[] dates;
// The ValuesGroup
ValuesGroup[] groups = new ValuesGroup[20];
int[] group_map = new int[20];
int num_groups = 0;
// The parent for whom the files are loaded
IOInterface parent;
// The filename of the file to load
String filename;
String directory;
String address;
int linenum;
// Checks to see if it is still loading
boolean loading = false;
boolean saving = false;
// Used to select from the list of possible local files
//FileDailog dialogbox = new FileDialog(this, "Select File");
// Max number of useful tokens in any given line
protected final int MAX_NUM_TOKENS= 2;
// Used to initial the node location
int start_x = 10;
int start_y = 10;
// Used to tell one file from another
//----------------------- Animation Stuff -------------------
boolean mutli_file_mode;
// The current file loading
int fileIndex = 0;
// The list of urls to load (Applet)
String[] urls;
// The list of of directories and files (StandAlone)
String[] dirs;
String[] files;
// The index mapping from one file to the next
int[] node_map;
int[] link_map;
// The num_files that need to be loaded
int num_files;
public IOHandler(IOInterface parent_input)
{
super("IOHandlerThread");
parent = parent_input;
file_format = NONE;
}
public void setStart(int x, int y)
{
start_x = x;
start_y = y;
}
// Sets up all the needed state varialbes
public void setUpLoad()
{
fileIndex = 0;
num_nodes = 0;
num_links = 0;
}
public void Load(String address_input)
{
//stop();
type = REMOTE;
if (address_input == null)
parent.FinishedLoading(list,groups, file_format,dates);
urls = new String[1];
dates = new Date[1];
urls[0] = address_input;
start();
}
public void Load(String filename_input,String directory_input)
{
fileIndex = 0;
num_nodes = 0;
num_links = 0;
//Stop();
type = LOCAL;
files = new String[1];
dates = new Date[1];
files[0] = filename_input;
dirs = new String[1];
dirs[0] = directory_input;
loading = true;
start();
}
// Animatiom: requires the loading of multiple files
public void Load(String[] urls_input)
{
type = REMOTE;
urls = urls_input;
dates = new Date[urls_input.length];
if (urls == null || urls.length < 1)
parent.FinishedLoading(list,groups,file_format,dates);
num_files = urls.length;
start();
}
public void Load(String[] files_input, String[] dirs_input)
{
type = LOCAL;
dirs = dirs_input;
if (dirs_input == null || files_input == null
|| dirs_input.length < 1
|| dirs_input.length < files_input.length)
parent.FinishedLoading(list,groups,file_format,dates);
dirs = dirs_input;
files = files_input;
dates = new Date[files.length];
start();
}
public void Stop()
{
if (loading)
{
loading = false;
parent.FinishedLoading(list,groups,file_format,dates);
}
else if (saving)
{
saving = false;
parent.FinishedSaving();
}
super.stop();
}
public void run()
{
fileIndex = 0;
num_nodes = 0;
num_links = 0;
loading = true;
if (type == LOCAL)
num_files= files.length;
else
num_files = urls.length;
while (fileIndex < num_files)
{
// Reseting mapping for a new file
node_map = null;
link_map = null;
if (type == LOCAL)
{
filename = files[fileIndex];
directory = dirs[fileIndex];
}
else
address = urls[fileIndex];
try {
linenum = 1;
if (loading)
StartLoading();
else if (saving)
StartSaving();
} catch (IOException e1) {
Error("IOHandler.run()",e1.toString());
Stop();
}
fileIndex++;
if (type == LOCAL)
parent.printMessage("Loaded File:"
+filename);
else
parent.printMessage("Loaded URL:"
+address);
}
loading = false;
parent.FinishedLoading(list,groups,file_format,dates);
}
public void StartLoading() throws IOException
{
// The buffer that holds the tokens string
char[] buffer = new char[256];
// control flag that ends the loop
boolean working = true;
// the curent length of the string in buffer
int current_length = 0;
// The number of byte read into byte_buffer
int length;
byte[] byte_buffer = new byte[256];
// the input Stream
InputStream is = getInputStream();
// A comment charater has been reached and the rest of the
// the line should be ignored.
boolean is_comment = false;
if (is == null)
{
Error("IOHandler.StartLoading()","InputStream is null");
Stop();
}
do
{
length = is.read(byte_buffer);
if (length < 0)
{
length = 0;
byte_buffer[length++] = (byte)'\n';
working = false;
}
for (int offset=0; offset < length; offset++)
{
if (current_length == buffer.length)
{
char[] temp = new char[(int)(buffer.length*1.1)];
for (int index=0; index < buffer.length; index++)
temp[index] = buffer[index];
buffer = temp;
}
buffer[current_length] = (char) byte_buffer[offset];
if (buffer[current_length] == '\n')
{
ParseString(current_length,buffer);
current_length= 0;
linenum++;
is_comment = false;
}
else if (buffer[current_length] == '#')
is_comment = true;
else if (!is_comment)
current_length++;
}
} while (working);
if (links != null)
{
for (int index=0; index < links.length;index++)
if (links[index] != null)
list.enqueue(links[index]);
}
if (paths != null)
{
for(int index=0; index < paths.length;index++)
if (paths[index] != null)
list.enqueue(paths[index]);
}
if (nodes != null)
{
for (int index=0; index < nodes.length;index++)
if (nodes[index] != null)
{
nodes[index].finished();
list.enqueue(nodes[index]);
}
}
}
// The tricky part of the following is mapping nodes/links with
// diffrent indexs across files to the same node/link. So here is how it
// will work.
// Assume that the number of nodes that are in the first file
// are the number it will use. So set the number of nodes equal to it.
// Then assume map any new nodes you find to the index of that next node
// when you run out of nodes grow the array. All mapping from the
// file index to the local index will be handled by mapping.
// Where the location in the int array is the mapping of the node.
public void ParseString(int length, char[] buffer)
{
// checks for empty strings
if (length <= 0)
return;
int node_index1;
int nodex_index2;
// Skip the first char it should be format
int index = 2;
char format = buffer[0];
while (index < length && buffer[index] >= '0'
&& buffer[index] <= '9')
index++;
if (index == 2)
{
Error("IOHandler.ParseString()", "node_index1 not found");
return;
}
node_index1 = getInt(buffer,2,index);
if (format == TOTAL_NODES)
{
if (node_map != null)
{
Error("IOHandler.ParseString()"
, "A second nodes total was found");
return;
}
if (nodes == null)
{
nodes = new Node[node_index1];
num_nodes = node_index1;
}
// Grows the node array if it will not be
// large enough even if all the nodes are repeats
else if (nodes.length < node_index1)
{
Node[] temp = new Node[node_index1];
for(int i=0;i < num_nodes;i++)
temp[i] = nodes[i];
nodes = temp;
}
node_map = new int[node_index1];
for(int y=0; y< node_index1; y++)
node_map[y] = -1;
list.clear();
return;
}
else if (format == TOTAL_LINKS)
{
if (link_map != null)
{
Error("IOHandler.ParseString()"
, "A second links total was found");
return;
}
if (links == null)
{
links = new Link[node_index1];
num_links= node_index1;
}
// Grows the node array if it will not be
// large enough even if all the nodes are repeats
else if (links.length < node_index1)
{
Link[] temp = new Link[node_index1];
for(int i=0;i < num_links;i++)
temp[i] = links[i];
links = temp;
}
link_map = new int[node_index1];
for(int x=0; x< node_index1; x++)
link_map[x] = -1;
return;
}
index++;
if (format == SIZE)
{
node_size = node_index1;
link_size = node_index1;
}
else if (format == NODE_KNOWN || format == NODE_GEO
|| format == NODE_UNKNOWN)
{
if (nodes==null)
{
Error("IOHandler.ParseString","Attempt"+
" access nodes with out a 't ##' line.");
return;
}
if (node_index1 >= node_map.length)
{
Error("IOHandler.PraseString()"
,"Node index '" + node_index1 +"'"
+ " is outside of the range 0 - "+
(nodes.length-1));
return;
}
if (node_map[node_index1] >= 0)
{
Error("IOHandler.PraseString()",
"That node is already is use for this file.");
return;
}
double lat = 0;
double lon = 0;
if (format == NODE_KNOWN)
{
int sign = 1;
if (buffer[index] == '-')
{
index++;
sign = -1;
}
int start = index;
while (index < length && buffer[index] >= '0'
&& buffer[index] <= '9')
index++;
if ( index == start)
{
Error("IOHandler.parse"
,"x is not a integer");
format = NODE_UNKNOWN;
}
else
{
start_x = sign*getInt(buffer,start,index);
index++;
sign = 1;
if (buffer[index] == '-')
{
index++;
sign = -1;
}
start = index;
while (index < length && buffer[index] >= '0'
&& buffer[index] <= '9')
index++;
if ( index == start)
{
Error("IOHandler.parse"
,"y is not a integer");
format = NODE_UNKNOWN;
}
else
{
start_y = sign*getInt(buffer,start,index);
index++;
file_format = FIXED;
}
}
}
else if (format == NODE_GEO)
{
int sign = 1;
if (buffer[index] == '-')
{
sign = -1;
index++;
}
int start = index;
while (index < length
&& ((buffer[index] <= '9'
&& buffer[index] >= '0')
|| buffer[index] == '.'))
index++;
lat = sign*getDouble(buffer,start,index);
sign = 1;
if (buffer[++index] == '-')
{
sign = -1;
index++;
}
start = index;
while (index < length
&& ((buffer[index] <= '9'
&& buffer[index] >= '0')
|| buffer[index] == '.'))
index++;
lon = sign*getDouble(buffer,start,index);
index++;
file_format = GEO;
}
// Here it checks to see if an ip address
// is given
long ip = 0;
boolean ip_set = false;
int start_ip = index;
while (start_ip < length && buffer[start_ip] != '(')
start_ip++;
if (start_ip < length)
{
int end_ip = ++start_ip;
long scalar = 256*256*256;
while (end_ip < length
&& buffer[end_ip] != ')'
&& buffer[end_ip] != ' '
&& ((buffer[end_ip] >= '0'
&& buffer[end_ip] <= '9')
|| buffer[end_ip] == '.'))
{
if (buffer[end_ip] == '.')
{
ip += scalar*getInt(buffer,
start_ip,end_ip);
start_ip = ++end_ip;
scalar/=256;
}
end_ip++;
}
if (scalar == 1)
ip_set = true;
}
/*********************************
String name = new String(buffer,start,index-start);
//index++;
boolean is_root = false;
// This captures any special sysmbols
while (index < length)
{
switch (buffer[index])
{
case NODE_ROOT:
is_root = true;
}
index++;
}
*********************************/
boolean is_root = false;
if (buffer[length-1] == 'r' && buffer[length-2] == ' ')
{
is_root= true;
length -= 2;
}
String name = new String(buffer,index,length-index);
int map = 0;
Node node = null;
boolean notFound = true;
if (fileIndex > 0)
while (map < nodes.length && notFound)
{
node = nodes[map];
if (node != null
&& node.name.equals(name))
notFound = false;
else
map++;
}
if (notFound)
{
node = new Node(name,start_x,start_y,
fileIndex,num_files);
node.setDefaultSize(node_size);
if (format == NODE_GEO)
node.setGeo(lat,lon,"unknown");
if (nodes[node_index1] == null)
{
nodes[node_index1] = node;
map = node_index1;
}
else
{
if (num_nodes == nodes.length)
{
Node[] temp = new Node[(int)(
nodes.length*1.1)];
for(int x=0;x < nodes.length;x++)
temp[x] = nodes[x];
nodes = temp;
}
nodes[num_nodes] = node;
map = num_nodes;
num_nodes++;
}
}
else
node.setExists(fileIndex);
node_map[node_index1] = map;
if (is_root)
node.setRoot(true);
if (ip_set)
node.setIP(ip);
}
else if (format == LINK_ONE || format == LINK_TWO)
{
if (links == null)
{
Error("IOHandler.ParseString()",
"Attempt to create link before 'T #'");
return;
}
int start = index;
while (index < length && buffer[index] >= '0'
&& buffer[index] <= '9')
index++;
int link_index = node_index1;
node_index1 = getInt(buffer,start,index);
if (link_index >= links.length)
{
Error("IOHandler.PraseString()"
,"Link index '" + link_index+"'"
+ " is greater then size "+
links.length);
return;
}
start = ++index;
while (index < length && buffer[index] >= '0'
&& buffer[index] <= '9')
index++;
if (index == start)
{
Error("IOHandler.ParseString()"
, "There is no second node index");
return;
}
nodex_index2 = getInt(buffer,start,index);
if (node_index1 >= node_map.length)
{
Error("IOHandler.ParseString()"
,"Node index '" + node_index1 +"'"
+ " is greater then size "+
node_map.length);
return;
}
else if (node_map[node_index1] < 0)
{
Error("IOHandler.ParseString()"
,"Undefined node:"
+ node_index1);
return;
}
else if (nodex_index2 >= node_map.length)
{
Error("IOHandler.ParseString()"
,"Node index '" + nodex_index2 +"'"
+ " is greater then size "+
node_map.length);
return;
}
else if (node_map[nodex_index2] < 0)
{
Error("IOHandler.ParseString()"
,"Undefined node:"
+ nodex_index2);
return;
}
Node from = nodes[node_map[node_index1]];
Node to = nodes[node_map[nodex_index2]];
int type = DisplayObject.DIR_ONE;
if (format == LINK_TWO)
type = DisplayObject.DIR_TWO;
Link link = null;
int map = 0;
boolean notFound = true;
if (fileIndex > 0)
while(map < links.length && notFound)
{
link = links[map];
if (link != null &&
link.equals(from,to))
notFound = false;
else
map++;
}
if (notFound)
{
link = new Link(from,to,type,fileIndex
,num_files);
link.setDefaultSize(link_size);
if (links[link_index] == null)
{
links[link_index] = link;
map = link_index;
}
else
{
if (links.length == num_links)
{
int new_length = (int)(num_links*1.1);
if (new_length == num_links)
new_length = 10;
Link[] temp = new Link[new_length];
for(int x=0;x < links.length;x++)
temp[x] = links[x];
links= temp;
}
links[num_links] = link;
map = num_links;
num_links++;
}
}
else
link.setExists(fileIndex);
link_map[link_index] = map;
}
else if (format == PATH_ONE || format == PATH_TWO)
{
if (paths.length <= node_index1)
{
Path[] temp = paths;
paths = new Path[(int)(node_index1*1.5)];
for(int i=temp.length-1;i>=0;i--)
paths[i] = temp[i];
}
else if (paths[node_index1] != null)
{
Error("IOHandler.ParseString()",
"Path index '"+node_index1
+"' is assigned twice");
return;
}
int start = index;
while (index < length && buffer[index] >= '0'
&& buffer[index] <= '9')
index++;
int num_points = getInt(buffer,start,index);
Node[] points = new Node[num_points];
for (int i=0;i < num_points;i++)
{
start = ++index;
while (index < length && buffer[index] >= '0'
&& buffer[index] <= '9')
index++;
if (start == index)
{
Error("IOHandler.ParseString()"
,"Path expected " + num_points
+" nodes and found "+i);
return;
}
int node_index = getInt(buffer,start,index);
if (node_map == null || nodes == null
|| node_index > node_map.length
|| nodes[node_map[node_index]] == null)
{
Error("IOHandler.ParseString()"
,"Attempt to access none exists node "
+node_index);
return;
}
points[i] = nodes[node_map[node_index]];
}
int direction = DisplayObject.DIR_ONE;
if (format == PATH_TWO)
direction = DisplayObject.DIR_TWO;
paths[node_index1] = new Path(direction,num_points
,points);
paths[node_index1].setDefaultSize(link_size);
}
else if (format == DATE)
{
int start = index;
while (index < length && buffer[index] >= '0'
&& buffer[index] <= '9')
index++;
int month = getInt(buffer,start,index);
start = ++index;
while (index < length && buffer[index] >= '0'
&& buffer[index] <= '9')
index++;
int day = getInt(buffer,start,index);
if (dates[fileIndex] != null)
{
Error("IOHandler.ParseString()",
"Secound date found.");
return;
}
dates[fileIndex] = new Date(node_index1-1900,month,day);
}
else if (format == GROUP)
{
if (length-index < 5)
{
Error("IOHandler.ParseString()",
"Group field is not long enough");
return;
}
int type = 0;
if (GROUP_DOUBLE == buffer[index])
type = ValuesGroup.DOUBLE;
else type = ValuesGroup.STRING;
index+=2;
int start = index;
while (index < length && buffer[index] >= '0'
&& buffer[index] <= '9')
index++;
int num_fields = getInt(buffer,start,index);
index++;
String title = new String(buffer,index
,length-index);
if (node_index1 < group_map.length)
{
int[] temp =
new int [(int)(groups.length*1.5)];
for (int i=0; i < group_map.length;i++)
temp[i] = group_map[i];
group_map = temp;
}
int map = 0;
boolean notFound = true;
while (map < num_groups && notFound)
{
ValuesGroup group = groups[map];
if (group != null
&& group.getTitle().equals(title)
&& group.getNumFields() == num_fields)
notFound = false;
else
map++;
}
if (map == num_groups)
{
if (num_groups == groups.length)
{
ValuesGroup[] temp = new ValuesGroup
[(int)(groups.length*1.5)];
for (int i=0; i < groups.length;i++)
temp[i] = groups[i];
groups = temp;
}
groups[map] = new ValuesGroup(title,type,
num_fields);
num_groups++;
}
group_map[node_index1] = map;
}
else if (format == FIELDS)
{
if (node_index1 >= group_map.length
|| groups[group_map[node_index1]] == null)
{
Error("IOHandler.ParseString()",
"Attempt to access a non exists group:"
+ node_index1);
return;
}
ValuesGroup group = groups[group_map[node_index1]];
String[] fields = new String[group.getNumFields()];
int field_index = 0;
int start = index;
while (fields.length > field_index && index < length)
{
while (index < length && buffer[index] != '\'')
index++;
if (start != index)
{
fields[field_index] =
new String(buffer,start,
index-start);
start = ++index;
field_index++;
}
}
String[] current_fields = group.getFields();
if (current_fields != null)
{
int shortest = current_fields.length;
if (shortest < fields.length)
shortest = fields.length;
int i = 0;
boolean match = true;
while (i < shortest && match)
{
if (!current_fields[i].equals(
fields[i]))
match = false;
else
i++;
}
if (!match)
{
Error("IOHandler.Parse()",
"Groups do not match");
group.setNumFields(i);
return;
}
}
else
group.setFields(fields);
}
else if (format == VALUE_NODE || format == VALUE_LINK
|| format == VALUE_PATH)
{
DisplayObject object = null;
if (VALUE_NODE == format)
{
if (node_map == null
|| node_index1 >= node_map.length
|| node_map[node_index1] < 0
|| nodes[node_map[node_index1]] == null)
{
Error("IOHandler.ParseString()",
"Attempt to access a non exists node:"
+ node_index1);
return;
}
object = nodes[node_map[node_index1]];
}
else if (VALUE_PATH == format)
{
if (node_index1 >= paths.length
|| paths[node_index1] == null)
{
Error("IOHandler.ParseString()",
"Attempt to access a non exist path:"
+ node_index1);
return;
}
object = paths[node_index1];
}
else
{
if (node_index1 >= link_map.length
|| link_map[node_index1] < 0
|| links[link_map[node_index1]] == null)
{
Error("IOHandler.ParseString()",
"Attempt to access a non exist link:"
+ node_index1);
return;
}
object = links[link_map[node_index1]];
}
int start = index;
while (index < length && buffer[index] >= '0'
&& buffer[index] <= '9')
index++;
int group_index = getInt(buffer,start,index);
if (group_index >= group_map.length
|| groups[group_map[group_index]] == null)
{
Error("IOHandler.ParseString()",
"Attempt to access a non exists group:"
+ group_index);
return;
}
ValuesGroup group = groups[group_map[group_index]];
String[] strings = new String[group.getNumFields()];
int strings_index =0;
start = ++index;
while (strings_index < strings.length
&& index < length)
{
while (index < length && buffer[index] != '\'')
index++;
String answer;
if (index != start)
{
answer = new String(buffer,start,index-
start);
} else
{
answer = " ";
}
strings[strings_index] = answer;
strings_index++;
index++;
start = index;
}
if ((start>0) && (strings_index < strings.length)
&& (buffer[start-1]=='\'')){
strings[strings_index++]=" ";
}
if (strings_index != strings.length)
{
Error("IOHandler.Parse",
"Found " + strings_index +
" values wanted "+ strings.length);
return;
}
if (group.getType() == ValuesGroup.DOUBLE)
{
try {
double[] doubles = new double[strings.length];
for (int i=0; i < strings.length;i++)
{
System.err.println("string:"+strings[i]);
doubles[i] = ( new Float(strings[i])).
doubleValue();
}
object.addValues(group,doubles);
} catch (NumberFormatException e) {
Error("IOHandler.Parse",
"Values not double" + e.toString());
}
}
else
object.addValues(group,strings);
}
//jjung
else if (format == GEO)
{
int start = index;
while (index < length && (buffer[index] >= '0'
&& buffer[index] <= '9' || buffer[index] == '.'
|| buffer[index] == '-'))
index++;
if (start == index)
{
//not found
return;
}
String temp = new String(buffer,start,index-start);
double lat = GetDouble(temp,"Latitude");
start = ++index;
while (index < length && (buffer[index] >= '0'
&& buffer[index] <= '9' || buffer[index] == '.'
|| buffer[index] == '-'))
index++;
if (start == index)
{
Error("IOHandler.ParseString()",
"Error parsing longtude request number");
return;
}
temp = new String(buffer,start,index-start);
double lon = GetDouble(temp,"Longitude");
start = ++index;
while (index < length && buffer[index] != '\n')
index++;
if (start == index)
{
Error("IOHandler.ParseString()",
"Error parseing longtude request number");
return;
}
String city = new String(buffer,start,index-start);
DisplayObject object = null;
if (node_index1 < node_map.length
&& node_map[node_index1] >= 0)
object = nodes[node_map[node_index1]];
if (object == null)
{
Error("IOHandler.ParseString()",
"Undefined "+type+" ["+node_index1+"]");
return;
}
object.setGeo(lat,lon,city);
file_format = GEO;
}
//jjung
else
Error("IOHandler.ParseString()","Unknow formate '"
+ format +"'");
}
public InputStream getInputStream()
{
InputStream is = null;
if (type == LOCAL)
{
/**************************************
dailogbox.show();
filename = dialogbox.getFile();
**************************************/
try {
File file;
if (directory.equals("")) {
file=new File(filename);
} else {
file = new File(directory, filename);
}
if (!file.canRead())
Error("IOHandler.getInputStream()",
"can't read file");
is = new FileInputStream(file);
} catch (FileNotFoundException e1) {
Error("IOHandler.getInputStream()",
e1.toString());
Stop();
}
}
else
{
try {
URL url = new URL(address);
is = url.openStream();
} catch (MalformedURLException e0) {
Error("IOHandler.getInputSteam()",e0.toString());
} catch (IOException e1) {
Error("IOHandler.getInputSteam()",e1.toString());
}
}
return is;
}
public void StartSaving() {}
public void Error(String where, String msg)
{
String source = "";
/*
if (type == LOCAL)
source = directory + "/" + filename;
else
source = address;
if (type == LOCAL)
source = filename;
*/
System.err.println("FILE ERROR<"+where+"> [" + linenum +"]"
+ source + " " + msg);
parent.printMessage("FILE ERROR ["+linenum +"]" +source
+ "::" +msg);
}
//jjung
protected double GetDouble(String value,String msg)
{
try {
return Double.valueOf(value).doubleValue();
} catch (NumberFormatException e) {
System.err.println(" Data file `" + address
+ "' is curroputed\n"
+ ": "+msg+ ":"+ e.toString()+"\n");
}
return 0;
}
protected double getDouble(char[] buffer, int start, int end)
{
double answer = 0;
int index= start;
while (index < end && buffer[index] != '.')
{
answer *= 10;
answer += buffer[index] - '0';
index++;
}
index++;
double shift = 1;
while (index < end)
{
shift *= .1;
answer += shift*(buffer[index] - '0');
index++;
}
return answer;
}
protected int getInt(char[] buffer,int start, int end)
{
int answer = 0;
for (int index=start; index < end; index++)
{
answer *= 10;
answer += buffer[index] - '0';
}
return answer;
}
}
There was peace and harmony in the home of the Reverend Taylor. An air of neatness and prosperity was about his four-room adobe house. The mocking-bird that hung in a willow cage against the white wall, by the door, whistled sweet mimicry of the cheep of the little chickens in the back yard, and hopped to and fro and up and down on his perches, pecking at the red chili between the bars. From the corner of his eyes he could peek into the window, and it was bright with potted geraniums, white as the wall, or red as the chili, or pink as the little crumpled palm that patted against the glass to him. It was the first scene of the closing act of the tragic comedy of the Geronimo campaign. That wily old devil, weary temporarily of the bloodshed he had continued with more or less regularity for many years, had[Pg 297] sent word to the officers that he would meet them without their commands, in the Ca?on de los Embudos, across the border line, to discuss the terms of surrender. The officers had forthwith come, Crook yet hopeful that something might be accomplished by honesty and plain dealing; the others, for the most part, doubting. The two rival Ministers of England became every day more embittered against each other; and Bolingbroke grew more daring in his advances towards the Pretender, and towards measures only befitting a Stuart's reign. In order to please the High Church, whilst he was taking the surest measures to ruin it by introducing a popish prince, he consulted with Atterbury, and they agreed to bring in a Bill which should prevent Dissenters from educating their own children. This measure was sure to please the Hanoverian Tories, who were as averse from the Dissenters as the Whigs. Thus it would conciliate them and obtain their support at the[19] very moment that the chief authors of it were planning the ruin of their party. This Bill was called the Schism Bill, and enjoined that no person in Great Britain should keep any school, or act as tutor, who had not first subscribed the declaration to conform to the Church of England, and obtained a licence of the diocesan. Upon failure of so doing, the party might be committed to prison without bail; and no such licence was to be granted before the party produced a certificate of his having received the Sacrament according to the communion of the English Church within the last year, and of his having also subscribed the oaths of Allegiance and Supremacy. The earliest martial event of the year 1760 was the landing of Thurot, the French admiral, at Carrickfergus, on the 28th of February. He had been beating about between Scandinavia and Ireland till he had only three ships left, and but six hundred soldiers. But Carrickfergus being negligently garrisoned, Thurot made his way into the town and plundered it, but was soon obliged to abandon it. He was overtaken by Captain Elliot and three frigates before he had got out to sea, his ships were taken, he himself was killed, and his men were carried prisoners to Ramsey, in the Isle of Man. "I see you've got a cow here," said a large man wearing a dingy blue coat with a Captain's faded shoulder-straps. "I'm a Commissary, and it's my duty to take her." Suddenly they heard little Pete's voice calling: "Stop your ranting and tell me how the hogs got you." "Hold, Lord de Boteler," interrupted Father John, calmly; "the threat need not pass thy lips: I go; but before I depart I shall say, in spite of mortal tongue or mortal hand, that honor and true knighthood no longer preside in this hall, where four generations upheld them unsullied." HoME小明看看台湾视频发布
ENTER NUMBET 0017
scb10.com.cn
www.pingjunba.com.cn
flkyj.com.cn
www.zuzn.com.cn
www.caize2.net.cn
www.manme8.net.cn
xiemu4.com.cn
www.3gtsm.com.cn
www.0471r.com.cn
zhiwo6.net.cn