List of usage examples for java.io DataInputStream close
public void close() throws IOException
From source file:com.datatorrent.contrib.hdht.HDHTWalManager.java
/** * Remove files older than recoveryStartWalFileId. * /*from ww w . jav a2 s .c o m*/ * @param recoveryStartWalFileId */ public void cleanup(long recoveryStartWalFileId) { if (recoveryStartWalFileId == 0) { return; } recoveryStartWalFileId--; try { while (true) { DataInputStream in = bfs.getInputStream(walKey, WAL_FILE_PREFIX + recoveryStartWalFileId); in.close(); logger.info("deleting WAL file {}", recoveryStartWalFileId); bfs.delete(walKey, WAL_FILE_PREFIX + recoveryStartWalFileId); recoveryStartWalFileId--; } } catch (FileNotFoundException ex) { //Do nothing } catch (IOException ex) { //Do nothing } }
From source file:org.gdg.frisbee.android.cache.ModelCache.java
private long readExpirationFromDisk(InputStream is) throws IOException { DataInputStream din = new DataInputStream(is); long expiration = din.readLong(); din.close(); return expiration; }
From source file:org.apache.hadoop.io.TestBufferedByteInputOutput.java
/** * Test reading from closed buffer./* w w w.jav a 2 s .c o m*/ */ @Test public void testCloseInput() throws IOException { LOG.info("Running test close input"); setUp(1000); // input is of size 1000, so the ReadThread will attempt to write to // the buffer, which will fail, but we should be able to read 100 bytes ByteArrayInputStream is = new ByteArrayInputStream(input); DataInputStream dis = BufferedByteInputStream.wrapInputStream(is, 100, 10); // wait for the thread to read from is and // write to the buffer while (dis.available() < 100) { sleep(10); } // no more writes to the internal buffer dis.close(); try { dis.read(); // read will call DataInputStream fill() which should fail fail("Read should fail because we are closed"); } catch (Exception e) { LOG.info("Expected exception " + e.getMessage()); } dis.close(); // can call multiple close() try { dis.read(new byte[10], 0, 10); fail("Read should fail because we are closed"); } catch (Exception e) { LOG.info("Expected exception " + e.getMessage()); } try { dis.available(); fail("Available should fail because we are closed"); } catch (Exception e) { LOG.info("Expected exception " + e.getMessage()); } }
From source file:net.modsec.ms.connector.ConnRequestHandler.java
/** * Reads the modsecurity configuration file on modsecurity machine. * @param json/*from www.j ava 2s . co m*/ */ @SuppressWarnings("unchecked") public static void onReadMSConfig(JSONObject json) { log.info("onReadMSConfig called.. : " + json.toJSONString()); MSConfig serviceCfg = MSConfig.getInstance(); String fileName = serviceCfg.getConfigMap().get("MSConfigFile"); InputStream ins; BufferedReader br; try { File file = new File(fileName); DataInputStream in; @SuppressWarnings("resource") FileChannel channel = new RandomAccessFile(file, "rw").getChannel(); FileLock lock = channel.lock(); try { ins = new FileInputStream(file); in = new DataInputStream(ins); br = new BufferedReader(new InputStreamReader(in)); String line = ""; while ((line = br.readLine()) != null) { //log.info("Line :" + line); for (ModSecConfigFields field : ModSecConfigFields.values()) { if (line.startsWith(field.toString())) { if (line.trim().split(" ")[0].equals(field.toString())) { json.put(field.toString(), line.trim().split(" ")[1].replace("\"", "")); } } } } log.info("ModSecurity Configurations configurations Loaded ... "); } finally { lock.release(); } br.close(); in.close(); ins.close(); } catch (FileNotFoundException e1) { json.put("status", "1"); json.put("message", "configuration file not found"); e1.printStackTrace(); } catch (IOException | NullPointerException e) { json.put("status", "1"); json.put("message", "configuration file is corrupt"); e.printStackTrace(); } log.info("Sending Json :" + json.toJSONString()); ConnectorService.getConnectorProducer().send(json.toJSONString()); json.clear(); }
From source file:org.openxdata.server.servlet.WMDownloadServlet.java
private void downloadStudies(HttpServletResponse response) throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); formDownloadService.downloadStudies(dos, "", ""); baos.flush();/* www. j a va 2 s . c o m*/ dos.flush(); byte[] data = baos.toByteArray(); baos.close(); dos.close(); DataInputStream dis = new DataInputStream(new ByteArrayInputStream(data)); PrintWriter out = response.getWriter(); out.println("<StudyList>"); try { @SuppressWarnings("unused") byte size = dis.readByte(); //reads the size of the studies while (true) { String value = "<study id=\"" + dis.readInt() + "\" name=\"" + dis.readUTF() + "\"/>"; out.println(value); } } catch (EOFException exe) { //exe.printStackTrace(); } out.println("</StudyList>"); out.flush(); dis.close(); }
From source file:com.photon.phresco.framework.impl.CIManagerImpl.java
private void setSvnCredential(CIJob job) throws JDOMException, IOException { S_LOGGER.debug("Entering Method CIManagerImpl.setSvnCredential"); try {//from ww w . j a v a 2s .com InputStream credentialXml = PhrescoFrameworkFactory.getServiceManager().getCredentialXml(); SvnProcessor processor = new SvnProcessor(credentialXml); DataInputStream in = new DataInputStream(credentialXml); while (in.available() != 0) { System.out.println(in.readLine()); } in.close(); processor.changeNodeValue("credentials/entry//userName", job.getUserName()); processor.changeNodeValue("credentials/entry//password", job.getPassword()); processor.writeStream(new File(Utility.getJenkinsHome() + File.separator + job.getName())); //jenkins home location String jenkinsJobHome = System.getenv(JENKINS_HOME); StringBuilder builder = new StringBuilder(jenkinsJobHome); builder.append(File.separator); processor.writeStream(new File(builder.toString() + CI_CREDENTIAL_XML)); } catch (Exception e) { S_LOGGER.error( "Entered into the catch block of CIManagerImpl.setSvnCredential " + e.getLocalizedMessage()); } }
From source file:org.apache.hadoop.hdfs.server.namenode.ConfigManager.java
/** * Removes all the entries currently in neverDeletePaths * and add the new ones specified//from w ww . ja va2 s. co m */ void reloadWhitelist() throws IOException { // read the entire whitelist into memory outside the // FSNamessytem lock. // LinkedList<String> paths = new LinkedList<String>(); FileInputStream fstream = new FileInputStream(whitelistFile); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); int count = 0; while (true) { String str = br.readLine(); if (str == null) { break; // end of file } str = str.trim(); // remove all whitespace from start and end if (str.startsWith("#")) { continue; // ignore lines with starting with # } paths.add(str); LOG.info("Whitelisted directory [" + count + "] " + str); count++; } in.close(); // acquire the writelock and insert newly read entries into // the Namenode's configuration. namesys.writeLock(); try { namesys.neverDeletePaths.clear(); for (String s : paths) { namesys.neverDeletePaths.add(s); } } finally { namesys.writeUnlock(); } }
From source file:org.apache.hadoop.fs.slive.TestSlive.java
@Test public void testBadChunks() throws Exception { File fn = getTestFile();//www. ja va 2 s . c o m int byteAm = 10000; FileOutputStream fout = new FileOutputStream(fn); byte[] bytes = new byte[byteAm]; rnd.nextBytes(bytes); fout.write(bytes); fout.close(); // attempt to read it DataVerifier vf = new DataVerifier(); VerifyOutput vout = new VerifyOutput(0, 0, 0, 0); DataInputStream in = null; try { in = new DataInputStream(new FileInputStream(fn)); vout = vf.verifyFile(byteAm, in); } catch (Exception e) { } finally { if (in != null) in.close(); } assertTrue(vout.getChunksSame() == 0); }
From source file:com.photon.phresco.framework.impl.CIManagerImpl.java
public void setMailCredential(CIJob job) { S_LOGGER.debug("Entering Method CIManagerImpl.setMailCredential"); try {/*w ww . j a v a 2 s . c om*/ InputStream credentialXml = PhrescoFrameworkFactory.getServiceManager().getMailerXml(); SvnProcessor processor = new SvnProcessor(credentialXml); DataInputStream in = new DataInputStream(credentialXml); while (in.available() != 0) { System.out.println(in.readLine()); } in.close(); // Mail have to with jenkins running email address InetAddress ownIP = InetAddress.getLocalHost(); processor.changeNodeValue(CI_HUDSONURL, HTTP_PROTOCOL + PROTOCOL_POSTFIX + ownIP.getHostAddress() + COLON + job.getJenkinsPort() + FORWARD_SLASH + CI + FORWARD_SLASH); processor.changeNodeValue("smtpAuthUsername", job.getSenderEmailId()); processor.changeNodeValue("smtpAuthPassword", job.getSenderEmailPassword()); processor.changeNodeValue("adminAddress", job.getSenderEmailId()); //jenkins home location String jenkinsJobHome = System.getenv(JENKINS_HOME); StringBuilder builder = new StringBuilder(jenkinsJobHome); builder.append(File.separator); processor.writeStream(new File(builder.toString() + CI_MAILER_XML)); } catch (Exception e) { S_LOGGER.error( "Entered into the catch block of CIManagerImpl.setMailCredential " + e.getLocalizedMessage()); } }
From source file:com.Candy.center.AboutCandy.java
private void bugreport() { try {//from w w w . j av a 2 s .c o m //collect system information FileInputStream fstream = new FileInputStream("/system/build.prop"); DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; while ((strLine = br.readLine()) != null) { String[] line = strLine.split("="); if (line[0].equalsIgnoreCase("ro.modversion")) { mStrDevice = line[1]; } } in.close(); } catch (Exception e) { Toast.makeText(getView().getContext(), getString(R.string.system_prop_error), Toast.LENGTH_LONG).show(); e.printStackTrace(); } String kernel = getFormattedKernelVersion(); //check if sdcard is available CandySizer sizer = new CandySizer(); short state = sizer.sdAvailable(); //initialize logfiles File extdir = Environment.getExternalStorageDirectory(); path = new File(extdir.getAbsolutePath().replace("emulated/0", "emulated/legacy") + "/Candykat/Bugreport"); File savefile = new File(path + "/system.log"); File logcat = new File(path + "/logcat.log"); File last_kmsg = new File(path + "/last_kmsg.log"); File kmsg = new File(path + "/kmsg.log"); File zip = new File(Environment.getExternalStorageDirectory() + "/Candykat/bugreport.zip"); systemfile = savefile.toString(); logfile = logcat.toString(); last_kmsgfile = last_kmsg.toString(); kmsgfile = kmsg.toString(); zipfile = zip.toString(); //cleanup old logs if (state == 2) { try { // create directory if it doesnt exist if (!path.exists()) { path.mkdirs(); } if (savefile.exists()) { savefile.delete(); } if (logcat.exists()) { logcat.delete(); } if (zip.exists()) { zip.delete(); } if (last_kmsg.exists()) { last_kmsg.delete(); } if (kmsg.exists()) { kmsg.delete(); } // create savefile and output lists to it FileWriter outstream = new FileWriter(savefile); BufferedWriter save = new BufferedWriter(outstream); save.write("Device: " + mStrDevice + '\n' + "Kernel: " + kernel); save.close(); outstream.close(); //get logcat and write to file getLogs("logcat -d -f " + logcat + " *:V\n"); getLogs("cat /proc/last_kmsg > " + last_kmsgfile + "\n"); getLogs("cat /proc/kmsg > " + kmsgfile + "\n"); try { Thread.sleep(2000); } catch (InterruptedException e) { e.printStackTrace(); } //create zip file if (savefile.exists() && logcat.exists() && last_kmsg.exists() && kmsg.exists()) { boolean zipcreated = zip(); if (zipcreated == true) { dialog(true); } else { dialog(false); } } } catch (IOException e) { e.printStackTrace(); } } else { toast(getResources().getString(R.string.sizer_message_sdnowrite)); } }