當前位置: 首頁>>代碼示例>>Golang>>正文


Golang StickyReader.ReadInt16方法代碼示例

本文整理匯總了Golang中github.com/MJKWoolnough/byteio.StickyReader.ReadInt16方法的典型用法代碼示例。如果您正苦於以下問題:Golang StickyReader.ReadInt16方法的具體用法?Golang StickyReader.ReadInt16怎麽用?Golang StickyReader.ReadInt16使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/MJKWoolnough/byteio.StickyReader的用法示例。


在下文中一共展示了StickyReader.ReadInt16方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: transferFile


//.........這裏部分代碼省略.........
						xjs.SetInnerText(status, ReadError(&r).Error())
						return
					}
				}
			} else {
				f := files.NewFileReader(files.NewFile(fileI.Files()[0]))
				l := f.Len()
				if l == 0 {
					xjs.SetInnerText(status, "Zero-length file")
					return
				}
				w.WriteUint8(typeID<<1 | 1)
				w.WriteInt32(int32(l))
				io.Copy(&w, pb.Reader(f, l))
			}

			d.RemoveChild(pb)
			xjs.SetInnerText(status, "Checking File")

			data.WriteString(&w, name.Value)

			var ctx *dom.CanvasRenderingContext2D

			for {
				switch v := r.ReadUint8(); v {
				case 0:
					if r.Err != nil {
						xjs.SetInnerText(status, r.Err.Error())
					} else {
						xjs.SetInnerText(status, ReadError(&r).Error())
					}
					return
				case 1:
					files := make([]xform.Option, r.ReadInt16())
					for i := range files {
						files[i] = xform.Option{
							Value: strconv.Itoa(i),
							Label: data.ReadString(&r),
						}
					}
					j := xform.SelectBox("files", files...)
					sel := xjs.SetInnerText(xdom.Button(), "Select")
					fo := overlay.New(xjs.AppendChildren(xdom.Div(), xjs.AppendChildren(xdom.Fieldset(),
						xjs.SetInnerText(xdom.Legend(), "Please select the "+typeName+" file"),
						xform.Label("File", "files"),
						j,
						xdom.Br(),
						sel,
					)))
					c := make(chan int16, 0)
					done := false
					fo.OnClose(func() {
						if !done {
							done = true
							c <- -1
						}
					})
					sel.AddEventListener("click", false, func(dom.Event) {
						if !done {
							done = true
							v, err := strconv.Atoi(j.Value)
							if err != nil {
								v = -1
							}
							c <- int16(v)
							fo.Close()
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:67,代碼來源:utils.go

示例2: generator

func (t Transfer) generator(name string, r *byteio.StickyReader, w *byteio.StickyWriter, f *os.File, size int64) error {
	g := t.c.Generators.New(t.c.Settings().DirGenerators)
	if g == nil {
		return errors.New("error creating generator")
	}
	g.Name = name

	done := false
	defer func() {
		if !done {
			t.c.RemoveGenerator(g.ID)
		}
		go t.c.Save()
	}()

	zr, err := zip.NewReader(f, size)
	if err != nil {
		f.Seek(0, 0)
		e := json.NewDecoder(f).Decode(new(data.GeneratorData))
		if e != nil {
			return err
		}
		err = moveFile(f.Name(), path.Join(g.Path, "data.gen"))
		if err != nil {
			return err
		}

		done = true
		return nil
	}

	gens := make([]*zip.File, 0, 16)
	for _, file := range zr.File {
		if file.Name == "data.gen" {
			gens = []*zip.File{file}
			break
		}
		if strings.HasSuffix(file.Name, ".gen") || strings.HasSuffix(file.Name, ".json") {
			gens = append(gens, file)
		}
	}

	if len(gens) == 0 {
		return errors.New("cannot find generator data in zip")
	}
	if len(gens) > 1 {
		w.WriteUint8(1)
		w.WriteInt16(int16(len(gens)))
		for _, gen := range gens {
			data.WriteString(w, gen.Name)
		}
		if w.Err != nil {
			return w.Err
		}
		p := r.ReadInt16()
		if r.Err != nil {
			return r.Err
		}
		if int(p) >= len(gens) || p < 0 {
			return errors.New("error selecting generator data")
		}
		gens[0] = gens[p]
	}

	gd, err := gens[0].Open()
	if err != nil {
		return err
	}

	err = json.NewDecoder(gd).Decode(new(data.GeneratorData))
	if err != nil {
		return err
	}

	err = unzip(zr, g.Path)
	if err != nil {
		return err
	}

	err = os.Rename(path.Join(g.Path, gens[0].Name), path.Join(g.Path, "data.gen"))
	if err != nil {
		return err
	}

	done = true
	return nil
}
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:87,代碼來源:transfer_generator.go

示例3: server

func (t Transfer) server(name string, r *byteio.StickyReader, w *byteio.StickyWriter, f *os.File, size int64) error {
	zr, err := zip.NewReader(f, size)
	if err != nil {
		return err
	}
	jars := make([]*zip.File, 0, 16)
	for _, file := range zr.File {
		if file.Name == "server.jar" {
			jars = []*zip.File{file}
			break
		}
		if strings.HasSuffix(file.Name, ".jar") {
			jars = append(jars, file)
		}
	}
	s := t.c.NewServer()
	done := false
	defer func() {
		if !done {
			t.c.RemoveServer(s.ID)
		}
		go t.c.Save()
	}()
	if s == nil {
		return errors.New("error creating server")
	}
	s.Lock()
	s.Name = name
	d := s.Path
	s.Unlock()
	if len(jars) == 0 {
		err = moveFile(f.Name(), path.Join(d, "server.jar"))
	} else {
		if len(jars) > 1 {
			w.WriteUint8(1)
			w.WriteInt16(int16(len(jars)))
			for _, jar := range jars {
				data.WriteString(w, jar.Name)
			}
			if w.Err != nil {
				return w.Err
			}
			p := r.ReadInt16()
			if r.Err != nil {
				return r.Err
			}
			if int(p) >= len(jars) || p < 0 {
				return errors.New("error selecting server jar")
			}
			jars[0] = jars[p]
		}
		if err == nil {
			err = unzip(zr, d)
			if err == nil {
				err = os.Rename(path.Join(d, jars[0].Name), path.Join(d, "server.jar"))
			}
		}
	}
	if err != nil {
		return err
	}
	serverProperties := DefaultServerSettings()
	ps, err := os.OpenFile(path.Join(d, "properties.server"), os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0644)
	defer ps.Close()
	if err != nil {
		if !os.IsExist(err) {
			return err
		}
	} else {
		err = serverProperties.WriteTo(ps)
		if err != nil {
			return err
		}
	}
	done = true
	return nil
}
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:77,代碼來源:transfer_server.go

示例4: generate

func (t Transfer) generate(name string, r *byteio.StickyReader, w *byteio.StickyWriter, f *os.File, size int64) error {
	gp.Add(1)
	defer gp.Done()
	mp := t.c.NewMap()
	if mp == nil {
		return errors.New("failed to create map")
	}

	done := false
	defer func() {
		if !done {
			t.c.RemoveMap(mp.ID)
		}
		t.c.Save()
	}()

	mp.Lock()
	mp.Name = name
	mapPath := mp.Path
	mp.Server = -2
	mp.Unlock()

	t.c.Generators.mu.RLock()
	gs := make([]data.Generator, len(t.c.Generators.List))
	for n, g := range t.c.Generators.List {
		gs[n] = *g
	}
	t.c.Generators.mu.RUnlock()
	var g data.Generator
	if len(gs) == 0 {
		return errors.New("no generators installed")
	} else if len(gs) == 1 {
		g = gs[0]
	} else {
		w.WriteUint8(1)
		w.WriteInt16(int16(len(gs)))
		for _, tg := range gs {
			data.WriteString(w, tg.Name)
		}
		if w.Err != nil {
			return w.Err
		}
		gID := r.ReadInt16()
		if r.Err != nil {
			return r.Err
		}

		if gID < 0 || int(gID) >= len(gs) {
			return errors.New("unknown generator")
		}
		g = gs[gID]
	}

	ms := DefaultMapSettings()
	ms["level-type"] = minecraft.FlatGenerator
	ms["generator-settings"] = "0"
	ms["motd"] = name

	j, err := os.Open(path.Join(g.Path, "data.gen"))
	if err != nil {
		return err
	}
	var gj data.GeneratorData
	err = json.NewDecoder(j).Decode(&gj)
	j.Close()
	if err != nil {
		return err
	}

	for k, v := range gj.Options {
		ms[k] = v
	}

	pf, err := os.Create(path.Join(mapPath, "properties.map"))
	if err != nil {
		return err
	}

	if err = ms.WriteTo(pf); err != nil {
		return err
	}
	pf.Close()

	cmd := exec.Command(t.c.Settings().GeneratorExecutable)
	cmd.ExtraFiles = append(cmd.ExtraFiles, f)
	cmd.Dir, err = os.Getwd()
	if err != nil {
		return err
	}
	cmd.Stdout = w
	pw, err := cmd.StdinPipe()
	if err != nil {
		return err
	}

	err = gp.Start(cmd)
	if err != nil {
		return err
	}
	defer gp.Remove(cmd)
//.........這裏部分代碼省略.........
開發者ID:MJKWoolnough,項目名稱:minewebgen,代碼行數:101,代碼來源:transfer_generate.go


注:本文中的github.com/MJKWoolnough/byteio.StickyReader.ReadInt16方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。