Java Code Examples for java.util.zip.DataFormatException

Following code examples demonstrate how to use java.util.zip.DataFormatExceptionfrom android. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use java.util.zip.DataFormatExceptionand various code implementation of this class.

    @Category(Draft.class)
    public void create_DataFormatException()
    throws Exception {
        @SuppressWarnings("unused")
        final DataFormatException sut = new DataFormatException();
    } 


            public int inflate(byte[] arrby, int n2, int n3) throws DataFormatException {
                int n4 = super.inflate(arrby, n2, n3);
                if (n4 == 0 && this.needsDictionary()) {
                    this.setDictionary(Spdy3.DICTIONARY);
                    n4 = super.inflate(arrby, n2, n3);
                }
                return n4;
            } 

    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to DataFormatException.class!",
                   DataFormatException.class.isAssignableFrom(sut));
    } 

  
  HeartbeatMsg(byte[] in) throws DataFormatException
  {
    
    if (in.length != 1 || in[0] != MSG_TYPE_HEARTBEAT)
    {
      throw new DataFormatException("Input is not a valid Heartbeat Message.");
    }
  } 

    public static void main(String[] args) {

	try {

	    DonneesSimulation d = LecteurDonnees.creeDonnees("cartes/carteSujet.map");

	    Robot r0 = d.getRobot(0);
	    Robot r1 = d.getRobot(1);
	    Robot r2 = d.getRobot(2);

	    
	    System.out.println("\n ******** HERE IS INFORMATION ON THE MAP ********");
	    System.out.println(d.getCarte());
	    System.out.println("");

	    System.out.println("\n ******** HERE IS INFORMATION ON THE ROBOT POSITION ********");
	    System.out.println(r2.getPosition());
	    System.out.println("");

	    System.out.println("\n ******** HERE IS THE SHORTEST PATH  TO : (0,0) ********");
	    
	    Dijkstra dij = new Dijkstra(r2.getMatriceAdj(), r2.getPosition(), d.getCarte().getCase(0,0), d.getCarte());

	    Chemin chemin = dij.getPCC();
	    Iterator<Case> ite = chemin.getIterator();
	    Case currentCase;
	    
	    while (ite.hasNext()) {

		currentCase = ite.next();
		System.out.print("(" + currentCase.getLigne() + " , "
				 + currentCase.getColonne() + ") -> ");

	    }

	    System.out.print("THE LENGTH OF THIS PATH IS : " + chemin.getDuree());
	    System.out.println("");
		    
	    
	} catch (FileNotFoundException e) {
	    
	    System.out.println("fichier " + args[0] + " inconnu ou illisible");
	    
	} catch (DataFormatException e) {
            System.out.println("\n\t**format du fichier " + args[0] + " invalide: " + e.getMessage());  
        }

    } 

    public static void main(String[] args) throws NoSuchAlgorithmException, UnsupportedEncodingException, IOException, DataFormatException {

        DataEncryption dataEncryption = new DataEncryption();
        SignDataWithKey signDataWithKey = new SignDataWithKey();
        

        final String strToEncrypt = "Hello Amran";
        final String strPssword = "just@1234";
        final String orgId = "0001";
        Pair<String, String> encData = dataEncryption.encrypt(strToEncrypt, strPssword, orgId);
        byte[] publicKeyValue = CompressionUtils.compress(FileReadWrite.getPubKeyFile(orgId));
        String signResult = signDataWithKey.dataSignWithDSAndPrivateKey(encData.getValue(), orgId);
        

        System.out.println("------------------Key Value----------------------------------");
        System.out.println("| " + CompressionUtils.compress(signResult.getBytes("UTF-8"))
                + " | " + CompressionUtils.compress(encData.getKey().getBytes("UTF-8"))
                + " | " + publicKeyValue);
        System.out.println("------------------Key Value-----------------------------------");

    } 

            public int inflate(byte[] arrby, int n2, int n3) throws DataFormatException {
                int n4 = super.inflate(arrby, n2, n3);
                if (n4 == 0 && this.needsDictionary()) {
                    this.setDictionary(o.a);
                    n4 = super.inflate(arrby, n2, n3);
                }
                return n4;
            } 

	public static void main(String[] args) {
		Carte map = new Carte(3, 2, 100);
		Robot drone1 = new Drone(map, map.getCase(0, 0));
		Robot drone2 = new Drone(map, map.getCase(0, 0), 150);
		MatriceAdj adj = new MatriceAdj(drone2, map);
		int[][] mat = adj.getMatriceAdj();
		afficher(mat);

		try {
     	       	DonneesSimulation d = LecteurDonnees.creeDonnees("cartes/carteSujet.map");
		Robot r0 = d.getRobot(0);
		Robot r1 = d.getRobot(1);
		Robot r2 = d.getRobot(2);
		afficher(r2.getMatriceAdj());
		} catch (FileNotFoundException e) {
           	 System.out.println("fichier " + args[0] + " inconnu ou illisible");
       		 } catch (DataFormatException e) {
            System.out.println("\n\t**format du fichier " + args[0] + " invalide: " + e.getMessage());  
        }

	} 

    public static void main(String args[]) throws IOException, DataFormatException {

        final String stringValue = "This is the sample text to write to a file.";
        final String fileName = "checksumed.dat";

        deflate(stringValue, fileName);

        inflate(fileName);
    } 

    public static void inflate(final String fileName) throws IOException, DataFormatException {

        FileInputStream fin = new FileInputStream(fileName);
        byte[] bytes = new byte[1024];
        fin.read(bytes);
        Inflater inflate = new Inflater(true);
        inflate.setInput(bytes);
        byte[] byteValues = new byte[1024];
        inflate.inflate(byteValues);
        inflate.end();
        System.out.println("The values are : " + new String(byteValues));
    } 

    private static void m() throws DataFormatException {
        try {
            throw new FileNotFoundException();
        } finally {
            throw new DataFormatException();
        }
    } 

    public static void main(String[] args) {
        try {
            m();
        } catch (DataFormatException e) {
            e.printStackTrace();
        }
    } 

        switch (contentEncoding) {
            case "compress":
                in = new CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.BROTLI, is);
                break;
            case "gzip":
                in = new CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.GZIP, is);
                break;
            case "deflate":
                in = new CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.DEFLATE, is);
                break;
                return data;
            case "br":
                in = new CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.BROTLI, is);
                break;
            case "xz":
                in = new CompressorStreamFactory().createCompressorInputStream(CompressorStreamFactory.XZ, is);
                break;
            default:
                throw new DataFormatException("Unsupported content-encoding: " + contentEncoding);
        } 

Advertisement
Javadoc
Signals that a data format error has occurred. @author David Connelly
Advertisement