how to add image meta data after updating

Viewed 27

I have used apache tika for extracting metadata from an image file.After extracting metadata I am able to update or add some new meta tag data.Now I want to attach that updated meta tag data to that image file.How can i do that.

here's the code for getting image meta data

public Metadata getImageMetaData(){
try {
            FileInputStream fileInputStream = new FileInputStream(mainFile);
            Parser parser = new AutoDetectParser();
            BodyContentHandler handler = new BodyContentHandler();
            Metadata metaData = new Metadata();
            ParseContext parseContext = new ParseContext();

            try {
                parser.parse(fileInputStream, handler, metaData, parseContext);
            } catch (IOException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (TikaException e) {
                e.printStackTrace();
            }
            return metaData;
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return null;    
    }

and here's the code for updating meta data

private Metadata updateImageMetaData(Metadata metaData) {

        JSONArray imageMetaTagArray = new JSONArray(getNode().getImageMetaTagDto().getMetaTag());

        for (int i = 0; i < imageMetaTagArray.length(); i++) {
            JSONObject imageMetaTagJson = imageMetaTagArray.getJSONObject(i);
            Iterator<String> keys = imageMetaTagJson.keys();
            while (keys.hasNext()) {
                String key = keys.next();
                metaData.set(key, imageMetaTagJson.get(key).toString());
            }
        }
        return metaData;
    }

now my question is how to add the updating meta data to this image.

0 Answers
Related