This week's book giveaway is in the Cloud forum.
We're giving away four copies of Terraform in Action and have Scott Winkler on-line!
See this thread for details.
Win a copy of Terraform in Action this week in the Cloud forum!

Pablo Manrubia

Greenhorn
+ Follow
since Dec 29, 2007
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Pablo Manrubia

Ok

I won't add new methods to DBMain interface.

Thanks both for your replys.
Sorry but I forgot the question...

Am i authorized to do this change according to SUN exam rules??

Thanks
Hi all!,

My app is a 3-tier application.

Id' like to change DBMain interface (addings 3 methods)
1) public void setLockStrategy(LockStrategy)
2) public Accommodation recordToAccomodation(String[] record)
3) public String[] accomodationToRecord(Accomodation ac)

Explanation:
1) Just to be able to disable/enable lockstrategy in DAO (DBMain). I don't like using singleton with a LockManager
2) and 3): Application of value object pattern in DAO. In my opinion DBMain is responsible to transform domain objects (bussiness objects) in database format objects

Thanks in advance
Hi Dmitri!,

Don't forget to change DataInputStream to RandomAccessFile.
The code above is only for debuggig
Yes, but you'd have to use dis.readUnsignedShort because it's a two bytes number.

I'm parsing my file with this code (my schema is a bit different)

InputStream is = FileDBMain.class.getResourceAsStream(FILE_NAME);
DataInputStream dis = new DataInputStream(new BufferedInputStream(is));
assert (is != null) : "File not found?" + FILE_NAME;

try {

int magicNumber = dis.readInt();
int nFields = dis.readUnsignedShort();
int[] fSizes = new int[nFields];

// schema
for (int i = 0; i < nFields; i++) {
int fieldNameLength = dis.readUnsignedByte();
dis.read(buffer, 0, fieldNameLength);
fSizes[i] = dis.readUnsignedByte();
}

// data
int counter = 0;
while (true) {
int flag = dis.readUnsignedByte();
if (flag == 0x00) {
list.add(counter);
}
for (int j = 0; j < fSizes.length; j++) {
dis.read(buffer, 0, fSizes[j]);
String fieldName = new String(buffer, 0, fSizes[j],ENCODING);
System.out.println(j + "-" + fieldName);
}
counter++;
}

} catch (EOFException e) {
// todo comentar
System.out.println("Fin de la lectura");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

I think you can't see the numbers correctly with your hex editor because each byte is interpreted as a character; they'd have to be read as two byte numbers by your application

I hope it helps!
Hi Dmitri!,

Try using DataInputStream this way...
//...
InputStream is = FileDBMain.class.getResourceAsStream(FILE_NAME);
DataInputStream dis = new DataInputStream(new BufferedInputStream(is));
//...
int magicNumber = dis.readInt();
int nRecords = dis.readUnsignedShort();
//...
for (int i = 0; i < nRecords; i++) {
int nLength = dis.readUnsignedByte();
dis.read(buffer,0, nLength);
String fieldName = new String(buffer,0,nLength,ENCODING);
int fLength = dis.readUnsignedByte();
fields[i] = fLength;
}

This way I can parse the file correctly.