Used to encode the request content using the OpenCsv writer.

@param config the configuration
@param ts the server request content accessor
484800
public static void encode(final ChainedHttpConfig config, final ToServer ts) {
        if (handleRawUpload(config, ts)) {
            return;
        }

        final ChainedHttpConfig.ChainedRequest request = config.getChainedRequest();
        final Csv.Context ctx = (Csv.Context) config.actualContext(request.actualContentType(), Csv.Context.ID);
        final Object body = checkNull(request.actualBody());
        checkTypes(body, new Class[]{Iterable.class});
        final StringWriter writer = new StringWriter();
        final CSVWriter csvWriter = ctx.makeWriter(new StringWriter());

        Iterable<?> iterable = (Iterable<?>) body;
        for (Object o : iterable) {
            csvWriter.writeNext((String[]) o);
        }

        ts.toServer(stringToStream(writer.toString(), request.actualCharset()));
    }
713867
public void encode(AsnOutputStream aos) throws EncodeException {

        if (this.originatingTransactionId == null || this.originatingTransactionId.length != 4)
            throw new EncodeException("Error while encoding TCQueryMessage: originatingTransactionId is not defined or has not a length 4");

        if ((this.component == null || this.component.length == 0) && this.dp == null)
            throw new EncodeException("Error while encoding TCQueryMessage: neither dialogPortion nor componentPortion is defined");

        try {
            if (this.dialogTermitationPermission)
                aos.writeTag(Tag.CLASS_PRIVATE, false, TCQueryMessage._TAG_QUERY_WITH_PERM);
            else
                aos.writeTag(Tag.CLASS_PRIVATE, false, TCQueryMessage._TAG_QUERY_WITHOUT_PERM);
            int pos = aos.StartContentDefiniteLength();

            aos.writeOctetString(Tag.CLASS_PRIVATE, TCQueryMessage._TAG_TRANSACTION_ID, this.originatingTransactionId);

            if (this.dp != null)
                this.dp.encode(aos);

            if (component != null && component.length > 0) {
                aos.writeTag(Tag.CLASS_PRIVATE, false, TCQueryMessage._TAG_COMPONENT_SEQUENCE);
                int pos2 = aos.StartContentDefiniteLength();
                for (Component c : this.component) {
                    c.encode(aos);
                }
                aos.FinalizeContent(pos2);
            }

            aos.FinalizeContent(pos);

        } catch (IOException e) {
            throw new EncodeException("IOException while encoding TCQueryMessage: " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new EncodeException("AsnException while encoding TCQueryMessage: " + e.getMessage(), e);
        }

    }
207449
private void processConfiguration(final MtasConfiguration config)
      throws IOException {
    HashMap<String, Integer> indexEncodingMapper = new HashMap<>();
    indexEncodingMapper.put("payload", MtasPayloadEncoder.ENCODE_PAYLOAD);
    indexEncodingMapper.put("offset", MtasPayloadEncoder.ENCODE_OFFSET);
    indexEncodingMapper.put("realoffset", MtasPayloadEncoder.ENCODE_REALOFFSET);
    indexEncodingMapper.put("parent", MtasPayloadEncoder.ENCODE_PARENT);
    // process
    if (config != null) {
      for (int i = 0; i < config.children.size(); i++) {
        if (config.children.get(i).name.equals(CONFIGURATION_MTAS_INDEX)) {
          MtasConfiguration index = config.children.get(i);
          for (int j = 0; j < index.children.size(); j++) {
            if (indexEncodingMapper.containsKey(index.children.get(j).name)) {
              String value = index.children.get(j).attributes.get(CONFIGURATION_MTAS_INDEX_ATTRIBUTE);
              if ((value.equals(VALUE_TRUE)) || (value.equals(VALUE_1))) {
                encodingFlags |= indexEncodingMapper
                    .get(index.children.get(j).name);
              } else if ((value.equals(VALUE_FALSE)) || (value.equals(VALUE_0))) {
                encodingFlags &= ~indexEncodingMapper
                    .get(index.children.get(j).name);
              }
            }
          }
        } else if (config.children.get(i).name.equals(CONFIGURATION_MTAS_PARSER)) {
          if (config.children.get(i).attributes.containsKey(CONFIGURATION_MTAS_PARSER_ATTRIBUTE)) {
            parserName = config.children.get(i).attributes.get(CONFIGURATION_MTAS_PARSER_ATTRIBUTE);
            parserConfiguration = config.children.get(i);
          } else {
            throw new IOException("no parser configuration");
          }
        }
      }
    } else {
      throw new IOException("no (valid) configuration");
    }
  }
1353625
@Modified
    protected void modified(Map<String, Object> config) {
        if (null == config || config.isEmpty()) {
            return;
        }

        // config dictionaries are case-insensitive but case preserving per spec.
        // The default value type is String, unless a different type is indicated in metatype.

        setContextRootNotFoundMessage((String) config.get(PROP_VHOST_NOT_FOUND));

        enableWelcomePage(MetatypeUtils.parseBoolean(CONFIG_ALIAS,
                                                     PROP_ENABLE_WELCOME_PAGE,
                                                     config.get(PROP_ENABLE_WELCOME_PAGE),
                                                     true));

        setPadContextRootNotFoundMessage(MetatypeUtils.parseBoolean(CONFIG_ALIAS,
                                                                    PROP_PAD_VHOST_NOT_FOUND,
                                                                    config.get(PROP_PAD_VHOST_NOT_FOUND),
                                                                    false));

        origHeaderOrigin = MetatypeUtils.parseStringArray(CONFIG_ALIAS,
                                                          PROP_TRUSTED_PRIVATE_HEADER_ORIGIN,
                                                          config.get(PROP_TRUSTED_PRIVATE_HEADER_ORIGIN),
                                                          new String[] { "*" });

        origSensitiveHeaderOrigin = MetatypeUtils.parseStringArray(CONFIG_ALIAS,
                                                                   PROP_TRUSTED_SENSITIVE_HEADER_ORIGIN,
                                                                   config.get(PROP_TRUSTED_SENSITIVE_HEADER_ORIGIN),
                                                                   new String[] { "none" });

        parseTrustedPrivateHeaderOrigin(origHeaderOrigin, origSensitiveHeaderOrigin);
    }
458449
function (config) {

    // check parameters
    if ((typeof config.IN_PORT !== 'number' && 
        typeof config.OUT_PORT !== 'number')) {
    
        LOG.warn('config needs to define parameters: IN_PORT or OUT_PORT');
        return; 
    }
	
	var server_type = config.type || 'MPEG';

    var STREAM_SECRET = config.secret;
		IN_PORT = config.IN_PORT || 8082,
		OUT_PORT = config.OUT_PORT || 8084,
		STREAM_MAGSR_BYTES = 'jsmp'; // Must be 4 bytes
		
	// channel info
	var l_channels = {};
        
    var socketServer = undefined;
    var streamServer = undefined;

    this.start = function () {
    
        // Websocket Server
        socketServer = new (require('ws').Server)({port: OUT_PORT});
		
		// process incoming connection of subscribers
        socketServer.on('connection', function (socket) {

			// generate unique clientID
			var clientID = UTIL.createUUID();
			var clientData = socketServer.clients[socketServer.clients.length - 1];
			
			var channel = undefined;
			LOG.sys( 'New WebSocket Connection (' + socketServer.clients.length + ' total) id: ' + clientID );
					 
			// we start to handle after receiving channel name to subscribe
			// NOTE: the incoming content is not string type
			socket.on('message', function (name) {

                try {
 
                    /*
					var obj = JSON.parse(name.data);
					LOG.warn(obj);
					*/
                    
					// extract info
					if (l_channels.hasOwnProperty(name) === false) {
						var msg = 'no stream registered for channel [' + name + ']';
						LOG.warn(msg);
						socket.send(msg);
						return;
					}
					
					// record channel name
					channel = name;
					
					// get parameters
					var params = l_channels[channel].para;
		        
					// NOTE: we convert string to numbers with | 0			
					var width = (params[0] || 320) | 0;
					var height = (params[1] || 240) | 0;
					
					LOG.warn('params:');
					LOG.warn(params);
					LOG.warn('client to receive channel: ' + channel + ' w: ' + width + ' h: ' + height);
                
					// record this user's reference as part of the channel subscribers
					// NOTE: we record clientData, not socket
					l_channels[channel].users[clientID] = clientData;   
					
					LOG.warn('channel [' + channel + '] has ' + Object.keys(l_channels[channel].users).length + ' users', 'message');
					
					// Send back magic bytes and video size to the newly connected socket
					// struct { char magic[4]; unsigned short width, height;}
					var streamHeader = new Buffer(8);
					streamHeader.write(STREAM_MAGSR_BYTES);
					streamHeader.writeUInt16BE(width, 4);
					streamHeader.writeUInt16BE(height, 6);
					socket.send(streamHeader, {binary:true}); 
                
                }
                catch(e) {
                    LOG.error(e);
                }    
			});
			
			// handles closing in-coming connection
			socket.on('close', function (code, message) {
				LOG.sys( 'Disconnected WebSocket (' + socketServer.clients.length + ' total)' );
				
				// remove user record (i.e., socket) from channel
				if (l_channels.hasOwnProperty(channel)) {		
					delete l_channels[channel].users[clientID];
					LOG.warn('client [' + clientID + '] unsubscribe from channel [' + channel + ']');
				}
			});
        });
    
        socketServer.broadcast = function (channel, data, opts) {
		
			// go over all clients for a given channel
			if (l_channels.hasOwnProperty(channel) === false) {
				LOG.warn('channel [' + channel + '] not registered, cannot broadcast');
				return;
			}
			//LOG.warn('channel [' + channel + '] has ' + Object.keys(l_channels[channel].users).length + ' users', 'broadcast');
			
			var clients = l_channels[channel].users;
			
			for (var id in clients) {
				
				try {
					//this.clients[i].send(data, opts);
					clients[id].send(data, opts);
				}
				catch(e) {
					LOG.warn('client[' + id + '] fails to send to channel [' + channel + ']');
				}
			}
        };
    
        // HTTP Server to accept incoming MPEG Stream
        streamServer = require('http').createServer(function (request, response) {
			var params = request.url.substr(1).split('/');			
			var channel = params[0];
        
			if (channel) {
				LOG.sys(
					'Stream Connected: ' + request.socket.remoteAddress + 
					':' + request.socket.remotePort + ' channel: ' + channel
				);
				
				//' size: ' + width + 'x' + height
				
				
				// remove first element (channel name) and store the rest as parameters
				params.splice(0, 1);
				l_channels[channel] = {
					para: params,		// app-specific parameters in string array format
					users: {}			// user clients conneted awating message updates
				}
				
				request.on('data', function(data) {
					if (socketServer)
						socketServer.broadcast(channel, data, {binary:true});
				});
			}
			else {
				LOG.sys(
					'failed connection: '+ request.socket.remoteAddress + 
					request.socket.remotePort + ' - no channel specified.'
				);
				response.end();
			}
        }).listen(IN_PORT);
    
        LOG.warn('Listening for stream on http://'+ SR.Settings.SERVER_INFO.IP +':'+IN_PORT+'/<channel>/<para1>/<para2>/<para3>/...', 'SR.Stream');
        LOG.warn('Awaiting WebSocket connections on ws://' + SR.Settings.SERVER_INFO.IP + ':'+OUT_PORT+'/', 'SR.Stream');
    }
    
    this.stop = function () {

        if (socketServer) {
            socketServer.close();
        }
        
        if (streamServer) {
            streamServer.close();
        }
    }
    
}
565416
protected function encodeConfiguration($config = [])
    {
        $value = [];
        ksort($config);
        foreach ($config as $directive => $values) {
            $values = array_unique($values);
            sort($values);
            array_unshift($values, $directive);
            $string = implode($this->sourceSeparator, $values);

            if ($string) {
                $value[] = $string;
            }
        }

        return implode($this->directiveSeparator . ' ', $value);
    }
851885
function csvWrapForExcel(encoder) {
  // Pipe the CSV encoder to the ucs2 converter
  var converter = new Stream.Transform();
  var csvStream = new Stream.PassThrough();
  converter._transform = function(chunk, encoding, cb) {
    this.push(new Buffer(chunk.toString(), 'ucs2'));
    cb();
  };
  // Write the UCS2 BOM http://www.unicode.org/faq/utf_bom.html#bom1
  csvStream.write(new Buffer([0xFF, 0xFE]));
  return encoder.pipe(converter).pipe(csvStream);
}
848088
public void writeAddition(Writer writer, String type, String name) throws IOException {
		writer.append(TAB).append(ANGULAR_MODULE).append(OPENPARENTHESIS).append(MODULENAME).append(CLOSEPARENTHESIS)
				  .append(DOT).append(type).append(OPENPARENTHESIS);
		if(name!=null) {
			writer.append("'").append(name).append("'").append(COMMA).append(SPACEOPTIONAL);
		}
		writer.append(type).append(CLOSEPARENTHESIS).append(SEMICOLON).append(CR); //\tangular.module('ocelot.ds').type(type);
	}
1362058
@Override
	public void encodeBegin(FacesContext context, UIComponent component) throws IOException {
		assertComponentIsInsideForm(component,
				"The initially opened tab is opened after an post-back request, regardless which tab has been previously activated by the user");
		if (!component.isRendered()) {
			return;
		}
		TabView tabView = (TabView) component;
		ResponseWriter writer = context.getResponseWriter();
		String clientId = tabView.getClientId();
		if (!tabView.isRendered()) {
			return;
		}

		writer.startElement("input", tabView);
		writer.writeAttribute("type", "hidden", null);
		final String hiddenInputFieldID = clientId.replace(":", "_") + "_activeIndex";
		writer.writeAttribute("name", hiddenInputFieldID, "name");
		writer.writeAttribute("id", hiddenInputFieldID, "id");
		writer.writeAttribute("value", "", "value");
		writer.endElement("input");

		// set tab directions
		final String tabPosition = tabView.getTabPosition();
		String wrapperClass = "tab-panel";
		if ("bottom".equalsIgnoreCase(tabPosition))
			wrapperClass += " tabs-below";

		writer.startElement("div", tabView);
		writer.writeAttribute("class", wrapperClass, "class");
		writer.writeAttribute("role", "tabpanel", "class");
		writer.writeAttribute("dir", tabView.getDir(), "dir");

		final List<UIComponent> tabs = getTabs(tabView);

		int activeIndex = forceActiveTabToBeEnabled(tabView, tabs);

		if ("bottom".equalsIgnoreCase(tabPosition)) {
			encodeTabContentPanes(context, writer, tabView, activeIndex, tabs);
			encodeTabLinks(context, writer, tabView, activeIndex, tabs, clientId, hiddenInputFieldID);
		} else if ("left".equalsIgnoreCase(tabPosition)) {
			writer.startElement("div", component);
			writer.writeAttribute("class", "col-md-2", "class");
			encodeTabLinks(context, writer, tabView, activeIndex, tabs, clientId, hiddenInputFieldID);
			writer.endElement("div");
			writer.startElement("div", component);
			writer.writeAttribute("class", "col-md-10", "class");
			encodeTabContentPanes(context, writer, tabView, activeIndex, tabs);
			writer.endElement("div");
			drawClearDiv(writer, tabView);
		} else if ("right".equalsIgnoreCase(tabPosition)) {
			writer.startElement("div", component);
			writer.writeAttribute("class", "col-md-10", "class");
			encodeTabContentPanes(context, writer, tabView, activeIndex, tabs);
			writer.endElement("div");
			writer.startElement("div", component);
			writer.writeAttribute("class", "col-md-2", "class");
			encodeTabLinks(context, writer, tabView, activeIndex, tabs, clientId, hiddenInputFieldID);
			writer.endElement("div");
			drawClearDiv(writer, tabView);
		} else {
			encodeTabLinks(context, writer, tabView, activeIndex, tabs, clientId, hiddenInputFieldID);
			encodeTabContentPanes(context, writer, tabView, activeIndex, tabs);
		}

		writer.endElement("div");
		new AJAXRenderer().generateBootsFacesAJAXAndJavaScriptForJQuery(context, component, writer,
				"#" + clientId + " > li > a[data-toggle=\"tab\"]", null);
		Tooltip.activateTooltips(context, tabView);
	}
600536
public function composeCsv(array $data = [], int $status = 200, array $config = []): SymfonyResponse
    {
        $filename = $config['filename'] ?? 'export';

        $collection = $this->convertToCsvable($data, $config);

        return Response::make($collection->toCsv(), $status, [
            'Content-Type' => 'text/csv',
            'Content-Disposition' => 'attachment; filename="'.$filename.'.csv"',
            'Cache-Control' => 'private',
            'pragma' => 'cache',
        ]);
    }
1305599
public void encode(AsnOutputStream aos) throws EncodeException {

        if (this.originatingTransactionId == null || this.originatingTransactionId.length != 4)
            throw new EncodeException("Error while encoding TCConversationMessage: originatingTransactionId is not defined or has not a length 4");
        if (this.destinationTransactionId == null || this.destinationTransactionId.length != 4)
            throw new EncodeException("Error while encoding TCConversationMessage: destinationTransactionId is not defined or has not a length 4");

        // TODO: should we send a Component without both components and dialogPortion ?
        if ((this.component == null || this.component.length == 0) && this.dp == null)
            throw new EncodeException("Error while encoding TCConversationMessage: neither dialogPortion nor componentPortion is defined");

        try {
            if (this.dialogTermitationPermission)
                aos.writeTag(Tag.CLASS_PRIVATE, false, TCConversationMessage._TAG_CONVERSATION_WITH_PERM);
            else
                aos.writeTag(Tag.CLASS_PRIVATE, false, TCConversationMessage._TAG_CONVERSATION_WITHOUT_PERM);
            int pos = aos.StartContentDefiniteLength();

            byte[] buf = new byte[8];
            System.arraycopy(this.originatingTransactionId, 0, buf, 0, 4);
            System.arraycopy(this.destinationTransactionId, 0, buf, 4, 4);
            aos.writeOctetString(Tag.CLASS_PRIVATE, TCQueryMessage._TAG_TRANSACTION_ID, buf);

            if (this.dp != null)
                this.dp.encode(aos);

            if (component != null && component.length > 0) {
                aos.writeTag(Tag.CLASS_PRIVATE, false, TCQueryMessage._TAG_COMPONENT_SEQUENCE);
                int pos2 = aos.StartContentDefiniteLength();
                for (Component c : this.component) {
                    c.encode(aos);
                }
                aos.FinalizeContent(pos2);
            }

            aos.FinalizeContent(pos);

        } catch (IOException e) {
            throw new EncodeException("IOException while encoding TCConversationMessage: " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new EncodeException("AsnException while encoding TCConversationMessage: " + e.getMessage(), e);
        }
    }
882216
public void encode(AsnOutputStream aos) throws EncodeException {

        try {
            if (this.isInteger()) {
                aos.writeInteger(Tag.CLASS_PRIVATE, ApplicationContext._TAG_INTEGER, integerVal);
            } else if (this.isObjectID()) {
                aos.writeObjectIdentifier(Tag.CLASS_PRIVATE, ApplicationContext._TAG_OBJECT_ID, this.oidVal);
            } else {
                throw new EncodeException("Error while encoding ApplicationContextName: Neither OId nor Integer value is set");
            }

        } catch (IOException e) {
            throw new EncodeException("IOException while encoding ApplicationContextName: " + e.getMessage(), e);
        } catch (AsnException e) {
            throw new EncodeException("AsnException while encoding ApplicationContextName: " + e.getMessage(), e);
        }
    }
536894
public static void writeTSV(Connection connection, String fileName, String tableReference, String encoding) throws SQLException, IOException {       
        TSVDriverFunction tSVDriverFunction = new TSVDriverFunction();
        tSVDriverFunction.exportTable(connection, tableReference, URIUtilities.fileFromString(fileName), new EmptyProgressVisitor(), encoding);
    }
293648
public static void toStream(final HttpConfig config, final OutputStream ostream) {
        toStream(config, ContentTypes.ANY.getAt(0), ostream);
    }
642222
public void write(Configuration config)
    throws IOException {

    pp.startDocument();
    pp.startElement("duke", null);

    // FIXME: here we should write the objects, but that's not
    // possible with the current API. we don't need that for the
    // genetic algorithm at the moment, but it would be useful.

    pp.startElement("schema", null);

    writeElement("threshold", "" + config.getThreshold());
    if (config.getMaybeThreshold() != 0.0)
      writeElement("maybe-threshold", "" + config.getMaybeThreshold());

    for (Property p : config.getProperties())
      writeProperty(p);

    pp.endElement("schema");

    String dbclass = config.getDatabase(false).getClass().getName();
    AttributeListImpl atts = new AttributeListImpl();
    atts.addAttribute("class", "CDATA", dbclass);
    pp.startElement("database", atts);
    pp.endElement("database");

    if (config.isDeduplicationMode())
      for (DataSource src : config.getDataSources())
        writeDataSource(src);
    else {
      pp.startElement("group", null);
      for (DataSource src : config.getDataSources(1))
        writeDataSource(src);
      pp.endElement("group");

      pp.startElement("group", null);
      for (DataSource src : config.getDataSources(2))
        writeDataSource(src);
      pp.endElement("group");
    }

    pp.endElement("duke");
    pp.endDocument();
  }
367792
public byte[] convertToXmlByteArray(BucketTaggingConfiguration config) throws SdkClientException {

        XmlWriter xml = new XmlWriter();
        xml.start("Tagging");

        for (TagSet tagset : config.getAllTagSets()) {
            writeRule(xml, tagset);
        }

        xml.end();

        return xml.getBytes();
    }
127085
public void toStringSegment(final ToString ts) {
   ts.append("sysCode", String.valueOf(getSysCode()));
   ts.append("dtstamp", getDtstamp());
   ts.append("sequence", getSequence());
 }