DS_Store Assignment

DS_Store Assignment
Assignment 1/.idea/modules.xml
Assignment 1/.idea/workspace.xml
1590960794916 1590960794916
Assignment 1/Assignment 1.iml
Assignment 1/src/.DS_Store
Assignment 1/src/main/.DS_Store
Assignment 1/src/main/ca/.DS_Store
Assignment 1/src/main/ca/bcit/.DS_Store
Assignment 1/src/main/ca/bcit/comp2526/.DS_Store
Assignment 1/src/main/ca/bcit/comp2526/NotEnoughDataException.java
Assignment 1/src/main/ca/bcit/comp2526/NotEnoughDataException.java
package ca . bcit . comp2526 ;
public class NotEnoughDataException
extends Exception
{
private final int expected ;
public NotEnoughDataException ( final int expected )
{
super ( String . format ( “Require %d bytes to be available” , expected ));

this . expected = expected ;
}

public int getExpected ()
{
return expected ;
}
}
Assignment 1/src/main/ca/bcit/comp2526/StreamUtils.java
Assignment 1/src/main/ca/bcit/comp2526/StreamUtils.java
package ca . bcit . comp2526 ;
import java . io . DataInputStream ;
import java . io . IOException ;
import java . io . InputStream ;
public final class StreamUtils
{
private StreamUtils ()
{
throw new IllegalStateException ( “Do not instantiate” );
}
// this has issues, but will do for now
private static boolean checkAvailable ( final InputStream stream ,
final int required )
throws IOException
{
final int available ;

available = stream . available ();

return available >= required ;
}

public static void readBytes ( final DataInputStream stream ,
final byte [] bytes )
throws IOException ,
NotEnoughDataException
{
if ( ! ( checkAvailable ( stream , bytes . length )))
{
throw new NotEnoughDataException ( bytes . length );
}

stream . readFully ( bytes );
}

public static byte readByte ( final DataInputStream stream )
throws IOException ,
NotEnoughDataException
{
if ( ! ( checkAvailable ( stream , 1 )))
{
throw new NotEnoughDataException ( 1 );
}

final byte value ;

value = stream . readByte ();

return value ;
}

public static short readUnsignedByte ( final DataInputStream stream )
throws IOException ,
NotEnoughDataException
{
final byte value ;
final short unsigned ;

value = readByte ( stream );
// Why isn’t there a Byte.toUnsignedShort?!
unsigned = ( short ) Byte . toUnsignedInt ( value );

return unsigned ;
}

public static short readShort ( final DataInputStream stream )
throws IOException ,
NotEnoughDataException
{
if ( ! ( checkAvailable ( stream , 2 )))
{
throw new NotEnoughDataException ( 2 );
}

final short value ;

value = stream . readShort ();

return value ;
}

public static int readUnsignedShort ( final DataInputStream stream )
throws IOException ,
NotEnoughDataException
{
final short value ;
final int unsigned ;

value = readShort ( stream );
unsigned = Short . toUnsignedInt ( value );

return unsigned ;
}

public static int readInt ( final DataInputStream stream )
throws IOException ,
NotEnoughDataException
{
if ( ! ( checkAvailable ( stream , 4 )))
{
throw new NotEnoughDataException ( 4 );
}

final int value ;

value = stream . readInt ();

return value ;
}

public static long readUnsignedInt ( final DataInputStream stream )
throws IOException ,
NotEnoughDataException
{
final int value ;
final long unsigned ;

value = readInt ( stream );
unsigned = Integer . toUnsignedLong ( value );

return unsigned ;
}

public static float readFloat ( final DataInputStream stream )
throws IOException ,
NotEnoughDataException
{
if ( ! ( checkAvailable ( stream , 4 )))
{
throw new NotEnoughDataException ( 4 );
}

final float value ;

value = stream . readFloat ();

return value ;
}

public static long readLong ( final DataInputStream stream )
throws IOException ,
NotEnoughDataException
{
if ( ! ( checkAvailable ( stream , 8 )))
{
throw new NotEnoughDataException ( 8 );
}

final long value ;

value = stream . readLong ();

return value ;
}

public static double readDouble ( final DataInputStream stream )
throws IOException ,
NotEnoughDataException
{
if ( ! ( checkAvailable ( stream , 8 )))
{
throw new NotEnoughDataException ( 8 );
}

final double value ;

value = stream . readDouble ();

return value ;
}
}
Assignment 1/src/test/.DS_Store
Assignment 1/src/test/ca/.DS_Store
Assignment 1/src/test/ca/bcit/.DS_Store
Assignment 1/src/test/ca/bcit/comp2526/BadMagicTests.java
Assignment 1/src/test/ca/bcit/comp2526/BadMagicTests.java
package ca . bcit . comp2526 ;
import org . junit . jupiter . api . BeforeAll ;
import org . junit . jupiter . api . Test ;
import org . junit . jupiter . api . TestInstance ;
import java . io . IOException ;
import static org . hamcrest . CoreMatchers . equalTo ;
import static org . hamcrest . MatcherAssert . assertThat ;
import static org . junit . jupiter . api . Assertions . * ;
import static org . junit . jupiter . api . Assertions . assertThrows ;
public class BadMagicTests
extends ClassFileTest
{
@ Test
public void badMagicNumber1 ()
{
final InvalidMagicNumberException ex ;
ex = assertThrows ( InvalidMagicNumberException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA , ( byte ) 0xFE , ( byte ) 0xBA , ( byte ) 0xBD }));
assertThat ( ex . getMessage (), equalTo ( “Magic number must be 3405691582, was: 3405691581” ));
}

@ Test
public void badMagicNumber2 ()
{
final InvalidMagicNumberException ex ;

ex = assertThrows ( InvalidMagicNumberException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA , ( byte ) 0xFE , ( byte ) 0xBA , ( byte ) 0xBC }));
assertThat ( ex . getMessage (), equalTo ( “Magic number must be 3405691582, was: 3405691580” ));
}
}
Assignment 1/src/test/ca/bcit/comp2526/ClassFileTest.java
Assignment 1/src/test/ca/bcit/comp2526/ClassFileTest.java
package ca . bcit . comp2526 ;
import java . io . ByteArrayInputStream ;
import java . io . DataInputStream ;
import java . io . IOException ;
public abstract class ClassFileTest
{
protected ClassFile createClassFile ( final byte [] bytes )
throws IOException ,
NotEnoughDataException ,
ClassFileException
{
try ( final DataInputStream stream = new DataInputStream ( new ByteArrayInputStream ( bytes )))
{
final ClassFile classFile ;
classFile = new ClassFile ( stream );

return classFile ;
}
}
}
Assignment 1/src/test/ca/bcit/comp2526/MissingMagicTests.java
Assignment 1/src/test/ca/bcit/comp2526/MissingMagicTests.java
package ca . bcit . comp2526 ;
import org . junit . jupiter . api . Test ;
import org . junit . jupiter . api . TestInstance ;
import java . io . IOException ;
import static org . hamcrest . CoreMatchers . equalTo ;
import static org . hamcrest . MatcherAssert . assertThat ;
import static org . junit . jupiter . api . Assertions . * ;
import static org . junit . jupiter . api . Assertions . assertThrows ;
public class MissingMagicTests
extends ClassFileTest
{
@ Test
public void createClassFile ()
{
final NotEnoughDataException ex ;
ex = assertThrows ( NotEnoughDataException . class , () -> createClassFile ( new byte []{}));
assertThat ( ex . getMessage (), equalTo ( “Require 4 bytes to be available” ));
}
}
Assignment 1/src/test/ca/bcit/comp2526/MissingMajorTests.java
Assignment 1/src/test/ca/bcit/comp2526/MissingMajorTests.java
package ca . bcit . comp2526 ;
import org . junit . jupiter . api . Test ;
import org . junit . jupiter . api . TestInstance ;
import java . io . IOException ;
import static org . hamcrest . CoreMatchers . equalTo ;
import static org . hamcrest . MatcherAssert . assertThat ;
import static org . junit . jupiter . api . Assertions . assertThrows ;
public class MissingMajorTests
extends ClassFileTest
{
@ Test
public void createClassFile ()
{
final NotEnoughDataException ex ;
ex = assertThrows ( NotEnoughDataException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA , ( byte ) 0xFE , ( byte ) 0xBA , ( byte ) 0xBE , ( byte ) 0x00 , ( byte ) 0x00 }));
assertThat ( ex . getMessage (), equalTo ( “Require 2 bytes to be available” ));
}
}
Assignment 1/src/test/ca/bcit/comp2526/MissingMinorTests.java
Assignment 1/src/test/ca/bcit/comp2526/MissingMinorTests.java
package ca . bcit . comp2526 ;
import org . junit . jupiter . api . Test ;
import org . junit . jupiter . api . TestInstance ;
import java . io . IOException ;
import static org . hamcrest . CoreMatchers . equalTo ;
import static org . hamcrest . MatcherAssert . assertThat ;
import static org . junit . jupiter . api . Assertions . * ;
import static org . junit . jupiter . api . Assertions . assertThrows ;
public class MissingMinorTests
extends ClassFileTest
{
@ Test
public void createClassFile ()
{
final NotEnoughDataException ex ;
ex = assertThrows ( NotEnoughDataException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA , ( byte ) 0xFE , ( byte ) 0xBA , ( byte ) 0xBE }));
assertThat ( ex . getMessage (), equalTo ( “Require 2 bytes to be available” ));
}
}
Assignment 1/src/test/ca/bcit/comp2526/ShortMagic1Tests.java
Assignment 1/src/test/ca/bcit/comp2526/ShortMagic1Tests.java
package ca . bcit . comp2526 ;
import org . junit . jupiter . api . Test ;
import org . junit . jupiter . api . TestInstance ;
import java . io . IOException ;
import static org . hamcrest . CoreMatchers . equalTo ;
import static org . hamcrest . MatcherAssert . assertThat ;
import static org . junit . jupiter . api . Assertions . * ;
import static org . junit . jupiter . api . Assertions . assertThrows ;
public class ShortMagic1Tests
extends ClassFileTest
{
@ Test
public void createClassFile ()
{
final NotEnoughDataException ex ;
ex = assertThrows ( NotEnoughDataException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA }));
assertThat ( ex . getMessage (), equalTo ( “Require 4 bytes to be available” ));
}
}
Assignment 1/src/test/ca/bcit/comp2526/ShortMagic2Tests.java
Assignment 1/src/test/ca/bcit/comp2526/ShortMagic2Tests.java
package ca . bcit . comp2526 ;
import org . junit . jupiter . api . Test ;
import org . junit . jupiter . api . TestInstance ;
import java . io . IOException ;
import static org . hamcrest . CoreMatchers . equalTo ;
import static org . hamcrest . MatcherAssert . assertThat ;
import static org . junit . jupiter . api . Assertions . * ;
import static org . junit . jupiter . api . Assertions . assertThrows ;
public class ShortMagic2Tests
extends ClassFileTest
{
@ Test
public void createClassFile ()
{
final NotEnoughDataException ex ;
ex = assertThrows ( NotEnoughDataException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA , ( byte ) 0xFE }));
assertThat ( ex . getMessage (), equalTo ( “Require 4 bytes to be available” ));
}
}
Assignment 1/src/test/ca/bcit/comp2526/ShortMagic3Tests.java
Assignment 1/src/test/ca/bcit/comp2526/ShortMagic3Tests.java
package ca . bcit . comp2526 ;
import org . junit . jupiter . api . Test ;
import org . junit . jupiter . api . TestInstance ;
import java . io . IOException ;
import static org . hamcrest . CoreMatchers . equalTo ;
import static org . hamcrest . MatcherAssert . assertThat ;
import static org . junit . jupiter . api . Assertions . * ;
import static org . junit . jupiter . api . Assertions . assertThrows ;
public class ShortMagic3Tests
extends ClassFileTest
{
@ Test
public void createClassFile ()
{
final NotEnoughDataException ex ;
ex = assertThrows ( NotEnoughDataException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA , ( byte ) 0xFE , ( byte ) 0xBA , }));
assertThat ( ex . getMessage (), equalTo ( “Require 4 bytes to be available” ));
}
}
Assignment 1/src/test/ca/bcit/comp2526/ShortMajorTests.java
Assignment 1/src/test/ca/bcit/comp2526/ShortMajorTests.java
package ca . bcit . comp2526 ;
import org . junit . jupiter . api . Test ;
import org . junit . jupiter . api . TestInstance ;
import java . io . IOException ;
import static org . hamcrest . CoreMatchers . equalTo ;
import static org . hamcrest . MatcherAssert . assertThat ;
import static org . junit . jupiter . api . Assertions . * ;
import static org . junit . jupiter . api . Assertions . assertThrows ;
public class ShortMajorTests
extends ClassFileTest
{
@ Test
public void createClassFile ()
{
final NotEnoughDataException ex ;
ex = assertThrows ( NotEnoughDataException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA , ( byte ) 0xFE , ( byte ) 0xBA , ( byte ) 0xBE , ( byte ) 0x00 , ( byte ) 0x00 , ( byte ) 0x00 }));
assertThat ( ex . getMessage (), equalTo ( “Require 2 bytes to be available” ));
}
}
Assignment 1/src/test/ca/bcit/comp2526/ShortMinorTests.java
Assignment 1/src/test/ca/bcit/comp2526/ShortMinorTests.java
package ca . bcit . comp2526 ;
import org . junit . jupiter . api . Test ;
import org . junit . jupiter . api . TestInstance ;
import java . io . IOException ;
import static org . hamcrest . CoreMatchers . equalTo ;
import static org . hamcrest . MatcherAssert . assertThat ;
import static org . junit . jupiter . api . Assertions . * ;
import static org . junit . jupiter . api . Assertions . assertThrows ;
public class ShortMinorTests
extends ClassFileTest
{
@ Test
public void createClassFile ()
{
final NotEnoughDataException ex ;
ex = assertThrows ( NotEnoughDataException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA , ( byte ) 0xFE , ( byte ) 0xBA , ( byte ) 0xBE , ( byte ) 0x00 }));
assertThat ( ex . getMessage (), equalTo ( “Require 2 bytes to be available” ));
}
}
Assignment 1/src/test/ca/bcit/comp2526/TooHighMajorTests.java
Assignment 1/src/test/ca/bcit/comp2526/TooHighMajorTests.java
package ca . bcit . comp2526 ;
import org . junit . jupiter . api . Test ;
import java . io . IOException ;
import static org . hamcrest . CoreMatchers . equalTo ;
import static org . hamcrest . MatcherAssert . assertThat ;
import static org . junit . jupiter . api . Assertions . * ;
import static org . junit . jupiter . api . Assertions . assertThrows ;
public class TooHighMajorTests
extends ClassFileTest
{
@ Test
public void majorTooHigh1 ()
{
final InvalidMajorVersionException ex ;
ex = assertThrows ( InvalidMajorVersionException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA , ( byte ) 0xFE , ( byte ) 0xBA , ( byte ) 0xBE , ( byte ) 0x00 , ( byte ) 0x00 , ( byte ) 0x00 , ( byte ) 0x38 }));
assertThat ( ex . getMessage (), equalTo ( “Major number must be between 45 and 55, was: 56” ));
}
@ Test
public void majorTooHigh2 ()
{
final InvalidMajorVersionException ex ;

ex = assertThrows ( InvalidMajorVersionException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA , ( byte ) 0xFE , ( byte ) 0xBA , ( byte ) 0xBE , ( byte ) 0x00 , ( byte ) 0x00 , ( byte ) 0x00 , ( byte ) 0x39 }));
assertThat ( ex . getMessage (), equalTo ( “Major number must be between 45 and 55, was: 57” ));
}
}
Assignment 1/src/test/ca/bcit/comp2526/TooLowMajorTests.java
Assignment 1/src/test/ca/bcit/comp2526/TooLowMajorTests.java
package ca . bcit . comp2526 ;
import org . junit . jupiter . api . Test ;
import java . io . IOException ;
import static org . hamcrest . CoreMatchers . equalTo ;
import static org . hamcrest . MatcherAssert . assertThat ;
import static org . junit . jupiter . api . Assertions . * ;
import static org . junit . jupiter . api . Assertions . assertThrows ;
public class TooLowMajorTests
extends ClassFileTest
{
@ Test
public void majorTooLow1 ()
{
final InvalidMajorVersionException ex ;
ex = assertThrows ( InvalidMajorVersionException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA , ( byte ) 0xFE , ( byte ) 0xBA , ( byte ) 0xBE , ( byte ) 0x00 , ( byte ) 0x00 , ( byte ) 0x00 , ( byte ) 0x2C }));
assertThat ( ex . getMessage (), equalTo ( “Major number must be between 45 and 55, was: 44” ));
}

@ Test
public void majorTooLow2 ()
{
final InvalidMajorVersionException ex ;

ex = assertThrows ( InvalidMajorVersionException . class , () -> createClassFile ( new byte [] { ( byte ) 0xCA , ( byte ) 0xFE , ( byte ) 0xBA , ( byte ) 0xBE , ( byte ) 0x00 , ( byte ) 0x00 , ( byte ) 0x00 , ( byte ) 0x2B }));
assertThat ( ex . getMessage (), equalTo ( “Major number must be between 45 and 55, was: 43” ));
}
}

What Students Are Saying About Us

.......... Customer ID: 12*** | Rating: ⭐⭐⭐⭐⭐
"Honestly, I was afraid to send my paper to you, but splendidwritings.com proved they are a trustworthy service. My essay was done in less than a day, and I received a brilliant piece. I didn’t even believe it was my essay at first 🙂 Great job, thank you!"

.......... Customer ID: 14***| Rating: ⭐⭐⭐⭐⭐
"The company has some nice prices and good content. I ordered a term paper here and got a very good one. I'll keep ordering from this website."

"Order a Custom Paper on Similar Assignment! No Plagiarism! Enjoy 20% Discount"