Java Code Examples for org.apache.commons.io.IOUtils

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.

Source file: HttpGetter.java

  33 
vote

public String execute() throws ClientProtocolException, IOException {
  if (response == null) {
    HttpClient httpClient=HttpClientSingleton.getInstance();
    HttpResponse serverresponse=null;
    serverresponse=httpClient.execute(httpget);
    HttpEntity entity=serverresponse.getEntity();
    StringWriter writer=new StringWriter();
    IOUtils.copy(entity.getContent(),writer);
    response=writer.toString();
  }
  return response;
}
 

Example 2

From project and-bible, under directory /ReadingPlanCreator/src/org/andbible/util/readingplan/.

Source file: Start.java

  30 
vote

public static void main(String[] args){
  try {
    File[] files=new File("in").listFiles();
    for (    File file : files) {
      String in=IOUtils.toString(new FileInputStream(file));
      in=new RemoveLineStart().filter(in);
      in=new RemoveEmptyLines().filter(in);
      in=new AddDayNumbers().filter(in);
      in=new CompressBookNames().filter(in);
      in=in.replace(" - ",", ").replace(" -- ",", ");
      IOUtils.write(in,new FileOutputStream("out/" + file.getName().replace(".txt",".properties")));
    }
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 3

From project Activiti-KickStart, under directory /activiti-kickstart-java/src/main/java/org/activiti/kickstart/service/alfresco/.

Source file: AlfrescoKickstartServiceImpl.java

  29 
vote

protected String readTemplateFile(String templateFile){
  LOGGER.info("Reading template file '" + templateFile + "'");
  InputStream inputStream=AlfrescoKickstartServiceImpl.class.getResourceAsStream(templateFile);
  if (inputStream == null) {
    LOGGER.warning("Could not read template file '" + templateFile + "'!");
  }
 else {
    try {
      return IOUtils.toString(inputStream);
    }
 catch (    IOException e) {
      LOGGER.log(Level.SEVERE,"Error while reading '" + templateFile + "' : "+ e.getMessage());
    }
  }
  return null;
}
 

Example 4

From project agit, under directory /agit/src/main/java/com/madgag/agit/.

Source file: MarkdownActivityBase.java

  29 
vote

private String loadMarkdown(){
  String markdown;
  String fileName=markdownFile();
  try {
    markdown=IOUtils.toString(getAssets().open(fileName));
  }
 catch (  Exception e) {
    markdown="Problem loading '" + fileName + "'.";
    Log.e(TAG,markdown,e);
  }
  return markdown;
}
 

Example 5

From project Aion-Extreme, under directory /AE-go_GameServer/src/com/aionemu/gameserver/dataholders/loadingutils/.

Source file: XmlMerger.java

  29 
vote

private Properties restoreFileModifications(File file){
  if (!file.exists() || !file.isFile())   return null;
  FileReader reader=null;
  try {
    Properties props=new Properties();
    reader=new FileReader(file);
    props.load(reader);
    return props;
  }
 catch (  IOException e) {
    logger.debug("File modfications restoring error. ",e);
    return null;
  }
 finally {
    IOUtils.closeQuietly(reader);
  }
}
 

Example 6

From project akubra, under directory /akubra-core/src/main/java/org/akubraproject/impl/.

Source file: AbstractBlobStoreConnection.java

  29 
vote

@Override public Blob getBlob(InputStream content,long estimatedSize,Map<String,String> hints) throws IOException, UnsupportedOperationException {
  Blob blob=getBlob(null,hints);
  boolean success=false;
  try {
    OutputStream out=blob.openOutputStream(estimatedSize,true);
    try {
      IOUtils.copyLarge(content,out);
      out.close();
      out=null;
    }
  finally {
      if (out != null)       IOUtils.closeQuietly(out);
    }
    success=true;
  }
  finally {
    if (!success) {
      try {
        blob.delete();
      }
 catch (      Throwable t) {
        log.error("Error deleting blob after blob-creation failure",t);
      }
    }
  }
  return blob;
}
 

Example 7

From project android-bankdroid, under directory /src/com/liato/bankdroid/banking/.

Source file: Bank.java

  29 
vote

public SessionPackage getSessionPackage(Context context){
  String preloader="Error...";
  try {
    preloader=IOUtils.toString(context.getResources().openRawResource(R.raw.loading));
  }
 catch (  NotFoundException e1) {
    e1.printStackTrace();
  }
catch (  IOException e1) {
    e1.printStackTrace();
  }
  try {
    LoginPackage lp=preLogin();
    if (lp == null) {
      throw new BankException("No automatic login for this bank. preLogin() is not implemented or has failed.");
    }
    String html=String.format(preloader,"function go(){document.getElementById('submitform').submit(); }",Helpers.renderForm(lp.getLoginTarget(),lp.getPostData()) + "<script type=\"text/javascript\">setTimeout('go()', 1000);</script>");
    CookieStore cookies=urlopen.getHttpclient().getCookieStore();
    return new SessionPackage(html,cookies);
  }
 catch (  ClientProtocolException e) {
    Log.e(TAG,e.getMessage());
  }
catch (  IOException e) {
    Log.e(TAG,e.getMessage());
  }
catch (  BankException e) {
    Log.e(TAG,e.getMessage());
  }
  String html=String.format(preloader,String.format("function go(){window.location=\"%s\" }",this.URL),"<script type=\"text/javascript\">setTimeout('go()', 1000);</script>");
  return new SessionPackage(html,null);
}
 

Example 8

From project api-sdk-java, under directory /api-sdk/src/main/java/com/smartling/api/sdk/file/.

Source file: FileApiClientAdapterImpl.java

  29 
vote

private StringResponse inputStreamToString(InputStream inputStream,String encoding) throws FileApiException {
  StringWriter writer=new StringWriter();
  try {
    String responseEncoding=(null == encoding || !encoding.toUpperCase().contains(UTF_16) ? DEFAULT_ENCODING : UTF_16);
    IOUtils.copy(inputStream,writer,responseEncoding);
    return new StringResponse(writer.toString(),responseEncoding);
  }
 catch (  IOException e) {
    throw new FileApiException(e);
  }
}
 

Example 9

From project Arecibo, under directory /alert-data-support/src/test/java/com/ning/arecibo/alert/confdata/dao/.

Source file: TestConfDataDAO.java

  29 
vote

@BeforeMethod(alwaysRun=true) public void setUp() throws Exception {
  final String ddl=IOUtils.toString(MysqlTestingHelper.class.getResourceAsStream("/com/ning/arecibo/alert/confdata/create_alert_config_tables.sql"));
  helper.startMysql();
  helper.initDb(ddl);
  dao=dbi.onDemand(ConfDataQueries.class);
  confDataDAO=new ConfDataDAO(dbi);
}
 

Example 10

From project arquillian-extension-drone, under directory /drone-webdriver/src/test/java/org/jboss/arquillian/drone/webdriver/factory/remote/reusable/ftest/.

Source file: TestReusableRemoteWebDriver.java

  29 
vote

@SuppressWarnings("unchecked") private <T>T serializeDeserialize(T object){
  ByteArrayOutputStream baos=new ByteArrayOutputStream();
  ObjectOutputStream out=null;
  try {
    out=new ObjectOutputStream(baos);
    out.writeObject(object);
  }
 catch (  IOException ex) {
    throw new IllegalStateException(ex);
  }
 finally {
    IOUtils.closeQuietly(out);
  }
  ByteArrayInputStream bais=new ByteArrayInputStream(baos.toByteArray());
  ObjectInputStream in=null;
  try {
    in=new ObjectInputStream(bais);
    return (T)object.getClass().cast(in.readObject());
  }
 catch (  IOException ex) {
    throw new IllegalStateException(ex);
  }
catch (  ClassNotFoundException ex) {
    throw new IllegalStateException(ex);
  }
 finally {
    IOUtils.closeQuietly(in);
  }
}
 

Example 11

From project arquillian-graphene, under directory /graphene-selenium/graphene-selenium-impl/src/main/java/org/jboss/arquillian/ajocado/framework/.

Source file: GrapheneSeleniumImpl.java

  29 
vote

/** 
 * Loads the list of resource names from the given resource.
 * @param resourceName the path to resource on classpath
 * @return the list of resource names from the given resource.
 */
@SuppressWarnings("unchecked") protected static List<String> getExtensionsListFromResource(String resourceName){
  try {
    return IOUtils.readLines(ClassLoader.getSystemResourceAsStream(resourceName));
  }
 catch (  IOException e) {
    throw new IllegalStateException(e);
  }
}
 

Example 12

From project arquillian_deprecated, under directory /extensions/drone/src/main/java/org/jboss/arquillian/drone/factory/.

Source file: AjocadoFactory.java

  29 
vote

@SuppressWarnings("unchecked") private List<String> getExtensionsListFromResource(String resourceName){
  try {
    return IOUtils.readLines(ClassLoader.getSystemResourceAsStream(resourceName));
  }
 catch (  IOException e) {
    throw new IllegalStateException(e);
  }
}
 

Example 13

From project artifactory-plugin, under directory /src/main/java/org/jfrog/hudson/generic/.

Source file: DependenciesDownloaderImpl.java

  29 
vote

public Map<String,String> saveDownloadedFile(InputStream is,String filePath) throws IOException {
  try {
    FilePath child=workspace.child(filePath);
    child.copyFrom(is);
    return child.act(new DownloadFileCallable(log));
  }
 catch (  InterruptedException e) {
    log.warn("Caught interrupted exception: " + e.getLocalizedMessage());
  }
 finally {
    IOUtils.closeQuietly(is);
  }
  return null;
}
 

Example 14

From project aws-toolkit-for-eclipse, under directory /com.amazonaws.eclipse.elasticbeanstalk/src/com/amazonaws/eclipse/elasticbeanstalk/webproject/.

Source file: CreateNewAwsJavaWebProjectRunnable.java

  29 
vote

private void unzipSampleAppTemplate(File file,File destination) throws FileNotFoundException, IOException {
  ZipInputStream zipInputStream=new ZipInputStream(new FileInputStream(file));
  ZipEntry zipEntry=null;
  while ((zipEntry=zipInputStream.getNextEntry()) != null) {
    IPath path=new Path(zipEntry.getName());
    path=path.removeFirstSegments(1);
    File destinationFile=new File(destination,path.toOSString());
    if (zipEntry.isDirectory()) {
      destinationFile.mkdirs();
    }
 else {
      FileOutputStream outputStream=new FileOutputStream(destinationFile);
      IOUtils.copy(zipInputStream,outputStream);
      outputStream.close();
    }
  }
  zipInputStream.close();
}
 

Example 15

From project Axon-trader, under directory /external-listeners/src/main/java/org/axonframework/samples/trader/listener/.

Source file: OrderbookExternalListener.java

  29 
vote

private void doHandle(TradeExecutedEvent event) throws IOException {
  String jsonObjectAsString=createJsonInString(event);
  HttpPost post=new HttpPost(remoteServerUri);
  post.setEntity(new StringEntity(jsonObjectAsString));
  post.addHeader("Content-Type","application/json");
  HttpClient client=new DefaultHttpClient();
  HttpResponse response=client.execute(post);
  if (response.getStatusLine().getStatusCode() != 200) {
    Writer writer=new StringWriter();
    IOUtils.copy(response.getEntity().getContent(),writer);
    logger.warn("Error while sending event to external system: {}",writer.toString());
  }
}
 

Example 16

From project azkaban, under directory /azkaban/src/java/azkaban/flow/.

Source file: ImmutableFlowManager.java

  29 
vote

@Override public FlowExecutionHolder saveExecutableFlow(FlowExecutionHolder holder){
  File storageFile=new File(storageDirectory,String.format("%s.json",holder.getFlow().getId()));
  JSONObject jsonObj=new JSONObject(serializer.apply(holder));
  BufferedWriter out=null;
  try {
    out=new BufferedWriter(new FileWriter(storageFile));
    out.write(jsonObj.toString(2));
    out.flush();
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
 finally {
    IOUtils.closeQuietly(out);
  }
  return holder;
}
 

Example 17

From project b3log-latke, under directory /latke/src/main/java/org/b3log/latke/repository/.

Source file: Repositories.java

  29 
vote

/** 
 * Loads repository description.
 */
private static void loadRepositoryDescription(){
  LOGGER.log(Level.INFO,"Loading repository description....");
  final InputStream inputStream=AbstractRepository.class.getClassLoader().getResourceAsStream("repository.json");
  if (null == inputStream) {
    LOGGER.log(Level.INFO,"Not found repository description[repository.json] file under classpath");
    return;
  }
  LOGGER.log(Level.INFO,"Parsing repository description....");
  try {
    final String description=IOUtils.toString(inputStream);
    LOGGER.log(Level.CONFIG,"{0}{1}",new Object[]{Strings.LINE_SEPARATOR,description});
    repositoriesDescription=new JSONObject(description);
    final String tableNamePrefix=StringUtils.isNotBlank(Latkes.getLocalProperty("jdbc.tablePrefix")) ? Latkes.getLocalProperty("jdbc.tablePrefix") + "_" : "";
    final JSONArray repositories=repositoriesDescription.optJSONArray("repositories");
    for (int i=0; i < repositories.length(); i++) {
      final JSONObject repository=repositories.optJSONObject(i);
      repository.put("name",tableNamePrefix + repository.optString("name"));
    }
  }
 catch (  final Exception e) {
    LOGGER.log(Level.SEVERE,"Parses repository description failed",e);
  }
 finally {
    try {
      inputStream.close();
    }
 catch (    final IOException e) {
      LOGGER.log(Level.SEVERE,e.getMessage(),e);
      throw new RuntimeException(e);
    }
  }
}
 

Example 18

From project b3log-solo, under directory /core/src/test/java/org/b3log/solo/util/.

Source file: MarkdownsTestCase.java

  29 
vote

/** 
 * Test method for  {@linkplain Markdowns#toHTML(java.lang.String)}.
 * @throws Exception exception
 */
@Test public void toHTML() throws Exception {
  String markdownText="";
  String html=Markdowns.toHTML(markdownText);
  Assert.assertNull(html);
  markdownText="# B3log Solo Markdown Editor";
  html=Markdowns.toHTML(markdownText);
  System.out.println(html);
  System.out.println(MarkdownsTestCase.class.getResource("/"));
  final URL testFile=MarkdownsTestCase.class.getResource("/markdown_syntax.text");
  System.out.println(testFile.getFile());
  final StringBuilder markdownTextBuilder=new StringBuilder();
  @SuppressWarnings("unchecked") final List<String> lines=IOUtils.readLines(new FileInputStream(testFile.getFile()));
  for (  final String line : lines) {
    markdownTextBuilder.append(line).append(Strings.LINE_SEPARATOR);
  }
  markdownText=markdownTextBuilder.toString();
  System.out.println(markdownText);
  Stopwatchs.start("Markdowning");
  html=Markdowns.toHTML(markdownText);
  Stopwatchs.end();
  System.out.println(html);
  System.out.println("Stopwatch: ");
  System.out.println(Stopwatchs.getTimingStat());
}
 

Example 19

From project baseunits, under directory /src/test/java/jp/xet/baseunits/tests/.

Source file: SerializationTester.java

  29 
vote

/** 
 * ????€?????????????????????
 * @param serializable ????€????????????????
 * @throws AssertionError ????€??????????????
 */
public static void assertCanBeSerialized(Object serializable){
  if (Serializable.class.isInstance(serializable) == false) {
    fail("Object doesn't implement java.io.Serializable interface: " + serializable.getClass());
  }
  ObjectOutputStream out=null;
  ObjectInputStream in=null;
  ByteArrayOutputStream byteArrayOut=new ByteArrayOutputStream();
  ByteArrayInputStream byteArrayIn=null;
  try {
    out=new ObjectOutputStream(byteArrayOut);
    out.writeObject(serializable);
    byteArrayIn=new ByteArrayInputStream(byteArrayOut.toByteArray());
    in=new ObjectInputStream(byteArrayIn);
    Object deserialized=in.readObject();
    if (serializable.equals(deserialized) == false) {
      fail("Reconstituted object is expected to be equal to serialized");
    }
  }
 catch (  IOException e) {
    fail(e.getMessage());
  }
catch (  ClassNotFoundException e) {
    fail(e.getMessage());
  }
 finally {
    IOUtils.closeQuietly(out);
    IOUtils.closeQuietly(in);
  }
}
 

Example 20

From project beanstalker, under directory /beanstalk-maven-plugin/src/main/java/br/com/ingenieux/mojo/beanstalk/config/.

Source file: DescribeConfigurationTemplatesMojo.java

  29 
vote

void describeConfigurationTemplate(String configTemplateName){
  DescribeConfigurationSettingsRequest req=new DescribeConfigurationSettingsRequest().withApplicationName(applicationName).withTemplateName(configTemplateName);
  DescribeConfigurationSettingsResult configSettings=getService().describeConfigurationSettings(req);
  List<String> buf=new ArrayList<String>();
  buf.add("<optionSettings>");
  for (  ConfigurationSettingsDescription configSetting : configSettings.getConfigurationSettings()) {
    for (    ConfigurationOptionSetting setting : configSetting.getOptionSettings()) {
      buf.add("  <optionSetting>");
      buf.add(String.format("    <%s>%s</%1$s>","namespace",setting.getNamespace()));
      buf.add(String.format("    <%s>%s</%1$s>","optionName",setting.getOptionName()));
      buf.add(String.format("    <%s>%s</%1$s>","value",setting.getValue()));
      buf.add("  </optionSetting>");
    }
  }
  buf.add("</optionSettings>");
  if (null != outputFile) {
    getLog().info("Dumping results to file: " + outputFile.getName());
    String bufChars=StringUtils.join(buf.iterator(),ENDL);
    FileWriter writer=null;
    try {
      writer=new FileWriter(outputFile);
      IOUtils.copy(new StringReader(bufChars),writer);
    }
 catch (    IOException e) {
      throw new RuntimeException("Failure when writing to file: " + outputFile.getName(),e);
    }
 finally {
      IOUtils.closeQuietly(writer);
    }
  }
 else {
    getLog().info("Dumping results to stdout");
    for (    String e : buf)     getLog().info(e);
  }
}
 

Example 21

From project behemoth, under directory /language-id/src/main/java/com/digitalpebble/behemoth/languageidentification/.

Source file: LanguageIdProcessor.java

  29 
vote

private static String loadLanguageProfile(String langCode) throws IOException {
  InputStream is=DetectorFactory.class.getClassLoader().getResourceAsStream("profiles/" + langCode);
  String profile=IOUtils.toString(is);
  is.close();
  return profile;
}
 

Example 22

From project bioportal-service, under directory /src/test/java/edu/mayo/cts2/framework/plugin/service/bioportal/service/transform/.

Source file: AssociationTransformTest.java

  29 
vote

@Before public void buildTransform() throws Exception {
  this.associationTransform=new AssociationTransform();
  IdentityConverter idConverter=EasyMock.createMock(IdentityConverter.class);
  UrlConstructor urlConstructor=EasyMock.createNiceMock(UrlConstructor.class);
  EasyMock.expect(idConverter.ontologyIdToCodeSystemName("1104")).andReturn("testCsName").anyTimes();
  EasyMock.expect(idConverter.ontologyVersionIdToCodeSystemVersionName("1104","44450")).andReturn("testCsVersionName").anyTimes();
  EasyMock.expect(idConverter.getCodeSystemAbout("csName","http://purl.bioontology.org/ontology/")).andReturn("http://test.doc.uri").anyTimes();
  EasyMock.expect(idConverter.getCodeSystemAbout("ICD10","http://purl.bioontology.org/ontology/")).andReturn("http://test.doc.uri").anyTimes();
  EasyMock.expect(idConverter.codeSystemVersionNameToVersion("ICD10")).andReturn("ICD10").anyTimes();
  EasyMock.replay(idConverter,urlConstructor);
  this.associationTransform.setIdentityConverter(idConverter);
  this.associationTransform.setUrlConstructor(urlConstructor);
  Resource resource=new ClassPathResource("bioportalXml/entityDescription.xml");
  StringWriter sw=new StringWriter();
  IOUtils.copy(resource.getInputStream(),sw);
  this.xml=sw.toString();
}
 

Example 23

From project Blister, under directory /code/modules/src/test/java/uk/co/sromo/blister/.

Source file: TestBPItems.java

  29 
vote

@Test public void TestReadingBinaryUnicode() throws IOException, BinaryPlistException {
  InputStream stream=TestBPItems.class.getResourceAsStream("/BinaryUnicode.plist");
  byte[] bytes=IOUtils.toByteArray(stream);
  BPItem root=BinaryPlist.decode(bytes);
  Assert.assertEquals("Not a dictionary",BPItem.Type.Dict,root.getType());
  BPDict newDict=(BPDict)root;
  Assert.assertEquals("New ascii lookup failed",ASCII_STRING_1,newDict.get(ASCII_STRING_2,"FAIL"));
  Assert.assertEquals("New unicode lookup failed",UNICODE_STRING_1,newDict.get(UNICODE_STRING_2,"FAIL"));
}
 

Example 24

From project bpelunit, under directory /net.bpelunit.framework/src/main/java/net/bpelunit/framework/control/deploy/ode/.

Source file: ODEDeployment.java

  29 
vote

private void addWSDL(String wsdlPath) throws ArchiveFileException {
  java.io.File wsdl=new java.io.File(wsdlPath);
  fLogger.info("CoverageTool: Adding WSDL-file " + wsdl.getPath() + " for CoverageLogging in ode-archive");
  FileOutputStream out=null;
  try {
    out=new FileOutputStream(getArchive() + File.separator + FilenameUtils.getName(wsdl.getAbsolutePath()));
    out.write(FileUtils.readFileToByteArray(wsdl));
    fLogger.info("CoverageTool: WSDL-file sucessfull added.");
  }
 catch (  IOException e) {
    throw new ArchiveFileException("Could not add WSDL file for coverage measurement tool (" + wsdl.getName() + ") in deployment archive ",e);
  }
 finally {
    IOUtils.closeQuietly(out);
  }
}
 

Example 25

From project brut.apktool, under directory /apktool-lib/src/main/java/brut/androlib/res/.

Source file: AndrolibResources.java

  29 
vote

public boolean detectWhetherAppIsFramework(File appDir) throws AndrolibException {
  File publicXml=new File(appDir,"res/values/public.xml");
  if (!publicXml.exists()) {
    return false;
  }
  Iterator<String> it;
  try {
    it=IOUtils.lineIterator(new FileReader(new File(appDir,"res/values/public.xml")));
  }
 catch (  FileNotFoundException ex) {
    throw new AndrolibException("Could not detect whether app is framework one",ex);
  }
  it.next();
  it.next();
  return it.next().contains("0x01");
}
 

Example 26

From project build-info, under directory /build-info-client/src/main/java/org/jfrog/build/client/.

Source file: ArtifactoryDependenciesClient.java

  29 
vote

/** 
 * Reads HTTP response and converts it to object of the type specified.
 * @param response     response to read
 * @param valueType    response object type
 * @param errorMessage error message to throw in case of error
 * @param < T >          response object type
 * @return response object converted from HTTP Json reponse to the type specified.
 * @throws java.io.IOException if reading or converting response fails.
 */
private <T>T readResponse(HttpResponse response,TypeReference<T> valueType,String errorMessage) throws IOException {
  if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    HttpEntity entity=response.getEntity();
    if (entity == null) {
      return null;
    }
    InputStream content=null;
    try {
      content=entity.getContent();
      JsonParser parser=httpClient.createJsonParser(content);
      return parser.readValueAs(valueType);
    }
  finally {
      if (content != null) {
        IOUtils.closeQuietly(content);
      }
    }
  }
 else {
    HttpEntity httpEntity=response.getEntity();
    if (httpEntity != null) {
      IOUtils.closeQuietly(httpEntity.getContent());
    }
    throw new IOException(errorMessage + ": " + response.getStatusLine());
  }
}
 

Example 27

From project CalendarPortlet, under directory /src/main/java/org/jasig/portlet/calendar/adapter/.

Source file: ConfigurableFileCalendarAdapter.java

  29 
vote

protected InputStream retrieveCalendar(String fileName) throws CalendarException {
  if (log.isDebugEnabled()) {
    log.debug("Retrieving calendar " + fileName);
  }
  try {
    InputStream in=new FileInputStream(fileName);
    ByteArrayOutputStream buffer=new ByteArrayOutputStream();
    IOUtils.copyLarge(in,buffer);
    return new ByteArrayInputStream(buffer.toByteArray());
  }
 catch (  HttpException e) {
    log.warn("Error fetching iCalendar feed",e);
    throw new CalendarException("Error fetching iCalendar feed",e);
  }
catch (  IOException e) {
    log.warn("Error fetching iCalendar feed",e);
    throw new CalendarException("Error fetching iCalendar feed",e);
  }
 finally {
  }
}
 

Example 28

From project CampusLifePortlets, under directory /src/main/java/org/jasig/portlet/campuslife/dao/.

Source file: ScreenScrapingService.java

  29 
vote

/** 
 * Get HTML content for the specified dining hall.
 * @param diningHall
 * @return
 * @throws ClientProtocolException
 * @throws IOException
 */
protected String getHtmlContent(String url) throws ClientProtocolException, IOException {
  final DefaultHttpClient httpclient=new DefaultHttpClient();
  final HttpGet httpget=new HttpGet(url);
  final HttpResponse response=httpclient.execute(httpget);
  final InputStream httpStream=response.getEntity().getContent();
  final String content=IOUtils.toString(httpStream);
  return content;
}
 

Example 29

From project candlepin, under directory /src/main/java/org/candlepin/servlet/filter/logging/.

Source file: LoggingRequestWrapper.java

  29 
vote

public LoggingRequestWrapper(HttpServletRequest request) throws IOException {
  super(request);
  InputStream inputStream=request.getInputStream();
  if (inputStream != null) {
    body=IOUtils.toByteArray(inputStream);
  }
 else {
    body=new byte[0];
  }
}
 

Example 30

From project Carolina-Digital-Repository, under directory /access/src/test/java/edu/unc/lib/dl/ui/util/.

Source file: StringFormatUtilTest.java

  29 
vote

@Test public void truncateText() throws IOException {
  String abstractText=IOUtils.toString(this.getClass().getResourceAsStream("multilineAbstract.txt"),"UTF-8");
  String truncated=StringFormatUtil.truncateText(abstractText,100);
  assertEquals(truncated.length(),99);
  abstractText="t" + abstractText;
  truncated=StringFormatUtil.truncateText(abstractText,100);
  assertEquals(truncated.length(),100);
  try {
    truncated=StringFormatUtil.truncateText(abstractText,-1);
    fail();
  }
 catch (  IndexOutOfBoundsException e) {
  }
  truncated=StringFormatUtil.truncateText(abstractText,abstractText.length() + 10);
  assertEquals(truncated.length(),abstractText.length());
  truncated=StringFormatUtil.truncateText(null,100);
  assertNull(truncated);
}
 

Example 31

From project cas, under directory /cas-server-core/src/main/java/org/jasig/cas/util/.

Source file: HttpClient.java

  29 
vote

public boolean isValidEndPoint(final URL url){
  HttpURLConnection connection=null;
  InputStream is=null;
  try {
    connection=(HttpURLConnection)url.openConnection();
    connection.setConnectTimeout(this.connectionTimeout);
    connection.setReadTimeout(this.readTimeout);
    connection.setInstanceFollowRedirects(this.followRedirects);
    connection.connect();
    final int responseCode=connection.getResponseCode();
    for (    final int acceptableCode : this.acceptableCodes) {
      if (responseCode == acceptableCode) {
        if (log.isDebugEnabled()) {
          log.debug("Response code from server matched " + responseCode + ".");
        }
        return true;
      }
    }
    if (log.isDebugEnabled()) {
      log.debug("Response Code did not match any of the acceptable response codes.  Code returned was " + responseCode);
    }
    if (responseCode == 500) {
      is=connection.getInputStream();
      final String value=IOUtils.toString(is);
      log.error(String.format("There was an error contacting the endpoint: %s; The error was:\n%s",url.toExternalForm(),value));
    }
  }
 catch (  final IOException e) {
    log.error(e.getMessage(),e);
  }
 finally {
    IOUtils.closeQuietly(is);
    if (connection != null) {
      connection.disconnect();
    }
  }
  return false;
}
 

Example 32

From project channel-directory, under directory /src/com/buddycloud/channeldirectory/commons/db/.

Source file: CreateSchema.java

  29 
vote

private static void runScript(ChannelDirectoryDataSource channelDirectoryDataSource,String sqlFile) throws IOException, FileNotFoundException, SQLException {
  List<String> readLines=IOUtils.readLines(new FileInputStream(sqlFile));
  Connection connection=channelDirectoryDataSource.getConnection();
  StringBuilder statementStr=new StringBuilder();
  for (  String line : readLines) {
    statementStr.append(line);
    if (line.endsWith(SQL_DELIMITER)) {
      Statement statement=connection.createStatement();
      statement.execute(statementStr.toString());
      statement.close();
      statementStr.setLength(0);
    }
  }
  connection.close();
}
 

Example 33

From project cidb, under directory /phenotype-mapping-service/src/main/java/edu/toronto/cs/cidb/hpoa/ontology/.

Source file: HPO.java

  29 
vote

public File getInputFileHandler(String inputLocation,boolean forceUpdate){
  try {
    File result=new File(inputLocation);
    if (!result.exists()) {
      String name=inputLocation.substring(inputLocation.lastIndexOf('/') + 1);
      result=getTemporaryFile(name);
      if (!result.exists()) {
        result.createNewFile();
        BufferedInputStream in=new BufferedInputStream((new URL(inputLocation)).openStream());
        OutputStream out=new FileOutputStream(result);
        IOUtils.copy(in,out);
        out.flush();
        out.close();
      }
    }
    return result;
  }
 catch (  IOException ex) {
    ex.printStackTrace();
    return null;
  }
}
 

Example 34

From project clearcase-plugin, under directory /src/main/java/hudson/plugins/clearcase/.

Source file: HudsonClearToolLauncher.java

  29 
vote

private void printToLogger(File logFile) throws FileNotFoundException, IOException {
  FileReader fileReader=new FileReader(logFile);
  BufferedReader br=new BufferedReader(fileReader);
  try {
    while (br.ready()) {
      listener.getLogger().println(br.readLine());
    }
  }
  finally {
    IOUtils.closeQuietly(br);
    IOUtils.closeQuietly(fileReader);
  }
}
 

Example 35

From project cloudbees-api-client, under directory /cloudbees-api-client/src/main/java/com/cloudbees/api/.

Source file: BeesClient.java

  29 
vote

/** 
 * The actual engine behind the REST API call. It sends a request in JSON and expects a JSON response back. Note that for historical reasons, there's the other half of the API that uses query parameters + digital signing.
 * @param apiTail The end point to hit. Appended to  {@link #base}. Shouldn't start with '/'
 * @param request JSON-bound POJO object that represents the request payload, or null if none.
 * @param type JSON-bound POJO class to unmarshal the response into.
 * @param method HTTP method name like GET or POST.
 * @throws IOException If the communication fails.
 */
<T>T postAndRetrieve(String apiTail,Object request,Class<T> type,String method) throws IOException {
  URL url=new URL(base,apiTail);
  HttpURLConnection uc=(HttpURLConnection)url.openConnection();
  uc.setRequestProperty("Authorization","Basic " + encodedAccountAuthorization);
  uc.setRequestProperty("Content-type","application/json");
  uc.setRequestProperty("Accept","application/json");
  uc.setRequestMethod(method);
  if (request != null) {
    uc.setDoOutput(true);
    MAPPER.writeValue(uc.getOutputStream(),request);
    uc.getOutputStream().close();
  }
  uc.connect();
  try {
    InputStreamReader r=new InputStreamReader(uc.getInputStream(),"UTF-8");
    String data=IOUtils.toString(r);
    if (type == null) {
      return null;
    }
    T ret=MAPPER.readValue(data,type);
    if (ret instanceof CBObject)     ((CBObject)ret).root=this;
    return ret;
  }
 catch (  IOException e) {
    String rsp="";
    InputStream err=uc.getErrorStream();
    if (err != null) {
      try {
        rsp=IOUtils.toString(err);
      }
 catch (      IOException _) {
      }
    }
    throw (IOException)new IOException("Failed to POST to " + url + " : code="+ uc.getResponseCode()+ " response="+ rsp).initCause(e);
  }
}
 

Example 36

From project cloudbees-deployer-plugin, under directory /src/test/java/org/jenkins/plugins/cloudbees/.

Source file: CloudbeesDeployWarTest.java

  29 
vote

public void assertOnArchive(InputStream inputStream) throws IOException {
  List<String> fileNames=new ArrayList<String>();
  ZipInputStream zipInputStream=null;
  try {
    zipInputStream=new ZipInputStream(inputStream);
    ZipEntry zipEntry=zipInputStream.getNextEntry();
    while (zipEntry != null) {
      fileNames.add(zipEntry.getName());
      zipEntry=zipInputStream.getNextEntry();
    }
  }
  finally {
    IOUtils.closeQuietly(zipInputStream);
  }
  assertTrue(fileNames.contains("META-INF/maven/org.olamy.puzzle.translate/translate-puzzle-webapp/pom.xml"));
  assertTrue(fileNames.contains("WEB-INF/lib/javax.inject-1.jar"));
}
 

Example 37

From project clutter, under directory /test/src/clutter/guerilla/.

Source file: GuerillaParserTest.java

  29 
vote

public void testParse() throws Exception {
  String snippet="junk <!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\">\n" + "<html>\n" + "<body foo=\"bar\" hello='world'>\n"+ "See, I am able to parseFromJSON\n"+ "</html>\n";
  GuerillaParser parser=new GuerillaParser(IOUtils.toInputStream(snippet));
  TextItem textItem=(TextItem)parser.next(false);
  assertEquals("junk ",textItem.getStringValue());
  DoctypeDeclaration docTypeDeclaration=(DoctypeDeclaration)parser.next(false);
  assertEquals("DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN\" \"http://www.w3.org/TR/html4/strict.dtd\"",docTypeDeclaration.getStringValue());
  assertEquals("\n",parser.next(false).getStringValue());
  OpeningTag html=(OpeningTag)parser.next(false);
  assertEquals("html",html.getStringValue());
  assertEquals("\n",parser.next(false).getStringValue());
  OpeningTag body=(OpeningTag)parser.next(false);
  assertEquals("body",body.getStringValue());
  assertEquals(2,body.getAttributes().size());
  assertEquals("\nSee, I am able to parseFromJSON\n",parser.next(false).getStringValue());
}
 

Example 38

From project cmsandroid, under directory /src/com/zia/freshdocs/widget/.

Source file: CMISAdapter.java

  29 
vote

/** 
 * Query the server using the query appropriate for the server version
 * @param term
 */
public void query(final String term){
  startProgressDlg(true);
  _dlThread=new ChildDownloadThread(_resultHandler,new Downloadable(){
    public Object execute(){
      Context context=getContext();
      Resources res=context.getResources();
      InputStream is=res.openRawResource(_cmis.getVersion().contains("0.6") ? R.raw.query_0_6 : R.raw.query_1_0);
      String xml=null;
      try {
        xml=String.format(IOUtils.toString(is),term,term);
        return _cmis.query(xml);
      }
 catch (      IOException e) {
        Log.e(CMISAdapter.class.getSimpleName(),"",e);
      }
      return null;
    }
  }
);
  _dlThread.start();
}
 

Example 39

From project com.cedarsoft.serialization, under directory /generator/common/src/test/java/com/cedarsoft/serialization/generator/common/.

Source file: DaGeneratorTest.java

  29 
vote

@Before public void setUp() throws Exception {
  myGenerator=new MyGenerator();
  sourceFile=tmp.newFile("MyClass.java");
  FileUtils.writeByteArrayToFile(sourceFile,IOUtils.toByteArray(getClass().getResourceAsStream("MyClass.java")));
  List<File> sourceFiles=Lists.newArrayList(sourceFile);
  out=new StringWriter();
  generatorConfiguration=new GeneratorConfiguration(sourceFiles,tmp.newFolder("dest"),tmp.newFolder("resources-dest"),tmp.newFolder("test-dest"),tmp.newFolder("test-resources-dest"),null,new PrintWriter(out));
}
 

Example 40

From project commons-fileupload, under directory /src/java/org/apache/commons/fileupload/disk/.

Source file: DiskFileItem.java

  29 
vote

/** 
 * Reads the state of this object during deserialization.
 * @param in The stream from which the state should be read.
 * @throws IOException if an error occurs.
 * @throws ClassNotFoundException if class cannot be found.
 */
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
  in.defaultReadObject();
  OutputStream output=getOutputStream();
  if (cachedContent != null) {
    output.write(cachedContent);
  }
 else {
    FileInputStream input=new FileInputStream(dfosFile);
    IOUtils.copy(input,output);
    dfosFile.delete();
    dfosFile=null;
  }
  output.close();
  cachedContent=null;
}
 

Example 41

From project commons-io, under directory /src/main/java/org/apache/commons/io/filefilter/.

Source file: MagicNumberFileFilter.java

  29 
vote

/** 
 * <p> Accepts the provided file if the file contains the file filter's magic number at the specified offset. </p> <p> If any  {@link IOException}s occur while reading the file, the file will be rejected. </p>
 * @param file the file to accept or reject.
 * @return {@code true} if the file contains the filter's magic number at the specified offset,  {@code false} otherwise.
 */
@Override public boolean accept(File file){
  if (file != null && file.isFile() && file.canRead()) {
    RandomAccessFile randomAccessFile=null;
    try {
      byte[] fileBytes=new byte[this.magicNumbers.length];
      randomAccessFile=new RandomAccessFile(file,"r");
      randomAccessFile.seek(byteOffset);
      int read=randomAccessFile.read(fileBytes);
      if (read != magicNumbers.length) {
        return false;
      }
      return Arrays.equals(this.magicNumbers,fileBytes);
    }
 catch (    IOException ioe) {
    }
 finally {
      IOUtils.closeQuietly(randomAccessFile);
    }
  }
  return false;
}
 

Example 42

From project components-ness-httpclient, under directory /client/src/test/java/com/nesscomputing/httpclient/testsupport/.

Source file: GenericWritingContentHandler.java

  29 
vote

@Override public void handle(final String target,final Request request,final HttpServletRequest httpRequest,final HttpServletResponse httpResponse) throws IOException, ServletException {
  method=request.getMethod();
  InputStream inputStream=request.getInputStream();
  postData=IOUtils.toString(inputStream);
  httpResponse.setContentType(contentType);
  httpResponse.setStatus(HttpServletResponse.SC_OK);
  request.setHandled(true);
  final PrintWriter writer=httpResponse.getWriter();
  writer.print(content);
  writer.flush();
}
 

Example 43

From project components-ness-pg, under directory /pg-embedded/src/main/java/com/nesscomputing/db/postgres/embedded/.

Source file: EmbeddedPostgreSQL.java

  29 
vote

private static List<String> system(String... command){
  try {
    Process process=new ProcessBuilder(command).start();
    Preconditions.checkState(0 == process.waitFor(),"Process %s failed\n%s",Arrays.asList(command),IOUtils.toString(process.getErrorStream()));
    InputStream stream=process.getInputStream();
    return IOUtils.readLines(stream);
  }
 catch (  Exception e) {
    throw Throwables.propagate(e);
  }
}
 

Example 44

From project conf4j, under directory /conf4j-mojo/src/main/java/org/conf4j/maven/.

Source file: Conf4jMojo.java

  29 
vote

public void execute() throws MojoExecutionException, MojoFailureException {
  if (!outputDirectory.exists())   throw new MojoFailureException(outputDirectory + " does not directory");
  if (!outputDirectory.isDirectory())   throw new MojoFailureException(outputDirectory + " is not a directory");
  final EScope targetScope;
  try {
    targetScope=EScope.valueOf(scope);
  }
 catch (  IllegalArgumentException e) {
    throw new MojoFailureException(e.getMessage());
  }
  final StringBuffer buffer=new StringBuffer();
  for (  Field field : ConfElements.class.getDeclaredFields()) {
    final Conf4j annotation=field.getAnnotation(Conf4j.class);
    if (annotation == null)     continue;
    final String value=annotation.value();
    final String description=annotation.description();
    final List<EScope> usages=Arrays.asList(annotation.scope());
    final boolean devPurposeOnly=annotation.devPurposeOnly();
    if (!devPurposeOnly)     continue;
    if (!usages.contains(targetScope) && !(usages.size() == 1 && usages.contains(undefined)))     continue;
    buffer.append(VARIABLE_0_VALUE_1_DESCRIPTION_2.format(new Object[]{field.getName(),value,description}));
  }
  final File file=new File(outputDirectory,"conf4j.properties");
  try {
    IOUtils.write(buffer,new FileOutputStream(file));
  }
 catch (  FileNotFoundException e) {
    throw new MojoFailureException(e.getMessage());
  }
catch (  IOException e) {
    throw new MojoFailureException(e.getMessage());
  }
 finally {
    getLog().info("written: " + file);
  }
}
 

Example 45

From project core_4, under directory /impl/src/test/integration/org/richfaces/integration/.

Source file: CoreDeployment.java

  29 
vote

/** 
 * Resolves Maven dependency and writes it to the cache, so it can be reused next run
 */
private void resolveMavenDependency(String missingDependency,File dir){
  Collection<JavaArchive> dependencies=DependencyResolvers.use(MavenDependencyResolver.class).loadEffectivePom("pom.xml").artifact(missingDependency).resolveAs(JavaArchive.class);
  for (  JavaArchive archive : dependencies) {
    dir.mkdirs();
    File outputFile=new File(dir,archive.getName());
    InputStream zipStream=archive.as(ZipExporter.class).exportAsInputStream();
    try {
      IOUtils.copy(zipStream,new FileOutputStream(outputFile));
    }
 catch (    IOException e) {
      throw new IllegalStateException(e);
    }
  }
}
 

Example 46

From project Cura, under directory /src/com/cura/Terminal/.

Source file: Terminal.java

  29 
vote

public synchronized String ExecuteCommand(String command){
  try {
    channel=session.openChannel("exec");
    ((ChannelExec)channel).setCommand(command);
    channel.connect();
    in=channel.getInputStream();
    writer.getBuffer().setLength(0);
    IOUtils.copy(in,writer);
    result=writer.toString();
    System.gc();
  }
 catch (  Exception i) {
    return "";
  }
  return result;
}
 

Example 47

From project Cyborg, under directory /src/main/java/com/alta189/cyborg/.

Source file: Cyborg.java

  29 
vote

private static String readVersion(){
  String version="-1";
  try {
    version=IOUtils.toString(Main.class.getResource("version").openStream(),"UTF-8");
  }
 catch (  Exception e) {
  }
  if (version.equalsIgnoreCase("${build.number}")) {
    version="custom_build";
  }
  return version;
}
 

Example 48

From project datafu, under directory /test/pig/datafu/test/pig/.

Source file: PigTests.java

  29 
vote

/** 
 * Gets the lines from a given file.
 * @param relativeFilePath The path relative to the datafu-tests project.
 * @return The lines from the file
 * @throws IOException
 */
protected String[] getLinesFromFile(String relativeFilePath) throws IOException {
  File file=new File(System.getProperty("user.dir"),relativeFilePath).getAbsoluteFile();
  BufferedInputStream content=new BufferedInputStream(new FileInputStream(file));
  Object[] lines=IOUtils.readLines(content).toArray();
  String[] result=new String[lines.length];
  for (int i=0; i < lines.length; i++) {
    result[i]=(String)lines[i];
  }
  return result;
}
 

Example 49

From project DB-Builder, under directory /src/main/java/org/silverpeas/dbbuilder/util/.

Source file: Configuration.java

  29 
vote

/** 
 * Load a properties file from the classpath then from $SILVERPEAS_HOME/properties
 * @param propertyName
 * @return a java.util.Properties
 * @throws IOException
 */
public static Properties loadResource(String propertyName) throws IOException {
  Properties properties=new Properties();
  InputStream in=Configuration.class.getClassLoader().getResourceAsStream(propertyName);
  try {
    if (in == null) {
      String path=propertyName.replace('/',File.separatorChar);
      path=path.replace('\\',File.separatorChar);
      if (!path.startsWith(File.separator)) {
        path=File.separatorChar + path;
      }
      File configurationFile=new File(getHome() + File.separatorChar + "properties"+ path);
      if (configurationFile.exists()) {
        in=new FileInputStream(configurationFile);
      }
    }
    if (in != null) {
      properties.load(in);
    }
  }
  finally {
    IOUtils.closeQuietly(in);
  }
  return properties;
}
 

Example 50

From project Dempsy, under directory /lib-dempsyimpl/src/main/java/com/nokia/dempsy/messagetransport/tcp/.

Source file: TcpSender.java

  29 
vote

protected void close(){
  if (dataOutputStream != null)   IOUtils.closeQuietly(dataOutputStream);
  dataOutputStream=null;
  closeQuietly(socket);
  socket=null;
}
 

Example 51

From project Dempsy-examples, under directory /userguide-wordcount/src/main/java/com/nokia/dempsy/example/userguide/wordcount/.

Source file: WordAdaptor.java

  29 
vote

private void setupStream() throws IOException {
  InputStream is=WordAdaptor.class.getClassLoader().getResourceAsStream("AV1611Bible.txt");
  StringWriter writer=new StringWriter();
  IOUtils.copy(is,writer);
  strings=writer.toString().split("\\s+");
}
 

Example 52

From project dimdwarf, under directory /dimdwarf-core/src/main/java/net/orfjackal/dimdwarf/server/.

Source file: ApplicationLoader.java

  29 
vote

private Properties getResourceAsProperties(String file) throws ConfigurationException {
  InputStream in=classLoader.getResourceAsStream(file);
  if (in == null) {
    throw new ConfigurationException("File not found from classpath: " + file);
  }
  Properties p=new Properties();
  try {
    p.load(in);
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
 finally {
    IOUtils.closeQuietly(in);
  }
  return p;
}
 

Example 53

From project DirectMemory, under directory /server/directmemory-server/src/main/java/org/apache/directmemory/server/services/.

Source file: JavaSerializedContentTypeHandler.java

  29 
vote

@Override public DirectMemoryRequest handlePut(HttpServletRequest request,HttpServletResponse response) throws DirectMemoryException, IOException {
  String expiresInHeader=request.getHeader(DirectMemoryHttpConstants.EXPIRES_IN_HTTP_HEADER);
  int expiresIn=StringUtils.isEmpty(expiresInHeader) ? 0 : Integer.valueOf(expiresInHeader);
  log.debug("expiresIn: {} for header value: {}",expiresIn,expiresInHeader);
  return new DirectMemoryRequest().setExpiresIn(expiresIn).setCacheContent(IOUtils.toByteArray(request.getInputStream()));
}
 

Example 54

From project Djinn, under directory /processor/src/main/java/com/webguys/djinn/marid/util/.

Source file: BuiltinAnnotationProcessor.java

  29 
vote

private boolean shouldGenerate() throws IOException {
  boolean result=false;
  UnifiedSet<String> typeStrings=this.elements.transform(ELEMENT_TO_TYPESTRING,UnifiedSet.<String>newSet(this.elements.size()));
  if (this.db.exists()) {
    this.builtins=UnifiedSet.<String>newSet(IOUtils.readLines(new FileInputStream(this.db),"UTF-8"));
    if (!this.builtins.containsAll(typeStrings)) {
      this.builtins.addAll(typeStrings);
      result=true;
    }
  }
 else {
    this.builtins=typeStrings;
    result=true;
  }
  return result;
}
 

Example 55

From project drools-planner, under directory /drools-planner-benchmark/src/main/java/org/drools/planner/benchmark/config/.

Source file: XmlPlannerBenchmarkFactory.java

  29 
vote

public XmlPlannerBenchmarkFactory configure(InputStream in){
  Reader reader=null;
  try {
    reader=new InputStreamReader(in,"UTF-8");
    return configure(reader);
  }
 catch (  UnsupportedEncodingException e) {
    throw new IllegalStateException("This vm does not support UTF-8 encoding.",e);
  }
 finally {
    IOUtils.closeQuietly(reader);
    IOUtils.closeQuietly(in);
  }
}
 

Example 56

From project dungbeetle, under directory /src/edu/stanford/mobisocial/dungbeetle/ui/adapter/.

Source file: ObjectListCursorAdapter.java

  29 
vote

private static int getBestBatchSize(){
  Runtime runtime=Runtime.getRuntime();
  if (runtime.availableProcessors() > 1)   return 100;
  try {
    File max_cpu_freq=new File("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq");
    byte[] freq_bytes=IOUtils.toByteArray(new FileInputStream(max_cpu_freq));
    String freq_string=new String(freq_bytes);
    double freq=Double.valueOf(freq_string);
    if (freq > 950000) {
      return 50;
    }
  }
 catch (  IOException e) {
    e.printStackTrace();
  }
  return 15;
}
 

Example 57

From project EasySOA, under directory /easysoa-proxy/easysoa-proxy-core/easysoa-proxy-core-httpdiscoveryproxy-test/src/test/java/org/easysoa/test/mock/nuxeo/.

Source file: EasySoaRestApiMock.java

  29 
vote

@Override public void service(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
  final String reqContent=IOUtils.toString(request.getInputStream());
  request=new HttpServletRequestWrapper(request){
    public ServletInputStream getInputStream(){
      return new ServletInputStream(){
        private ByteArrayInputStream bis=new ByteArrayInputStream(reqContent.getBytes());
        @Override public int read() throws IOException {
          return bis.read();
        }
      }
;
    }
    public BufferedReader getReader(){
      return new BufferedReader(new StringReader(reqContent));
    }
  }
;
  this.recordExchange(request);
  this.handleExchange(request,response);
}
 

Example 58

From project eclim, under directory /org.eclim.installer/java/org/eclim/installer/ant/.

Source file: ShutdownTask.java

  29 
vote

/** 
 * Executes this task.
 */
@SuppressWarnings("unchecked") public void execute() throws BuildException {
  FileReader reader=null;
  try {
    File instances=new File(System.getProperty("user.home") + "/.eclim/.eclimd_instances");
    int count=0;
    if (instances.exists()) {
      reader=new FileReader(instances);
      for (Iterator<String> ii=IOUtils.lineIterator(reader); ii.hasNext(); ) {
        count++;
        String instance=ii.next();
        try {
          log("Shutting down eclimd: " + instance);
          int port=Integer.parseInt(instance.replaceFirst(".*:",""));
          shutdown(port);
        }
 catch (        Exception e) {
          log("Unable to shut down eclimd (" + instance + "): "+ e.getClass().getName()+ " - "+ e.getMessage());
        }
      }
    }
    if (count == 0) {
      try {
        shutdown(9091);
      }
 catch (      Exception e) {
        log("Unable to shut down eclimd (9091): " + e.getClass().getName() + " - "+ e.getMessage());
      }
    }
  }
 catch (  FileNotFoundException fnfe) {
    log("Unable to locate eclimd instances file.");
  }
 finally {
    IOUtils.closeQuietly(reader);
  }
}
 

Example 59

From project elephant-twin, under directory /com.twitter.elephanttwin/src/main/java/com/twitter/elephanttwin/util/.

Source file: HdfsUtils.java

  29 
vote

/** 
 * Concatenate the content of all HDFS files matching  {@code hdfsGlob} into afile  {@code localFilename}.
 * @param hdfsNameNode The name of the Hadoop name node.
 * @param hdfsGlob Files matching this pattern will be fetched.
 * @param localFilename Name of local file to store concatenated content.
 * @return The newly created file.
 * @throws IOException when the file cannot be created/written.
 */
public static File getHdfsFiles(String hdfsNameNode,String hdfsGlob,String localFilename) throws IOException {
  Preconditions.checkNotNull(localFilename);
  Preconditions.checkNotNull(hdfsGlob);
  Preconditions.checkNotNull(hdfsNameNode);
  Configuration config=new Configuration();
  config.set(CommonConfigurationKeys.FS_DEFAULT_NAME_KEY,hdfsNameNode);
  FileSystem dfs=FileSystem.get(config);
  File localFile=new File(localFilename);
  FileOutputStream localStream=new FileOutputStream(localFile);
  FileStatus[] statuses=dfs.globStatus(new Path(hdfsGlob));
  LOG.info("Pattern " + hdfsGlob + " matched "+ statuses.length+ " HDFS files, "+ "fetching to "+ localFile.getCanonicalPath()+ "...");
  int copiedChars=0;
  FSDataInputStream remoteStream=null;
  for (  FileStatus status : statuses) {
    Path src=status.getPath();
    try {
      remoteStream=dfs.open(src);
      copiedChars+=IOUtils.copy(remoteStream,localStream);
    }
 catch (    IOException e) {
      LOG.severe("Failed to open/copy " + src);
    }
 finally {
      IOUtils.closeQuietly(remoteStream);
    }
  }
  LOG.info("Fetch " + copiedChars + " bytes to local FS");
  return localFile;
}
 

Example 60

From project email-preview, under directory /src/main/java/org/jasig/portlet/emailpreview/dao/javamail/.

Source file: JavamailAccountDaoImpl.java

  29 
vote

private EmailMessageContent getMessageContent(Object content,String mimeType) throws IOException, MessagingException {
  if (content instanceof String) {
    return new EmailMessageContent((String)content,isHtml(mimeType));
  }
 else   if (content instanceof MimeMultipart) {
    Multipart m=(Multipart)content;
    int parts=m.getCount();
    for (int i=parts - 1; i >= 0; i--) {
      EmailMessageContent result=null;
      BodyPart part=m.getBodyPart(i);
      Object partContent=part.getContent();
      String contentType=part.getContentType();
      boolean isHtml=isHtml(contentType);
      log.debug("Examining Multipart " + i + " with type "+ contentType+ " and class "+ partContent.getClass());
      if (partContent instanceof String) {
        result=new EmailMessageContent((String)partContent,isHtml);
      }
 else       if (partContent instanceof InputStream && (contentType.startsWith("text/html"))) {
        StringWriter writer=new StringWriter();
        IOUtils.copy((InputStream)partContent,writer);
        result=new EmailMessageContent(writer.toString(),isHtml);
      }
 else       if (partContent instanceof MimeMultipart) {
        result=getMessageContent(partContent,contentType);
      }
      if (result != null) {
        return result;
      }
    }
  }
  return null;
}
 

Example 61

From project ereviewboard, under directory /org.review_board.ereviewboard.core/src/org/review_board/ereviewboard/core/client/.

Source file: ReviewboardHttpClient.java

  29 
vote

private String getResponseBodyAsString(HttpMethodBase request,IProgressMonitor monitor){
  try {
    return IOUtils.toString(WebUtil.getResponseBodyAsStream(request,monitor));
  }
 catch (  IOException e) {
    throw new RuntimeException(e);
  }
}
 

Example 62

From project exanpe-t5-lib, under directory /src/main/java/fr/exanpe/t5/lib/components/.

Source file: BinaryImg.java

  29 
vote

@BeginRender void init(MarkupWriter writer) throws IOException {
  String src=null;
  try {
    _inputStream=new ByteArrayInputStream(IOUtils.toByteArray(inputStream));
    src=resources.createEventLink(EVENT).toURI();
  }
 catch (  IOException e) {
    logger.error("Impossible to consume stream",e);
    src=errorImage.toClientURL();
  }
  if (inputStream != null) {
    IOUtils.closeQuietly(inputStream);
  }
  writer.element("img","src",src);
  resources.renderInformalParameters(writer);
  writer.end();
}
 

Example 63

From project Extlet6, under directory /liferay-6.0.5-patch/portal-impl/src/com/liferay/portal/service/impl/.

Source file: PortletLocalServiceImpl.java

  29 
vote

private Set<String> _readLiferayPortletExtXML(Map<String,Portlet> portletsPool) throws Exception {
  Set<String> result=new HashSet();
  ClassLoader classLoader=getClass().getClassLoader();
  String resourceName="WEB-INF/liferay-portlet-ext.xml";
  Enumeration<URL> resources=classLoader.getResources(resourceName);
  if (_log.isDebugEnabled() && !resources.hasMoreElements()) {
    _log.debug("No " + resourceName + " has been found");
  }
  while (resources.hasMoreElements()) {
    URL resource=resources.nextElement();
    if (_log.isDebugEnabled()) {
      _log.debug("Loading " + resourceName + " from: "+ resource);
    }
    if (resource == null) {
      continue;
    }
    InputStream is=new UrlResource(resource).getInputStream();
    try {
      String xmlExt=IOUtils.toString(is,"UTF-8");
      result.addAll(_readLiferayPortletXML(xmlExt,portletsPool));
    }
 catch (    Exception e) {
      _log.error("Problem while loading file " + resource,e);
    }
 finally {
      is.close();
    }
  }
  return result;
}