List of usage examples for org.apache.commons.io IOUtils toInputStream
public static InputStream toInputStream(String input)
From source file:com.msopentech.odatajclient.proxy.MediaEntityTestITCase.java
@Test public void create() throws IOException { Car car = container.getCar().newCar(); final String TO_BE_UPDATED = "buffered stream sample (" + System.currentTimeMillis() + ")"; InputStream input = IOUtils.toInputStream(TO_BE_UPDATED); final String DESC = "DESC - " + System.currentTimeMillis(); car.setStream(input);// w w w . j av a 2 s .c om car.setDescription(DESC); container.flush(); int key = car.getVIN(); assertTrue(key > 0); EntityContainerFactory.getContext().detachAll(); car = container.getCar().get(key); assertEquals(DESC, car.getDescription()); input = car.getStream(); assertEquals(TO_BE_UPDATED, IOUtils.toString(input)); IOUtils.closeQuietly(input); container.getCar().delete(key); container.flush(); assertNull(container.getCar().get(key)); }
From source file:mitm.common.util.NameValueLineIteratorTest.java
@Test public void testNameValueLineIteratorCRLF() throws IOException { String data = "test=123\r\n test = 456 \r\n test=\r\ntest2"; NameValueLineIterator.Entry entry;/* www . ja va2s . c om*/ Iterator<NameValueLineIterator.Entry> it = new NameValueLineIterator(IOUtils.toInputStream(data)); assertTrue(it.hasNext()); entry = it.next(); assertEquals("test", entry.getName()); assertEquals("123", entry.getValue()); assertTrue(it.hasNext()); entry = it.next(); assertEquals("test", entry.getName()); assertEquals("456", entry.getValue()); assertTrue(it.hasNext()); entry = it.next(); assertEquals("test", entry.getName()); assertEquals("", entry.getValue()); assertFalse(it.hasNext()); }
From source file:info.magnolia.ui.form.field.transformer.multi.MultiValueChildrenNodeTransformerTest.java
@Override @Before//w w w . j a v a2 s.co m public void setUp() throws Exception { super.setUp(); // Init parent Node String nodeProperties = "/parent.@type=mgnl:content\n" + "/parent.propertyString=hello\n" + "/parent/00.@type=mgnl:content\n" + "/parent/00.property=value1\n" + "/parent/11.@type=mgnl:content\n" + "/parent/11.property=value2\n"; Session session = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE); new PropertiesImportExport().createNodes(session.getRootNode(), IOUtils.toInputStream(nodeProperties)); session.save(); definition.setName(propertyName); rootNode = session.getRootNode().getNode("parent"); }
From source file:com.norconex.collector.http.robot.impl.StandardRobotsTxtProviderTest.java
private IReferenceFilter[] parseRobotRule(String agent, String content, String url) throws IOException { StandardRobotsTxtProvider robotProvider = new StandardRobotsTxtProvider(); return robotProvider.parseRobotsTxt(IOUtils.toInputStream(content), url, "mister-crawler").getFilters(); }
From source file:com.receipts.services.ExportService.java
public InputStream createExportFile(Store store) { InputStream is = null;/*from w ww . j ava 2s .co m*/ String storeId = store.getStoreId(); String storeIdStr = StringUtils.leftPad(storeId, 3, "0"); Date storeDate = store.getStoreDate(); SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); String storeDateStr = sdf.format(storeDate); DecimalFormatSymbols dfs = new DecimalFormatSymbols(); dfs.setDecimalSeparator('.'); StringBuilder sb = new StringBuilder(); for (Receipt receipt : store.getReceipts()) { if (receipt.isComplete()) { String receiptId = receipt.getId().toString(); String receiptTime = receipt.getReceiptTime(); for (Product product : receipt.getProducts()) { // Store Id: 3 chars storeIdStr = StringUtils.substring(storeIdStr, 0, 3); sb.append(storeIdStr); // Product Name: 32 chars String productName = StringUtils.substring(product.getProductName(), 0, 32); String productNameStr = StringUtils.rightPad(productName, 32); sb.append(productNameStr); String productPrice = new DecimalFormat("0000.00", dfs).format(product.getProductPrice()); String productPriceStr = StringUtils.leftPad(productPrice, 7, "0"); sb.append(productPriceStr); // Receipt Id: 10 chars String receiptIdStr = StringUtils.leftPad(StringUtils.substring(receiptId, 0, 10), 10); sb.append(receiptIdStr); sb.append(storeDateStr); sb.append(receiptTime); String productQuantity = new DecimalFormat("#0.000", dfs).format(product.getProductQuantity()); String productQuantityStr = StringUtils.leftPad(productQuantity, 6, "0"); sb.append(productQuantityStr); sb.append(System.getProperty("line.separator")); } } } is = IOUtils.toInputStream(sb.toString()); return is; }
From source file:io.ingenieux.lambada.invoker.InvokerTestBase.java
public void withInput(String string) throws Exception { this.inputStream = IOUtils.toInputStream(string); }
From source file:info.magnolia.ui.form.field.transformer.composite.CompositeTransformerTest.java
@Override @Before/*w w w . ja v a2 s . com*/ public void setUp() throws Exception { super.setUp(); // Init parent Node String nodeProperties = "/parent.@type=mgnl:content\n" + "/parent.fieldNamefield2=hello2\n"; Session session = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE); new PropertiesImportExport().createNodes(session.getRootNode(), IOUtils.toInputStream(nodeProperties)); session.save(); definition.setName(fieldName); rootNode = session.getRootNode().getNode("parent"); parent = new JcrNodeAdapter(rootNode); delegate = new CompositeTransformer(parent, definition, PropertysetItem.class, fieldsName, mock(I18NAuthoringSupport.class)); }
From source file:info.magnolia.ui.form.field.transformer.multi.MultiValueJSONTransformerTest.java
@Override @Before//from w w w . ja va 2 s . c o m public void setUp() throws Exception { super.setUp(); // Init parent Node String nodeProperties = "/parent.@type=mgnl:content\n" + "/parent.propertyString=hello\n" + "/parent/child.@type=mgnl:content\n" + "/parent/child.propertyString=chield1\n"; ComponentsTestUtil.setInstance(I18NAuthoringSupport.class, mock(I18NAuthoringSupport.class)); Session session = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE); new PropertiesImportExport().createNodes(session.getRootNode(), IOUtils.toInputStream(nodeProperties)); session.save(); definition.setName(propertyName); rootNode = session.getRootNode().getNode("parent"); }
From source file:baggage.guerilla.GuerillaParserTest.java
public void testClosingTag() throws Exception { String snippet = "<b>foo</b>"; GuerillaParser parser = new GuerillaParser(IOUtils.toInputStream(snippet)); OpeningTag openingTag = (OpeningTag) parser.next(true); TextItem textItem = (TextItem) parser.next(false); assertEquals("foo", textItem.getStringValue()); ClosingTag closingTag = (ClosingTag) parser.next(false); assertEquals("b", closingTag.getStringValue()); }
From source file:edu.brandeis.cs.nlp.mae.io.DTDLoader.java
public boolean read(String string) throws MaeIODTDException, MaeDBException { logger.debug("reading annotation scheme from plain JAVA string"); return this.read(IOUtils.toInputStream(string)); }