Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/neuron/jaffer/AFP_ServerInfo.java


1   /* 
2    * Copyright (c) 2003 Stewart Allen <stewart@neuron.com>. All rights reserved.
3    * This program is free software. See the 'License' file for details.
4    */
5   
6   package com.neuron.jaffer;
7   
8   import java.io.*;
9   import java.net.*;
10  import java.util.*;
11  
12  // Reference: Inside Appletalk p. 442
13  // TODO: icon/mask support
14  class AFP_ServerInfo extends Utility
15  {
16    private String serverName;
17    private String afpVersions[];
18    private String uamModules[];
19    private Object icon;
20    private int    flags;
21  
22    AFP_ServerInfo(String sn, String av[], String ua[], int flags)
23    {
24      this.serverName = sn;
25      this.afpVersions = av;
26      this.uamModules = ua;
27      this.flags = flags;
28    }
29  
30    AFP_ServerInfo(ByteReader rr)
31      throws IOException
32    {
33      serverName = readPString(rr, readInt2(rr, 0));
34      afpVersions = readPStringArray(rr, readInt2(rr, 2));
35      uamModules  = readPStringArray(rr, readInt2(rr, 4));
36      flags       = readInt2(rr, 8);
37    }
38  
39    private int readInt2(ByteReader rr, int pos)
40      throws IOException
41    {
42      rr.seek(pos);
43      return rr.readUnsignedShort();
44    }
45  
46    private String readPString(ByteReader rr, int pos)
47      throws IOException
48    {
49      rr.seek(pos);
50      return rr.readPString();
51    }
52  
53    private String[] readPStringArray(ByteReader rr, int pos)
54      throws IOException
55    {
56      rr.seek(pos);
57      return rr.readPStringArray();
58    }
59  
60    public void write(ByteWriter ww)
61    {
62      ww.writePStringDeferred("Jaffer");
63      ww.writePStringArrayDeferred(afpVersions);
64      ww.writePStringArrayDeferred(uamModules);
65      ww.writeShort(0); // icon/mask offset
66      ww.writeShort(flags);
67      ww.writePString(serverName); // server name
68      if (ww.getOffset() % 2 == 1)
69      {
70        ww.writeByte(0);
71      }
72      ww.writeShort(0); // server signature offset (not implemented)
73      ww.writeShort(0); // network address offset (TODO)
74      ww.writeShort(0); // directory names offset (not implemented)
75      //ww.writePString(serverName); // server name in UTF8 (TODO)
76    }
77  
78    private final static int codedLength(String s[])
79    {
80      int len = 1;
81      for (int i=0; s != null && i<s.length; i++)
82      {
83        len += (s[i].length()+1);
84      }
85      return len;
86    }
87  
88    public String toString()
89    {
90      return
91        "sn="+serverName+",av="+list(afpVersions)+",uam="+list(uamModules)+",fl="+bits(flags,2);
92    }
93  }
94