List of usage examples for java.io DataInputStream close
public void close() throws IOException
From source file:org.dspace.installer_edm.InstallerCrosswalk.java
/** * Aade contenido archivo class a nuevo archivo class en el jar * * @param jarOutputStream flujo de escritura para el jar * @throws IOException/* w w w . j a v a 2s. co m*/ */ protected void addClass2Jar(JarOutputStream jarOutputStream) throws IOException { File file = new File(myInstallerWorkDirPath + fileSeparator + edmCrossWalkClass); byte[] fileData = new byte[(int) file.length()]; DataInputStream dis = new DataInputStream(new FileInputStream(file)); dis.readFully(fileData); dis.close(); jarOutputStream.putNextEntry(new JarEntry(edmCrossWalkClass)); jarOutputStream.write(fileData); jarOutputStream.closeEntry(); }
From source file:com.axelor.apps.account.service.payment.PayboxService.java
/** Chargement de la cle AU FORMAT der * Utliser la commande suivante pour 'convertir' la cl 'pem' en 'der' * openssl rsa -inform PEM -in pubkey.pem -outform DER -pubin -out pubkey.der *//w w w . j a v a 2 s. co m * @param pubKeyFile * @return * @throws Exception */ @Deprecated private PublicKey getPubKeyDer(String pubKeyPath) throws Exception { FileInputStream fis = new FileInputStream(pubKeyPath); DataInputStream dis = new DataInputStream(fis); byte[] pubKeyBytes = new byte[fis.available()]; dis.readFully(pubKeyBytes); fis.close(); dis.close(); KeyFactory keyFactory = KeyFactory.getInstance(this.ENCRYPTION_ALGORITHM); // extraction cle X509EncodedKeySpec pubSpec = new X509EncodedKeySpec(pubKeyBytes); return keyFactory.generatePublic(pubSpec); }
From source file:J2MEWriteReadMixedDataTypesExample.java
public void commandAction(Command command, Displayable displayable) { if (command == exit) { destroyApp(true);//from ww w.jav a2 s . c o m notifyDestroyed(); } else if (command == start) { try { recordstore = RecordStore.openRecordStore("myRecordStore", true); byte[] outputRecord; String outputString = "First Record"; int outputInteger = 15; boolean outputBoolean = true; ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); DataOutputStream outputDataStream = new DataOutputStream(outputStream); outputDataStream.writeUTF(outputString); outputDataStream.writeBoolean(outputBoolean); outputDataStream.writeInt(outputInteger); outputDataStream.flush(); outputRecord = outputStream.toByteArray(); recordstore.addRecord(outputRecord, 0, outputRecord.length); outputStream.reset(); outputStream.close(); outputDataStream.close(); String inputString = null; int inputInteger = 0; boolean inputBoolean = false; byte[] byteInputData = new byte[100]; ByteArrayInputStream inputStream = new ByteArrayInputStream(byteInputData); DataInputStream inputDataStream = new DataInputStream(inputStream); for (int x = 1; x <= recordstore.getNumRecords(); x++) { recordstore.getRecord(x, byteInputData, 0); inputString = inputDataStream.readUTF(); inputBoolean = inputDataStream.readBoolean(); inputInteger = inputDataStream.readInt(); inputStream.reset(); } inputStream.close(); inputDataStream.close(); alert = new Alert("Reading", inputString + " " + inputInteger + " " + inputBoolean, null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); recordstore.closeRecordStore(); if (RecordStore.listRecordStores() != null) { RecordStore.deleteRecordStore("myRecordStore"); } } catch (Exception error) { alert = new Alert("Error Removing", error.toString(), null, AlertType.WARNING); alert.setTimeout(Alert.FOREVER); display.setCurrent(alert); } } }
From source file:com.cloudera.recordbreaker.hive.RegExpSerDe.java
/** * <code>initDeserializer</code> sets up the RegExp-specific * parts of the SerDe. In particular, it loads in the regular * expressions and corresponding schema descriptions. * * The patternPayloadJSONFile parameter is a serailized JSON * object that contains the schema and regexp info. *//*from w ww . j a v a 2 s. c o m*/ void initDeserializer(String patternPayloadJSONFile) { try { DataInputStream in = new DataInputStream(new FileInputStream(new File(patternPayloadJSONFile))); byte buf[] = new byte[8096]; StringBuffer payload = new StringBuffer(); try { int numBytes = in.read(buf); while (numBytes >= 0) { payload.append(new String(buf, 0, numBytes)); numBytes = in.read(buf); } } finally { in.close(); } String payloadStr = payload.toString(); JSONObject jobj = new JSONObject(payloadStr); this.patterns = new ArrayList<Pattern>(); JSONArray patternArray = jobj.getJSONArray("patterns"); for (int i = 0; i < patternArray.length(); i++) { String patternStr = patternArray.getString(i); this.patterns.add(Pattern.compile(patternStr)); } this.schemaOptions = new ArrayList<Schema>(); JSONArray schemaOptionArray = jobj.getJSONArray("schemaoptions"); for (int i = 0; i < schemaOptionArray.length(); i++) { String schemaStr = schemaOptionArray.getString(i); this.schemaOptions.add(Schema.parse(schemaStr)); } } catch (UnsupportedEncodingException uee) { uee.printStackTrace(); } catch (IOException iex) { iex.printStackTrace(); } catch (JSONException jse) { jse.printStackTrace(); } }
From source file:org.apache.hama.bsp.sync.ZKSyncClient.java
/** * Utility function to read Writable object value from byte array. * /*from ww w. j av a2 s. c om*/ * @param data The byte array * @param valueHolder The Class object of expected Writable object. * @return The instance of Writable object. * @throws IOException */ protected boolean getValueFromBytes(byte[] data, Writable valueHolder) throws IOException { if (data != null) { ByteArrayInputStream istream = new ByteArrayInputStream(data); DataInputStream diStream = new DataInputStream(istream); try { valueHolder.readFields(diStream); } finally { diStream.close(); } return true; } return false; }
From source file:org.craftercms.cstudio.loadtesting.actions.GoLive.java
public String getDependencies(String fileName) throws Exception { ArrayList<String> content = new ArrayList<String>(); DataInputStream in = null; try {//from www. j av a 2 s. c o m System.out.println("[" + username + "] GET-DEPENDENCIES: reading " + fileName); FileInputStream fstream = new FileInputStream(fileName); in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String item; while ((item = br.readLine()) != null) { content.add(item); } } finally { if (in != null) { in.close(); } } return getDependencies(content); }
From source file:org.apache.giraph.ooc.data.OutOfCoreDataManager.java
/** * Loads and assembles all data for a given partition, and put it into the * data store./*from ww w . j a v a2s . co m*/ * * @param partitionId id of the partition to load ana assemble all data for * @param basePath path to load the data from * @throws IOException */ public void loadPartitionData(int partitionId, String basePath) throws IOException { ReadWriteLock rwLock = getPartitionLock(partitionId); rwLock.writeLock().lock(); if (hasPartitionDataOnDisk.contains(partitionId)) { loadInMemoryPartitionData(partitionId, getPath(basePath, partitionId)); hasPartitionDataOnDisk.remove(partitionId); // Loading raw data buffers from disk if there is any and applying those // to already loaded in-memory data. Integer numBuffers = numDataBuffersOnDisk.remove(partitionId); if (numBuffers != null) { checkState(numBuffers > 0); File file = new File(getBuffersPath(basePath, partitionId)); checkState(file.exists()); if (LOG.isDebugEnabled()) { LOG.debug("loadPartitionData: loading " + numBuffers + " buffers of" + " partition " + partitionId + " from " + file.getAbsolutePath()); } FileInputStream fis = new FileInputStream(file); BufferedInputStream bis = new BufferedInputStream(fis); DataInputStream dis = new DataInputStream(bis); for (int i = 0; i < numBuffers; ++i) { T entry = readNextEntry(dis); addEntryToImMemoryPartitionData(partitionId, entry); } dis.close(); checkState(file.delete(), "loadPartitionData: failed to delete %s.", file.getAbsoluteFile()); } // Applying in-memory raw data buffers to in-memory partition data. Pair<Integer, List<T>> pair = dataBuffers.remove(partitionId); if (pair != null) { for (T entry : pair.getValue()) { addEntryToImMemoryPartitionData(partitionId, entry); } } } rwLock.writeLock().unlock(); }
From source file:com.librelio.products.ui.ProductsBillingActivity.java
private static String getTempURL(HttpResponse response) { String tempURL = null;/*from w w w.j a va 2 s . c o m*/ Log.d(TAG, "status line: " + response.getStatusLine().toString()); HttpEntity entity = response.getEntity(); DataInputStream bodyStream = null; if (entity != null) { try { bodyStream = new DataInputStream(entity.getContent()); StringBuilder content = new StringBuilder(); if (null != bodyStream) { String line = null; while ((line = bodyStream.readLine()) != null) { content.append(line).append("\n"); } } Log.d(TAG, "body: " + content.toString()); } catch (Exception e) { Log.e(TAG, "get content failed", e); } finally { try { bodyStream.close(); } catch (Exception e) { } } } if (null != response.getAllHeaders()) { for (Header h : response.getAllHeaders()) { if (h.getName().equalsIgnoreCase("location")) { tempURL = h.getValue(); } Log.d(TAG, "header: " + h.getName() + " => " + h.getValue()); } } return tempURL; }
From source file:Util.PacketGenerator.java
public static void GeneratePacket() { try {//from w ww . j a va 2s . c o m File file = new File( "D:\\Mestrado\\Prototipo\\Trace\\Los Angeles\\equinix-sanjose.dirA.20120920-130000.UTC.anon.pcap.csv"); File newFile = new File("D:\\Mestrado\\SketchMatrix\\trunk\\Tracer_100_Pacotes.csv"); FileInputStream tracesFIS = new FileInputStream(file); DataInputStream tracesDIS = new DataInputStream(tracesFIS); BufferedReader tracesBR = new BufferedReader(new InputStreamReader(tracesDIS)); FileWriter tracesFW = new FileWriter(newFile); String tracesStr = tracesBR.readLine(); Random random = new Random(); long numberOfPackets = 0; while (tracesStr != null && numberOfPackets < 100) { String[] packetTokens = tracesStr.split(","); long time = Long.parseLong(packetTokens[0]); long srcIP = Long.parseLong(packetTokens[1]); long dstIP = Long.parseLong(packetTokens[2]); int srcPort = Integer.parseInt(packetTokens[3]); int dstPort = Integer.parseInt(packetTokens[4]); int payload = random.nextInt(256); tracesFW.write( time + "," + srcIP + "," + dstIP + "," + srcPort + "," + dstPort + "," + payload + "\n"); tracesStr = tracesBR.readLine(); numberOfPackets++; if ((numberOfPackets % 100000) == 0) { System.out.println(numberOfPackets / 1000 + "K Pacotes"); } } tracesBR.close(); tracesDIS.close(); tracesFIS.close(); tracesFW.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:com.netflix.ice.basic.BasicReservationService.java
public void init() { this.config = ProcessorConfig.getInstance(); files = Maps.newHashMap();/* w w w .j a v a2s. c o m*/ for (ReservationUtilization utilization : ReservationUtilization.values()) { files.put(utilization, new File(config.localDir, "reservation_prices." + term.name() + "." + utilization.name())); } boolean fileExisted = false; for (ReservationUtilization utilization : ReservationUtilization.values()) { File file = files.get(utilization); AwsUtils.downloadFileIfNotExist(config.workS3BucketName, config.workS3BucketPrefix, file); fileExisted = file.exists(); } if (!fileExisted) { try { pollAPI(); } catch (Exception e) { logger.error("failed to poll reservation prices", e); throw new RuntimeException("failed to poll reservation prices for " + e.getMessage()); } } else { for (ReservationUtilization utilization : ReservationUtilization.values()) { try { File file = files.get(utilization); if (file.exists()) { DataInputStream in = new DataInputStream(new FileInputStream(file)); ec2InstanceReservationPrices.put(utilization, Serializer.deserialize(in)); in.close(); } } catch (Exception e) { throw new RuntimeException("failed to load reservation prices " + e.getMessage()); } } } start(3600, 3600 * 24, true); }