Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

A private static writeInt method which takes a path parameter, then an integer parameter. 1 Use the Serializable API to write the given integer to

A private static writeInt method which takes a path parameter, then an integer parameter.
1 Use the Serializable API to write the given integer to the file at the given path using the default behavior.
2 This step E is the functional inverse of step F below.
F A private static readInt method which takes a path parameter and returns an integer.
1 Use the Serializable API to read the stored integer from the file at the given path using the default behavior.
2 Return the stored integer read from the file.
3 This step F is the functional inverse of step E above.
G In the Row record, modify the following features:
1 Mark that the record implements the Serializable interface, but dont implement any methods of that API.
.
I A private static readRow method which takes a path parameter and returns a row.
1 Use the Serializable API to read the stored row from the file at the given path using the default behavior.
2 Return the stored row read from the file.
3 This step I is the functional inverse of step H above.
J A private static deleteRow method which takes a path parameter.
1 Delete the file at the given path.
2 If the count of the list of files under the parent directory of the given path is now 0, delete the parent directory too.
K A private digestFunction method which takes a key parameter.
1 Define a salt which is a string literal containing your full name, then concatenate the salt with the given key.
2 Compute a digest from the salted key above using the MessageDigest algorithm SHA-1(known to be compromised).
3 Use java.util.HexFormat to convert the digest bytes to a lowercase hexadecimal string of 40 characters.
4 Return the hexadecimal string.
L A private pathOf method which takes a digest parameter (hexadecimal string).
1 Find the 2-character hexadecimal prefix and the 38-character hexadecimal suffix of the digest.
2 Resolve the suffix file under the prefix directory under the data directory.
3 Return the resolved path, which is the data directory sub 2-character prefix directory sub 38-character suffix file.
page 2/5
2ND QUARTER: FRAMEWORK, PUT, GET, REMOVE
M A public clear method.
1 Walk the data directory by streaming as follows:
i Skip the first path in the stream, which is itself being walked and shouldnt be deleted.
ii Sort the stream in reverse order, which streams from the lowest files to the highest directories.
iii For each path in the stream, delete the corresponding file or directory.
2 Call writeInt 0 to the size file under the metadata directory.
3 Call writeInt 0 to the fingerprint file under the metadata directory.
N Public methods for the following statistics and predicates:
1 The name method which returns the name of the table root, excluding the base directories (without an extension).
2 The columns method which returns the lines (list of strings) read from the columns file under the metadata directory.
3 The degree method which returns the size of the list of columns which is returned by the columns method.
4 The size method which returns readInt from the size file under the metadata directory.
5 The hashCode method which returns readInt from the fingerprint file under the metadata directory.
6 Dont implement capacity or loadFactor, because this is a FileTable, not a DataTable.
7 The equals method which returns true if the parameter is any table with the same fingerprint (as in previous modules).
O A public put method which takes a key parameter (string), then a list of fields parameter (list of objects).
1 If the degree of the given row doesnt match the result of calling the degree method, throw an illegal argument exception.
2 Find the path of the digest of the given key (calling steps K and L in order).
3 Create a new row composed of the key parameter and the list of fields parameter.
4 Check if a file exists at the path of the digest to determine a hit or a miss.
5 On a hit, readRow from the path of the old row, writeRow to the path with the new row, writeInt to the fingerprint
path under the metadata directory to update it (like in previous modules), and return the old list of fields.
6 On a miss, writeRow to the path with the new row, writeInt to the size and fingerprint paths under the metadata
directory to update them (like in previous modules), and return null.
P A public get method which takes a key parameter.
1 Find the path of the digest of the key equal to the given object (calling steps K and L in order).
2 Check if a file exists at the path of the digest to determine a hit or a miss.
3 On a hit, readRow from the path of the old row, and return the old list of fields.
4 On a miss, return null.
Q A public remove method which takes a key parameter.
1 Find the path of the digest of the key equal to the given object (calling steps K and L in order).
2 Check if a file exists at the path of the digest to determine a hit or a miss.
3 On a hit, readRow from the path of the old row, deleteRow at the same path, writeInt to the size and fingerprint
paths under the metadata

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions