Example usage for org.apache.poi.util StringUtil getFromUnicodeLE

List of usage examples for org.apache.poi.util StringUtil getFromUnicodeLE

Introduction

In this page you can find the example usage for org.apache.poi.util StringUtil getFromUnicodeLE.

Prototype

public static String getFromUnicodeLE(byte[] string) 

Source Link

Document

Given a byte array of 16-bit unicode characters in little endian format (most important byte last), return a Java String representation of it.

Usage

From source file:com.hp.application.automation.tools.octane.actions.UFTParameterFactory.java

License:Apache License

public static String convertResourceMtrAsJSON(InputStream resourceMtrInputStream) throws IOException {

    //TODO: Check is exists
    poiFS = new POIFSFileSystem(resourceMtrInputStream);
    DirectoryNode root = poiFS.getRoot();

    for (Entry entry : root) {
        String name = entry.getName();
        if (name.equals("ComponentInfo")) {
            if (entry instanceof DirectoryEntry) {
                System.out.println(entry);
            } else if (entry instanceof DocumentEntry) {
                byte[] content = new byte[((DocumentEntry) entry).getSize()];
                poiFS.createDocumentInputStream("ComponentInfo").read(content);
                String fromUnicodeLE = StringUtil.getFromUnicodeLE(content);
                xmlData = fromUnicodeLE.substring(fromUnicodeLE.indexOf('<')).replaceAll("\u0000", "");
                //                    System.out.println(xmlData);
            }//from w w  w  . j  av a2s .c o m
        }
    }
    try {
        SAXBuilder saxBuilder = new SAXBuilder(XMLReaders.NONVALIDATING, (SAXHandlerFactory) null,
                (JDOMFactory) null);
        Document document = null;
        document = saxBuilder.build(new StringReader(xmlData));
        Element classElement = document.getRootElement();
        List<Element> studentList = classElement.getChildren();
        ObjectMapper mapper = new ObjectMapper();
        ArrayList<UFTParameter> uftParameters = new ArrayList<UFTParameter>();
        UFTParameter uftParameter = new UFTParameter();
        for (int temp = 0; temp < studentList.size(); temp++) {
            Element tag = studentList.get(temp);
            if ("ArgumentsCollection".equalsIgnoreCase(tag.getName())) {
                List<Element> children = tag.getChildren();
                for (int i = 0; i < children.size(); i++) {
                    Element element = children.get(i);
                    List<Element> elements = element.getChildren();

                    for (int j = 0; j < elements.size(); j++) {

                        Element element1 = elements.get(j);
                        switch (element1.getName()) {
                        case "ArgName":
                            uftParameter.setArgName(element1.getValue());
                            break;
                        case "ArgDirection":
                            uftParameter.setArgDirection(Integer.parseInt(element1.getValue()));
                            break;
                        case "ArgDefaultValue":
                            uftParameter.setArgDefaultValue(element1.getValue());
                            break;
                        case "ArgType":
                            uftParameter.setArgType(element1.getValue());
                            break;
                        case "ArgIsExternal":
                            uftParameter.setArgIsExternal(Integer.parseInt(element1.getValue()));
                            break;
                        default:
                            logger.warning(
                                    String.format("Element name %s didn't match any case", element1.getName()));
                            break;
                        }
                    }
                    uftParameters.add(uftParameter);
                }
                return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(uftParameters);
            }
        }
    } catch (Exception e) {
        logger.severe(e.getMessage());
    }
    return null;
}

From source file:com.hp.octane.integrations.uft.UftTestDiscoveryUtils.java

License:Apache License

private static String extractXmlContentFromTspFile(InputStream stream) throws IOException {
    POIFSFileSystem poiFS = new POIFSFileSystem(stream);
    DirectoryNode root = poiFS.getRoot();
    String xmlData = "";

    for (Entry entry : root) {
        String name = entry.getName();
        if ("ComponentInfo".equals(name)) {
            if (entry instanceof DirectoryEntry) {
                System.out.println(entry);
            } else if (entry instanceof DocumentEntry) {
                byte[] content = new byte[((DocumentEntry) entry).getSize()];
                int readBytes = poiFS.createDocumentInputStream("ComponentInfo").read(content);
                if (readBytes < content.length) {
                    //  [YG] probably should handle this case and continue to read
                    logger.warn("expected to read " + content.length + " bytes, but read and stopped after "
                            + readBytes);
                }// w  w w. j a  v a2  s  .co m
                String fromUnicodeLE = StringUtil.getFromUnicodeLE(content);
                xmlData = fromUnicodeLE.substring(fromUnicodeLE.indexOf('<')).replaceAll("\u0000", "");
            }
        }
    }
    return xmlData;
}

From source file:com.hpe.application.automation.tools.octane.actions.UFTTestUtil.java

License:Open Source License

public static String decodeXmlContent(InputStream stream) throws IOException {
    POIFSFileSystem poiFS = new POIFSFileSystem(stream);
    DirectoryNode root = poiFS.getRoot();
    String xmlData = "";

    for (Entry entry : root) {
        String name = entry.getName();
        if ("ComponentInfo".equals(name)) {
            if (entry instanceof DirectoryEntry) {
                System.out.println(entry);
            } else if (entry instanceof DocumentEntry) {
                byte[] content = new byte[((DocumentEntry) entry).getSize()];
                poiFS.createDocumentInputStream("ComponentInfo").read(content);
                String fromUnicodeLE = StringUtil.getFromUnicodeLE(content);
                xmlData = fromUnicodeLE.substring(fromUnicodeLE.indexOf('<')).replaceAll("\u0000", "");
            }/*from   w  ww  .  java  2  s . c om*/
        }
    }
    return xmlData;
}

From source file:org.apache.tika.parser.dwg.DWGParser.java

License:Apache License

private String read2007and2010String(InputStream stream) throws IOException, TikaException {
    int stringLen = EndianUtils.readUShortLE(stream);

    byte[] stringData = new byte[stringLen * 2];
    IOUtils.readFully(stream, stringData);
    String value = StringUtil.getFromUnicodeLE(stringData);

    // Some strings are null terminated
    if (value.charAt(value.length() - 1) == 0) {
        value = value.substring(0, value.length() - 1);
    }/*from  w w w  .jav a2  s. c  o m*/

    return value;
}