Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

For all files and paths, use the Files and Paths APIs from the java.nio.file package when possible. B The following private fields: 1 A static

For all files and paths, use the Files and Paths APIs from the java.nio.file package when possible.
B The following private fields:
1 A static constant path for the base directories, which are db sub tables relative to the project directory.
2 A path for the table root, which is a directory containing a hierarchy of directories and files.
3 A path for the data directory, which is data resolved under the table root.
4 A path for the metadata directory, which is metadata resolved under the table root.
5 No fields for the degree, size, fingerprint, or other fields (unlike in previous modules), nor any other fields.
C A 2-ary constructor which takes a name parameter (string) and a columns parameter (list of strings).
1 Initialize the table root field by resolving the given name (without an extension) relative to the base directories.
2 Create the table root directory, if needed.
3 Initialize the data and metadata directories by resolving them under the table root.
4 Create the data and metadata directories, if needed.
5 Write the given columns as a list of lines (strings) to a columns file under the metadata directory.
D A 1-ary constructor which takes a name parameter (string) only.
1 Initialize the table root field by resolving the given name (without an extension) relative to the base directories.
2 If the directory doesnt exist at the table root field, throw an illegal argument exception.
3 Initialize the data and metadata directories by resolving them under the table root.
E 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.
H A private static writeRow method which takes a path parameter, then a row parameter.
1 Create the parent directories of the given path (not the path itself, but the paths parent), if needed.
2 Use the Serializable API to write the given row to the file at the given path using the default behavior.
3 This step H is the functional inverse of step I below.
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.

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