Example #1
0
  @Test
  public void testWriteBytes() {
    /** input file bigger than the array */
    byte[] rawBits = new byte[100];

    byte[] raw2 = new byte[100];

    try {
      InputStream in = f.getFile(0);
      int read = in.read(rawBits);

      /** write the same file back */
      f.writeBytes(0, rawBits, read);

      in = f.getFile(0);
      int read2 = in.read(raw2);

      /** make sure everything is the same */
      assertTrue(read == read2);
      Arrays.equals(rawBits, raw2);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      fail();
    } catch (IncompleteFileException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      fail();
    }
  }
Example #2
0
  @Test
  public void testGetFile() {
    byte[] msg = new byte[64];
    try {
      InputStream in = f.getFile(0);
      /*
       * TODO (FindBugs)
       *
       * [RR] Method ignores results of InputStream.read()
       * [RR_NOT_CHECKED]
       *
       * This method ignores the return value of one of the variants of
       * java.io.InputStream.read() which can return multiple bytes. If
       * the return value is not checked, the caller will not be able to
       * correctly handle the case where fewer bytes were read than the
       * caller requested. This is a particularly insidious kind of bug,
       * because in many programs, reads from input streams usually do
       * read the full amount of data requested, causing the program to
       * fail only sporadically.
       */
      in.read(msg);
      System.out.println(new String(msg, "UTF-8"));

      in = f.getFile(1);
      in.read(msg);
      System.out.println(new String(msg, "UTF-8"));

      in = f.getFile(2);
      in.read(msg);
      System.out.println(new String(msg, "UTF-8"));
    } catch (IncompleteFileException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      fail();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      fail();
    }
  }