List of usage examples for java.nio CharBuffer append
public CharBuffer append(CharSequence csq)
From source file:Main.java
public static void main(String[] args) { CharBuffer cb1 = CharBuffer.allocate(10); cb1.append("java2s.com"); cb1.rewind();/*from www .ja v a 2s. c o m*/ System.out.println(Arrays.toString(cb1.array())); CharBuffer cb2 = cb1.subSequence(0, 2); System.out.println(cb2); }
From source file:Main.java
public static void main(String[] args) { CharBuffer cb1 = CharBuffer.allocate(50); cb1.append("java2s.com"); cb1.rewind();//from w w w . ja v a 2 s. c om System.out.println(cb1.charAt(2)); System.out.println(Arrays.toString(cb1.array())); CharBuffer cb2 = cb1.slice(); System.out.println(Arrays.toString(cb2.array())); }
From source file:Main.java
public static void main(String[] args) { CharBuffer cb1 = CharBuffer.allocate(50); cb1.append("java2s.com"); cb1.rewind();//from www . ja v a 2 s .com System.out.println(cb1.charAt(2)); System.out.println(Arrays.toString(cb1.array())); CharBuffer cb2 = cb1.compact(); System.out.println(Arrays.toString(cb2.array())); }
From source file:Main.java
public static void main(String[] args) throws IOException { CharBuffer cb1 = CharBuffer.allocate(20); cb1.append("java2s.com"); cb1.rewind();//from www . ja v a 2 s .co m System.out.println(Arrays.toString(cb1.array())); CharBuffer cb2 = CharBuffer.allocate(50); cb2.read(cb1); System.out.println(cb2); }
From source file:Main.java
private static void getFormatTime(Context context, Time time, int i, boolean flag, CharBuffer charbuffer) { long l = time.toMillis(true); boolean flag1; if ((i & 1) != 0) flag1 = true;/*from w ww . ja v a2s . co m*/ else flag1 = false; if (flag) charbuffer.append(DateUtils.formatDateRange(context, l, l, i)); else if (flag1) { if ((i ^ 1) != 0) { charbuffer.append(DateUtils.formatDateRange(context, l, l, i ^ 1)); charbuffer.append(" "); } String s = getDetailedAmPm(time.hour); if (time.hour > 12) time.hour = -12 + time.hour; long l1 = time.toMillis(true); String s1 = DateUtils.formatDateRange(context, l1, l1, 129); Resources resources = Resources.getSystem(); Object aobj[] = new Object[2]; aobj[0] = s1; aobj[1] = s; charbuffer.append(resources.getString(0x60c01f7, aobj)); } else { charbuffer.append(DateUtils.formatDateRange(context, l, l, i)); } }
From source file:fuse.okuyamafs.OkuyamaFilesystem.java
public int readlink(String path, CharBuffer link) throws FuseException { log.info("readlink " + path); link.append(path); return 0;//www.j av a 2s. c om }
From source file:net.sf.smbt.touchosc.utils.TouchOSCUtils.java
/** * Initialize UI model from a .touchosc file * // w w w . j a v a2 s . co m * @param zipTouchoscFilePath a .touchosc file * * @return UI model */ public TouchOscApp loadAppFromTouchOscXML2(String zipTouchoscFilePath) { // // Create a resource set. // ResourceSet resourceSet = new ResourceSetImpl(); // // Register the default resource factory -- only needed for stand-alone! // resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(TouchoscPackage.eNS_PREFIX, new TouchoscResourceFactoryImpl()); resourceSet.getPackageRegistry().put(TouchoscPackage.eNS_URI, TouchoscPackage.eINSTANCE); resourceSet.getPackageRegistry().put(TouchoscappPackage.eNS_URI, TouchoscappPackage.eINSTANCE); List<String> touchoscFilePathList = new ArrayList<String>(); try { URL url = TouchOSCUtils.class.getClassLoader().getResource("."); FileInputStream touchoscFile = new FileInputStream(url.getPath() + "../samples/" + zipTouchoscFilePath); ZipInputStream fileIS = new ZipInputStream(touchoscFile); ZipEntry zEntry = null; while ((zEntry = fileIS.getNextEntry()) != null) { if (zEntry.getName().endsWith(".xml")) { touchoscFilePathList.add(url.getPath() + "../samples/_" + zipTouchoscFilePath); } FileOutputStream os = new FileOutputStream(url.getPath() + "../samples/_" + zipTouchoscFilePath); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os)); BufferedReader reader = new BufferedReader(new InputStreamReader(fileIS, Charset.forName("UTF-8"))); CharBuffer charBuffer = CharBuffer.allocate(65535); while (reader.read(charBuffer) != -1) charBuffer.append("</touchosc:TOP>\n"); charBuffer.flip(); String content = charBuffer.toString(); content = content.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", TOUCHOSC_XMLNS_HEADER); content = content.replace("numberX=", "number_x="); content = content.replace("numberY=", "number_y="); content = content.replace("invertedX=", "inverted_x="); content = content.replace("invertedY=", "inverted_y="); content = content.replace("localOff=", "local_off="); content = content.replace("oscCs=", "osc_cs="); writer.write(content); writer.flush(); os.flush(); os.close(); } fileIS.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e2) { e2.printStackTrace(); } // // Get the URI of the model file. // URI touchoscURI = URI.createFileURI(touchoscFilePathList.get(0)); // // Demand load the resource for this file. // Resource resource = resourceSet.getResource(touchoscURI, true); Object obj = (Object) resource.getContents().get(0); if (obj instanceof TOP) { TOP top = (TOP) obj; reverseZOrders(top); return initAppFromTouchOsc(top.getLayout(), "horizontal".equals(top.getLayout().getOrientation()), "0".equals(top.getLayout().getMode())); } return null; }
From source file:net.sf.smbt.touchosc.utils.TouchOSCUtils.java
/** * Initialize UI model from a .jzml file * //from ww w. j a va 2 s. c o m * @param zipTouchoscFilePath a .jzml file * * @return UI model */ public TouchOscApp loadAppFromTouchOscXML(String zipTouchoscFilePath) { // // Create a resource set. // ResourceSet resourceSet = new ResourceSetImpl(); IPath path = new Path(zipTouchoscFilePath); // // Register the default resource factory -- only needed for stand-alone! // resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put(TouchoscPackage.eNS_PREFIX, new TouchoscResourceFactoryImpl()); resourceSet.getPackageRegistry().put(TouchoscPackage.eNS_URI, TouchoscPackage.eINSTANCE); resourceSet.getPackageRegistry().put(TouchoscappPackage.eNS_URI, TouchoscappPackage.eINSTANCE); List<String> touchoscFilePathList = new ArrayList<String>(); try { FileInputStream touchoscFile = new FileInputStream(zipTouchoscFilePath); ZipInputStream fileIS = new ZipInputStream(touchoscFile); ZipEntry zEntry = null; while ((zEntry = fileIS.getNextEntry()) != null) { if (zEntry.getName().endsWith(".xml")) { touchoscFilePathList.add(path.removeLastSegments(1) + "/_" + path.lastSegment()); } FileOutputStream os = new FileOutputStream(path.removeLastSegments(1) + "/_" + path.lastSegment()); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os)); BufferedReader reader = new BufferedReader(new InputStreamReader(fileIS, Charset.forName("UTF-8"))); CharBuffer charBuffer = CharBuffer.allocate(65535); while (reader.read(charBuffer) != -1) charBuffer.append("</touchosc:TOP>\n"); charBuffer.flip(); String content = charBuffer.toString(); content = content.replace("<touchosc>", ""); content = content.replace("</touchosc>", ""); content = content.replace("<?xml version=\"1.0\" encoding=\"UTF-8\"?>", TOUCHOSC_XMLNS_HEADER); content = content.replace("numberX=", "number_x="); content = content.replace("numberY=", "number_y="); content = content.replace("invertedX=", "inverted_x="); content = content.replace("invertedY=", "inverted_y="); content = content.replace("localOff=", "local_off="); content = content.replace("oscCs=", "osc_cs="); writer.write(content); writer.flush(); os.flush(); os.close(); } fileIS.close(); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e2) { e2.printStackTrace(); } // // Get the URI of the model file. // URI touchoscURI = URI.createFileURI(touchoscFilePathList.get(0)); // // Demand load the resource for this file. // Resource resource = resourceSet.getResource(touchoscURI, true); Object obj = (Object) resource.getContents().get(0); if (obj instanceof TOP) { TOP top = (TOP) obj; reverseZOrders(top); return initAppFromTouchOsc(top.getLayout(), "horizontal".equals(top.getLayout().getOrientation()), "0".equals(top.getLayout().getMode())); } return null; }
From source file:org.apache.tika.parser.html.charsetdetector.charsets.XUserDefinedCharset.java
public CharsetDecoder newDecoder() { return new CharsetDecoder(this, 1, 1) { @Override/*w ww.j av a 2 s. c om*/ protected CoderResult decodeLoop(ByteBuffer in, CharBuffer out) { while (true) { if (!in.hasRemaining()) return CoderResult.UNDERFLOW; if (!out.hasRemaining()) return CoderResult.OVERFLOW; byte b = in.get(); out.append((char) ((b >= 0) ? b : 0xF700 + (b & 0xFF))); } } }; }
From source file:org.sonatype.nexus.obr.metadata.DefaultObrResourceReader.java
public int read(final CharBuffer cb) throws IOException { // just here to complete the Reader API, it's not actually used try {//from www . j a va 2s .c o m parser.nextToken(); } catch (final XmlPullParserException e) { throw new LocalStorageException("Error parsing XML token", e); } final int n = cb.length(); cb.append(parser.getText()); return cb.length() - n; }