当前位置: 首页>>代码示例>>Java>>正文


Java RString类代码示例

本文整理汇总了Java中com.ibm.streams.operator.types.RString的典型用法代码示例。如果您正苦于以下问题:Java RString类的具体用法?Java RString怎么用?Java RString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RString类属于com.ibm.streams.operator.types包,在下文中一共展示了RString类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sortAndSubmit

import com.ibm.streams.operator.types.RString; //导入依赖的package包/类
protected void sortAndSubmit(List<File> files) throws Exception {

        if (files.size() > 1) {
            Collections.sort(files, new Comparator<File>() {

                @Override
                public int compare(File o1, File o2) {
                    return Long.compare(o1.lastModified(), o2.lastModified());
                }
            });
        }

        for (File file : files) {
            if (accept(file)) {
                getOutput(0).submitAsTuple(new RString(file.getAbsolutePath()));
                seenFiles.add(file.getName());
            }
        }
    }
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:20,代码来源:DirectoryWatcher.java

示例2: testSPLContentsGood

import com.ibm.streams.operator.types.RString; //导入依赖的package包/类
@Test
public void testSPLContentsGood() throws Exception {
    final Topology topology = new Topology();
    TStream<String> source = topology.strings("A", "B", "C", "D");
    StreamSchema schema = SPLSchemas.STRING.extend("int32", "id");
    SPLStream tested = SPLStreams.convertStream(source, (s,t) -> {t.setString(0, s); t.setInt(1, s.charAt(0)); return t;}, schema);
    
    
    ExpectedTuples expected = new ExpectedTuples(schema);
    int id = "A".charAt(0);
    expected.addAsTuple(new RString("A"), id);
    expected.addAsTuple(new RString("B"), ++id);
    expected.addAsTuple(new RString("C"), ++id);
    expected.addAsTuple(new RString("D"), ++id);

    Condition<List<Tuple>> contents = expected.contents(tested);

    boolean passed = complete(topology.getTester(), contents, 10, TimeUnit.SECONDS);
    assertTrue(contents.toString(), contents.valid());
    assertTrue(passed);
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:22,代码来源:ConditionTest.java

示例3: testSPLContentsBad

import com.ibm.streams.operator.types.RString; //导入依赖的package包/类
@Test
public void testSPLContentsBad() throws Exception {
    final Topology topology = new Topology();
    TStream<String> source = topology.strings("A", "B", "C", "D");
    StreamSchema schema = SPLSchemas.STRING.extend("int32", "id");
    SPLStream tested = SPLStreams.convertStream(source, (s,t) -> {t.setString(0, s); t.setInt(1, s.charAt(0)); return t;}, schema);
    
    
    ExpectedTuples expected = new ExpectedTuples(schema);
    int id = "A".charAt(0);
    expected.addAsTuple(new RString("A"), id);
    expected.addAsTuple(new RString("B"), ++id);
    expected.addAsTuple(new RString("C"), 1241241);
    expected.addAsTuple(new RString("D"), ++id);

    Condition<List<Tuple>> contents = expected.contents(tested);

    boolean passed = complete(topology.getTester(), contents, 10, TimeUnit.SECONDS);
    assertFalse(passed);

    assertFalse(contents.toString(), contents.valid());
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:23,代码来源:ConditionTest.java

示例4: process

import com.ibm.streams.operator.types.RString; //导入依赖的package包/类
@Override
public void process(StreamingInput<Tuple> stream, Tuple tuple)
        throws Exception {

    final StreamingOutput<OutputTuple> out = getOutput(0);

    String fileName = tuple.getString(0);

    File file = new File(fileName);

    if (!file.isAbsolute()) {
        file = new File(getOperatorContext().getPE().getDataDirectory(),
                fileName);
    }

    FileInputStream fis = new FileInputStream(file);
    try {

        BufferedReader br = new BufferedReader(new InputStreamReader(fis,
                charset), 128 * 1024);

        for (;;) {
            String line = br.readLine();
            if (line == null)
                break;
            out.submitAsTuple(new RString(line));
        }
        br.close();

    } finally {
        fis.close();
    }
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:34,代码来源:TextFileReader.java

示例5: convertTo

import com.ibm.streams.operator.types.RString; //导入依赖的package包/类
@Override
public Tuple convertTo(String tuple) {
    if (tuple.isEmpty())
        return getSchema().getTuple();

    return getSchema().getTuple(new Object[] { new RString(tuple) });
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:8,代码来源:StringMapping.java

示例6: process

import com.ibm.streams.operator.types.RString; //导入依赖的package包/类
@Override
public void process(StreamingInput<Tuple> stream, Tuple tuple)
        throws Exception {
    
    String str = tuple.getString(0);
    
    getOutput(0).submitAsTuple(new RString(str));
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:9,代码来源:NoOpJavaPrimitive.java

示例7: convertAttributeToAvro

import com.ibm.streams.operator.types.RString; //导入依赖的package包/类
private static Object convertAttributeToAvro(String attributeName, Object tupleAttribute, Type tupleAttributeType,
		Schema avroSchema) {
	Object returnObject = null;
	MetaType metaType = tupleAttributeType.getMetaType();
	switch (metaType) {
	case BOOLEAN:
		returnObject = (Boolean) tupleAttribute;
		break;
	case FLOAT32:
		returnObject = (Float) tupleAttribute;
		break;
	case FLOAT64:
		returnObject = (Double) tupleAttribute;
		break;
	case INT32:
		returnObject = (Integer) tupleAttribute;
		break;
	case INT64:
		returnObject = (Long) tupleAttribute;
		break;
	case RSTRING:
		returnObject = ((RString) tupleAttribute).getString();
		break;
	case USTRING:
		returnObject = tupleAttribute.toString();
		break;
	case TUPLE:
		Tuple subTuple = (Tuple) tupleAttribute;
		StreamSchema subStreamSchema = subTuple.getStreamSchema();
		GenericRecord subDatum = convertTupleToAvro(subTuple, subStreamSchema, avroSchema);
		// Return the Avro record
		returnObject = subDatum;
		break;
	case LIST:
		@SuppressWarnings("unchecked")
		List<Object> subList = (List<Object>) tupleAttribute;
		// Obtain the type of the elements contained in the Streams list
		Type tupleElementType = ((CollectionType) tupleAttributeType).getElementType();
		// Obtain the type of the elements contained in the Avro array
		Schema avroArrayElementType = avroSchema.getElementType();
		// Now loop through all list elements and populate the associated
		// Avro array elements
		GenericArray<Object> subArray = new GenericData.Array<Object>(subList.size(), avroSchema);
		for (Object arrayElement : subList) {
			Object avroElement = convertAttributeToAvro(attributeName, arrayElement, tupleElementType,
					avroArrayElementType);
			subArray.add(avroElement);
		}
		// Return the Avro array
		returnObject = subArray;
		break;
	default:
		LOGGER.log(TraceLevel.WARN,
				"Ignoring attribute " + attributeName + " because of unsupported type " + metaType);
	}
	return returnObject;
}
 
开发者ID:IBMStreams,项目名称:streamsx.avro,代码行数:58,代码来源:TupleToAvroConverter.java

示例8: writeTuple

import com.ibm.streams.operator.types.RString; //导入依赖的package包/类
public void writeTuple(Tuple tuple) throws Exception {
	if (fWriter == null) {
		if (MetaType.BLOB == attrType) {
			initWriter(true, isAppend);
		}
		else {
			initWriter(false, isAppend);
		}
	}
	
	byte[] tupleBytes = null;
	
	switch (attrType) {
	case BLOB: 
		ByteBuffer buffer = tuple.getBlob(attrIndex).getByteBuffer();
		tupleBytes = new byte[buffer.limit()];
		buffer.get(tupleBytes);
		break;
	case RSTRING:
		Object attrObj = tuple.getObject(attrIndex);
		if (fEncoding.equals(UTF_8))
		{
			tupleBytes = ((RString)attrObj).getData();
		}
		else
		{
			tupleBytes = ((RString)attrObj).getData();
			tupleBytes = new String(tupleBytes, UTF_8).getBytes(fEncoding);
		}
		break;
	case USTRING:
		String attrString = tuple.getString(attrIndex);
		tupleBytes = attrString.getBytes(fEncoding);
		break;
	default:
		throw new Exception("Unsupported type "+attrType);
	}
	
	fWriter.write(tupleBytes);

	numTuples++;
	long tupleSize=tupleBytes.length;
	size += tupleSize+fNewLine.length;
	
	// check expiration after write, so the next write
	// will create a new file
	// check expiration after write, so the next write
	// will create a new file				
	if (expPolicy != EnumFileExpirationPolicy.NEVER)
	{
		switch (expPolicy) {
		case TUPLECNT:
			tupleCnt++;
			if (tupleCnt >= tuplesPerFile) {
				setExpired();
			}
			break;
		case SIZE:
			if((sizePerFile-size)<tupleSize)
			{
				setExpired();
			}
			break;			
		default:
			break;
		}
	}
}
 
开发者ID:IBMStreams,项目名称:streamsx.hdfs,代码行数:69,代码来源:HdfsFile.java

示例9: addAsTuple

import com.ibm.streams.operator.types.RString; //导入依赖的package包/类
/**
 * Add a tuple to expected list.
 * Equivalent to:
 * {@code add(getSchema().getTuple(values))}
 * with the exception that if an attribute is
 * of type {@code rstring} then a String object may be used.
 * <P>
 * Calls can be chained together to add multiple tuples.
 * For example with a schema of {@code tuple<rstring id, int32 value>}
 * this may be used to add two tuples:
 * <pre>
 * <code>
 * ExpectedTuples expected = new ExpectedTuples(schema);
 * 
 * expected.addAsTuple("a21", 33).addAsTuple("c43", 932);
 * </code>
 * </pre>
 * </P>

 * @param values Attribute values for the tuple.
 * @return This.
 */
public ExpectedTuples addAsTuple(Object ...values) {
    for (int i = 0; i < values.length; i++) {
        if (getSchema().getAttribute(i).getType().getMetaType() == MetaType.RSTRING) {
            if (values[i] instanceof String)
                values[i] = new RString(values[i].toString());
        }
    }
    return add(getSchema().getTuple(values));
}
 
开发者ID:IBMStreams,项目名称:streamsx.topology,代码行数:32,代码来源:ExpectedTuples.java


注:本文中的com.ibm.streams.operator.types.RString类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。