Example usage for org.apache.commons.io Charsets UTF_16LE

List of usage examples for org.apache.commons.io Charsets UTF_16LE

Introduction

In this page you can find the example usage for org.apache.commons.io Charsets UTF_16LE.

Prototype

Charset UTF_16LE

To view the source code for org.apache.commons.io Charsets UTF_16LE.

Click Source Link

Document

Sixteen-bit Unicode Transformation Format, little-endian byte order.

Usage

From source file:io.cloudslang.content.services.WSManRemoteShellService.java

/**
 * Executes a command on a remote shell by communicating with the WinRM server from the remote host.
 * Method creates a shell, runs a command on the shell, waits for the command execution to finnish, retrieves the result then deletes the shell.
 *
 * @param wsManRequestInputs/*from w  w  w  . j  av  a  2s. c  om*/
 * @return a map with the result of the command and the exit code of the command execution.
 * @throws RuntimeException
 * @throws IOException
 * @throws InterruptedException
 * @throws ParserConfigurationException
 * @throws TransformerException
 * @throws XPathExpressionException
 * @throws TimeoutException
 * @throws URISyntaxException
 * @throws SAXException
 */
public Map<String, String> runCommand(WSManRequestInputs wsManRequestInputs)
        throws RuntimeException, IOException, InterruptedException, ParserConfigurationException,
        TransformerException, XPathExpressionException, TimeoutException, URISyntaxException, SAXException {
    CSHttpClient csHttpClient = new CSHttpClient();
    HttpClientInputs httpClientInputs = new HttpClientInputs();
    URL url = buildURL(wsManRequestInputs, WSMAN_RESOURCE_URI);
    httpClientInputs = setCommonHttpInputs(httpClientInputs, url, wsManRequestInputs);
    String shellId = createShell(csHttpClient, httpClientInputs, wsManRequestInputs);
    WSManUtils.validateUUID(shellId, SHELL_ID);
    String commandStr = POWERSHELL_SCRIPT_PREFIX + " "
            + EncoderDecoder.encodeStringInBase64(wsManRequestInputs.getScript(), Charsets.UTF_16LE);
    String commandId = executeCommand(csHttpClient, httpClientInputs, shellId, wsManRequestInputs, commandStr);
    WSManUtils.validateUUID(commandId, COMMAND_ID);
    Map<String, String> scriptResults = receiveCommandResult(csHttpClient, httpClientInputs, shellId, commandId,
            wsManRequestInputs);
    deleteShell(csHttpClient, httpClientInputs, shellId, wsManRequestInputs);
    return scriptResults;
}

From source file:org.apache.nifi.processors.evtx.parser.BinaryReader.java

/**
 * Reads a string encoded with UTF_16LE of a given length
 *
 * @param length the number of characters
 * @return the string//from ww  w.j av a2 s. co  m
 */
public String readWString(int length) {
    int numBytes = length * 2;
    String result = Charsets.UTF_16LE.decode(ByteBuffer.wrap(bytes, position, numBytes)).toString();
    position += numBytes;
    return result;
}

From source file:org.apache.nifi.processors.windows.event.log.ConsumeWindowsEventLogTest.java

public static List<WinNT.HANDLE> mockEventHandles(WEvtApi wEvtApi, Kernel32 kernel32, List<String> eventXmls) {
    List<WinNT.HANDLE> eventHandles = new ArrayList<>();
    for (String eventXml : eventXmls) {
        WinNT.HANDLE eventHandle = mock(WinNT.HANDLE.class);
        when(wEvtApi.EvtRender(isNull(WinNT.HANDLE.class), eq(eventHandle),
                eq(WEvtApi.EvtRenderFlags.EVENT_XML), anyInt(), any(Pointer.class), any(Pointer.class),
                any(Pointer.class))).thenAnswer(invocation -> {
                    Object[] arguments = invocation.getArguments();
                    Pointer bufferUsed = (Pointer) arguments[5];
                    byte[] array = Charsets.UTF_16LE.encode(eventXml).array();
                    if (array.length > (int) arguments[3]) {
                        when(kernel32.GetLastError()).thenReturn(W32Errors.ERROR_INSUFFICIENT_BUFFER)
                                .thenReturn(W32Errors.ERROR_SUCCESS);
                    } else {
                        ((Pointer) arguments[4]).write(0, array, 0, array.length);
                    }/*from  ww  w  . ja  v a  2 s. co  m*/
                    bufferUsed.setInt(0, array.length);
                    return false;
                });
        eventHandles.add(eventHandle);
    }
    return eventHandles;
}

From source file:org.apache.nifi.processors.windows.event.log.jna.EventSubscribeXmlRenderingCallback.java

@Override
public synchronized int onEvent(int evtSubscribeNotifyAction, WinDef.PVOID userContext,
        WinNT.HANDLE eventHandle) {/*  ww w  .  j  a  va  2s  . c om*/
    if (logger.isDebugEnabled()) {
        logger.debug("onEvent(" + evtSubscribeNotifyAction + ", " + userContext + ", " + eventHandle);
    }

    if (evtSubscribeNotifyAction == WEvtApi.EvtSubscribeNotifyAction.ERROR) {
        if (eventHandle.getPointer().getInt(0) == WEvtApi.EvtSubscribeErrors.ERROR_EVT_QUERY_RESULT_STALE) {
            logger.error(MISSING_EVENT_MESSAGE);
        } else {
            logger.error(RECEIVED_THE_FOLLOWING_WIN32_ERROR + eventHandle.getPointer().getInt(0));
        }
    } else if (evtSubscribeNotifyAction == WEvtApi.EvtSubscribeNotifyAction.DELIVER) {
        wEvtApi.EvtRender(null, eventHandle, WEvtApi.EvtRenderFlags.EVENT_XML, size, buffer, used,
                propertyCount);

        // Not enough room in buffer, resize so it's big enough
        if (kernel32.GetLastError() == W32Errors.ERROR_INSUFFICIENT_BUFFER) {
            int newMaxSize = used.getInt(0);
            // Check for overflow or too big
            if (newMaxSize < size || newMaxSize > maxBufferSize) {
                logger.error("Dropping event " + eventHandle + " because it couldn't be rendered within "
                        + maxBufferSize + " bytes.");
                // Ignored, see https://msdn.microsoft.com/en-us/library/windows/desktop/aa385577(v=vs.85).aspx
                return 0;
            }
            size = newMaxSize;
            buffer = new Memory(size);
            wEvtApi.EvtRender(null, eventHandle, WEvtApi.EvtRenderFlags.EVENT_XML, size, buffer, used,
                    propertyCount);
        }

        int lastError = kernel32.GetLastError();
        if (lastError == W32Errors.ERROR_SUCCESS) {
            int usedBytes = used.getInt(0);
            String string = Charsets.UTF_16LE.decode(buffer.getByteBuffer(0, usedBytes)).toString();
            if (string.endsWith("\u0000")) {
                string = string.substring(0, string.length() - 1);
            }
            consumer.accept(string);
        } else {
            logger.error(EVT_RENDER_RETURNED_THE_FOLLOWING_ERROR_CODE + errorLookup.getLastError() + ".");
        }
    }
    // Ignored, see https://msdn.microsoft.com/en-us/library/windows/desktop/aa385577(v=vs.85).aspx
    return 0;
}