Question: Please help me implement this method! UTF 8 . java doesn't need to fixed but the methods I wrote do need to be used with
Please help me implement this method! UTFjava doesn't need to fixed but the methods I wrote do need to be used with the method I need help on Thanks!
UTFjava:
import java.util.Arrays;
public class UTF
public static void mainString args
System.out.printlntestByteCountfalse;
System.out.printlntestToBytesfalse;
Returns the number of bytes that are used
to encode a code point when using UTF
@param codePoint
@return the number of bytes that encode codePoint in UTF
public static int byteCountint codePoint
if codePoint
return ;
Four cases which return and respectively...
else if codePoint xF
return ;
else if codePoint xFF
return ;
else if codePoint xFFFF
return ;
else if codePoint xFFFF
return ;
else
return ; For large code points which cannot be encoded.
Returns the bytes that are used
to encode a code point when using UTF
@param codePoint the code point to encode
@return the bytes that encode codePoint in UTF
public static byte toBytesint codePoint
Calculates the number of bytes required
int count byteCountcodePoint;
byte b new bytecount;
If the code point only requires one byte, we can store the code point directly into the byte array b
if count
bbyte codePoint;
If the code point requires more than one byte, we will iteratively fill the byte array b
else
for int i count ; i ; i
bibytexcodePoint & xF;
codePoint ;
Since we are dealing with cases...
switch count
case :
bbytexC codePoint;
break;
case :
bbytexE codePoint;
break;
case :
bbytexF codePoint;
break;
return b;
Method I need help on:
There's a method called Help.UTFBEtoUTF Its signature is
public static byte UTFBEtoUTFbyte bytes
It converts the bytes used to encode a collection of unicode characters in UTFBE
to the bytes used to encode the same collection of unicode characters un UTF
It uses the methods you defined in UTFjava. Therefore, to perform correctly,
it requires you to have completed the first part of the HW
Use this method to make 'bytes' reference a new array of bytes ready for writing.
Open an output filestream. If a FileNotFoundException is thrown,
say to the user... output filename could not be opened for writing.
Make sure that you did not specify the name of a directory."
Converts the bytes used to encode a collection of Unicode characters in UTFBE to the bytes used to encode the same collection of Unicode characters in UTF
@param bytes The bytes to convert.
@return The converted bytes.
public static byte UTFBEtoUTFbyte bytes
TODO: Implement this method using the methods you defined in UTFjava
Hint: You can use a ByteBuffer to convert the bytes from UTFBE to UTFLE then from UTFLE to UTF
Make sure to handle the case where the input bytes are not a valid UTFBE encoded file.
throw new UnsupportedOperationExceptionNot implemented yet";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
